Database Reference
In-Depth Information
Listing 9-47. Route to Find Products of Nearby Friends and Matches Tags of Current User
# friends that are nearby bought this product.
# the product should also matches tags of the current user
@route('/intent/friendsPurchaseTagSimilarityAndProximityToLocation', method='GET')
def friends_purchase_tag_similarity_and_proximity_to_location():
# get user location
userlocations = UserLocation().get_user_location(graph_db, request.get_
cookie(graphstoryUserAuthKey))
# use first location
ul = userlocations[0]
# get result set
result = Purchase().friends_purchase_tag_similarity_and_proximity_to_location(graph_db,
request.get_cookie(graphstoryUserAuthKey), UserLocation().get_lq_distance_set(ul))
return template('public/templates/graphs/intent/index.html', layout=applayout,
title="Products Purchased by Friends Nearby and Matches User's Tags",
mappedProductUserPurchaseList=result, mappedUserLocation=userlocations)
The friends_purchase_tag_similarity_and_proximity_to_location route calls the friends_purchase_tag_
similarity_and_proximity_to_location method shown in Listing 9-48.
Listing 9-48. friendsPurchaseTagSimilarityAndProximityToLocation Method in the Purchase Class
# user's friends' purchases who are nearby and the products match the user's tags
def friends_purchase_tag_similarity_and_proximity_to_location(self, graph_db, username, lq):
query = neo4j.CypherQuery(graph_db,
" START n = node:geom({lq}) " +
" WITH n " +
" MATCH (u:User {username: {u} } )-[:USES]->(t)<-[:HAS]-p " +
" WITH n,u,p,t " +
" MATCH u-[:FOLLOWS]->(f)-[:HAS]->(n) " +
" WITH p,f,t " +
" MATCH f-[:MADE]->()-[:CONTAINS]->(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, "lq": lq}
result = query.execute(**params)
return result
The query begins with a location search within a certain distance, then matches the current user's tags to
products. Next, the query matches friends based on the location search. The resulting friends are matched against
products that are in the set of user tag matches. The result of the query is shown in Figure 9-21 .
 
Search WWH ::




Custom Search