Database Reference
In-Depth Information
Specific Products Purchased by Friends
If you click on the “Specific Products Purchased By Friends” link, you can specify a product, in this case “Star Wars
Mimobot Thumb Drives”, and then search for friends who have purchased this product (Figure 10-19 ). This is done via
the friends_purchase_by_product route and method of the same name in Purchase service class, both of which are
shown in Listing 10-47.
Figure 10-19. Specific Products Purchased by Friends
Listing 10-47. The friends_purchase_by_product Route and Method
# specific product purchases by friends
get '/intent/friends_purchase_by_product' do
@title = "Specific Products Purchased by Friends"
@producttitle = 'Star Wars Mimobot Thumb Drives'
@mappedProductUserPurchaseList = friends_purchase_by_product(neo,request.
cookies[graphstoryUserAuthKey], @producttitle)
mustache :"graphs/intent/index"
end
# a specific product purchased by friends
def friends_purchase_by_product(neo,username,title)
cypher = " MATCH (p:Product) " +
" WHERE lower(p.title) =lower({title}) " +
" WITH p " +
" MATCH (u:User { username: {u} } )-[:FOLLOWS]-(f)-[:MADE]->()-[:CONTAINS]->(p) " +
" RETURN p.productId as productId, p.title as title, " +
" collect(f.firstname + ' ' + f.lastname) as fullname, " +
" null as wordPhrase, count(f) as cfriends " +
" ORDER BY cfriends desc, p.title "
results=neo.execute_query(cypher, {:u => username, :title => title } )
results["data"].map {|row| Hash[results["columns"].zip(row)] }
end
 
Search WWH ::




Custom Search