Database Reference
In-Depth Information
Listing 10-46. The friends_purchase Method in the Purchase Class
# products purchased by friends
def friends_purchase(neo,username)
cypher = " 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} )
results["data"].map {|row| Hash[results["columns"].zip(row)] }
end
The query shown in Listing 10-46 finds the users being followed by the current user and then matches those
users to a purchase that has been MADE which CONTAINS a product. The return value is a set of properties that identify
the product title, the name of the friend or friends, as well the number of friends who have bought the product. The
result is ordered by the number of friends who have purchased the product and then by product title, as shown in
Figure 10-18 .
Figure 10-18. Products Purchased By Friends
 
Search WWH ::




Custom Search