Database Reference
In-Depth Information
Figure 9-20. Products Purchased by Friends and Matches User's Tags
Using friends_purchase_tag_similarity in Purchase service class, shown in Listing 9-46, the application
provides the username to the query and uses the FOLLOWS , MADE , and 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 9-46. 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(self, graph_db, username):
query = neo4j.CypherQuery(graph_db,
" 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, " +
" count(f) as cfriends " +
" ORDER BY cfriends desc, p.title ")
params = {"u": username}
result = query.execute(**params)
return result
Products Purchased by Friends Nearby and Matches User's Tags
Finding products that match with a specific user's tags and have been purchased by friends who live within a set
distance of the user is performed by the friends_purchase_tag_similarity_and_proximity_to_location method,
easily the world's longest method name, and is located in Purchase class(Listing 9-47).
Search WWH ::




Custom Search