Database Reference
In-Depth Information
Listing 9-44. The friends_purchase_by_product Route and Method
# specific product purchases by friends
@route('/intent/friendsPurchaseByProduct', method='GET')
def friends_purchase_by_product():
# get or use default product title
producttitle = request.query.producttitle or 'Star Wars Mimobot Thumb Drives'
# get result set
result = Purchase().friends_purchase_by_product(graph_db, request.get_
cookie(graphstoryUserAuthKey), producttitle)
return template('public/templates/graphs/intent/index.html', layout=applayout,
title="Specific Products Purchased by Friends",
mappedProductUserPurchaseList=result, producttitle=producttitle)
# a specific product purchased by friends
def friends_purchase_by_product(self, graph_db, username, title):
query = neo4j.CypherQuery(graph_db,
" MATCH (p:Product) " +
" WHERE lower(p.title) =lower({title}) " +
" WITH p " +
" 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 ")
params = {"u": username, "title": title}
result = query.execute(**params)
return result
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 also have tags that are
used by the current user (Listing 9-45). The result of the query is shown in Figure 9-20 .
Listing 9-45. Product and Tag Similarity of the Current User's Friends
# friends bought specific products. match these products to tags of the current user
@route('/intent/friendsPurchaseTagSimilarity', method='GET')
def friends_purchase_tag_similarity():
# get result set
result = Purchase().friends_purchase_tag_similarity(graph_db, request.get_
cookie(graphstoryUserAuthKey))
return template('public/templates/graphs/intent/index.html', layout=applayout,
title="Products Purchased by Friends and Matches User's Tags",
mappedProductUserPurchaseList=result)
Search WWH ::




Custom Search