Database Reference
In-Depth Information
" 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
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 the Purchase class (Listing 10-50).
Listing 10-50. The friendsPurchaseTagSimilarityAndProximityToLocation Route
# friends that are nearby bought this product. the product should also matches tags of the current
user
get '/intent/friends_purchase_tag_similarity_and_proximity_to_location' do
@title = "Products Purchased by Friends Nearby and Matches User's Tags"
@mappedUserLocation=get_user_location(neo,request.cookies[graphstoryUserAuthKey])
lq = get_lq(@mappedUserLocation[0],"10.00")
@mappedProductUserPurchaseList=friends_purchase_tag_similarity_and_proximity_to_
location(neo,request.cookies[graphstoryUserAuthKey],lq)
mustache :"graphs/intent/index"
end
The friendsPurchaseTagSimilarityAndProximityToLocation route calls the friends_purchase_tag_
similarity_and_proximity_to_location method shown in Listing 10-51.
Listing 10-51. The friends_purchase_tag_similarity_and_proximity_to_location Method in Purchase
# user's friends' purchases who are nearby and the products match the user's tags
def friends_purchase_tag_similarity_and_proximity_to_location(neo,username,lq)
cypher = " 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 "
results=neo.execute_query(cypher, {:u => username, :lq => lq} )
results["data"].map {|row| Hash[results["columns"].zip(row)] }
end
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 10-21 .
 
Search WWH ::




Custom Search