Database Reference
In-Depth Information
Products Purchased by Friends and Matches User's Tags
In this next instance, we want to determine products that have been purchased by friends but that also have tags used
by the current user (Listing 10-48). The result of the query is shown in Figure 10-20 .
Listing 10-48. Product and Tag Similarity of the Current Users's Friends.
# friends bought specific products. match these products to tags of the current user
get '/intent/friends_purchase_tag_similarity' do
@title = "Products Purchased by Friends and Matches User's Tags"
@mappedProductUserPurchaseList = friends_purchase_tag_similarity(neo,request.
cookies[graphstoryUserAuthKey])
mustache :"graphs/intent/index"
end
Figure 10-20. Products Purchased by Friends and Matches User's Tags
Using friends_purchase_tag_similarity in the Purchase service class, shown in Listing 10-49, the application
provides the userId to the query and uses the FOLLOWS , MADE and the CONTAINS relationships to return products
purchases by users being followed. The subsequent MATCH statement takes the USES and HAS directed relationship
types to determine the tag relationships the resulting products and the current user have in common.
Listing 10-49. The Method to Find Products Purchased by Friends and Matches Current User's Tags.
# products purchased by friends that match the user's tags
def friends_purchase_tag_similarity(neo,username)
cypher = " MATCH (u:User { username: {u} } )-[:FOLLOWS]-(f)-[:MADE]->()-[:CONTAINS]->p " +
" WITH u,p,f " +
" MATCH u-[:USES]->(t)<-[:HAS]-p " +
" RETURN p.productId as productId, p.title as title, " +
" collect(f.firstname + ' ' + f.lastname) as fullname, " +
" t.wordPhrase as wordPhrase, " +
 
Search WWH ::




Custom Search