Database Reference
In-Depth Information
Figure 9-15. The consumption console shows products connected to users via tags
Listing 9-37. The consumption console Route and Methods to Get Connected Products and Users via Tags
# displays products that are connected to users via a tag relationship
@route('/consumption/console', method='GET')
def consumption_console():
# was tag supplied, then get product matches based on specific tag
if request.query.get('tag'):
usersWithMatchingTags = Product().getProductsHasSpecificTagAndUserUsesSpecificTag(graph_db,
request.query.get('tag'))
# otherwise return all product matches as long as at least one tag matches against the users
else:
usersWithMatchingTags = Product().getProductsHasATagAndUserUsesAMatchingTag(graph_db)
return template('public/templates/graphs/consumption/console.html', layout=applayout,
usersWithMatchingTags=usersWithMatchingTags, title="Consumption Console")
# tags that match products and users
def getProductsHasATagAndUserUsesAMatchingTag(self, graph_db):
query = neo4j.CypherQuery(graph_db,
" MATCH (p:Product)-[:HAS]->(t)<-[:USES]-(u:User) "+
" RETURN p.title as title , collect(u.username) as users, " +
" collect(distinct t.wordPhrase) as tags ")
result = query.execute()
return result
Search WWH ::




Custom Search