Database Reference
In-Depth Information
" RETURN n.locationId as locationId, n.address as address, " +
" n.city as city, n.state as state, n.zip as zip, n.name as name, " +
" n.lat as lat, n.lon as lon")
params = {"lq": lq, "productNodeId": productNodeId}
result = query.execute(**params)
Intent Graph Model
The last part of the graph model exploration considers all the other graphs in order to suggest products based on the
Purchase node type. The intent graph also considers the products, users, locations, and tags that are connected based
on a Purchase.
Products Purchased by Friends
To get all of the products that have been purchased by friends, the friends_purchase method is called from Purchase
class, which is shown in Listing 9-43. The corresponding route is first shown in Listing 9-42.
Listing 9-42. Intent Route to Show Purchases Made by Friends
# purchases by friends
@route('/intent', method='GET')
def intent():
# get result set
result = Purchase().friends_purchase(graph_db, request.get_cookie(graphstoryUserAuthKey))
return template('public/templates/graphs/intent/index.html', layout=applayout,
title="Products Purchased by Friends",
mappedProductUserPurchaseList=result)
The query, show in Listing 9-43, finds the users being followed by the current user and then matches those users
to a purchase that has been MADE which CONTAINS a product. The return value is a set of properties that identify the
product title, the name of the friend or friends, as well the number of friends who have bought the product. The result is
ordered by the number of friends who have purchased the product and then by product title, as shown in Figure 9-18 .
Listing 9-43. The friends_purchase Method in the Purchase Class
# products purchased by friends
def friends_purchase(self, graph_db, username):
query = neo4j.CypherQuery(graph_db,
" 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}
result = query.execute(**params)
return result
 
Search WWH ::




Custom Search