neo4j cypher suggestion based on common relation rating -
scenario: graph image
john doe has rated 2 ingredients, 2 of ingredients happen belong soup recipe, , 1 pizza. query should return soup recipe because avg of ingredient ratings > 5
what have: started below query:
match (:subject {ref: 1})-[ir:ingredient_rating]->(:ingredient)<-[:has_ingredient]-(r:recipe) ir.value > 5 return r;
what happen: returns recipes ingredient has rating above 5, not take account other ingredients of recipe have lower ratings given user.
so have expand on above query i'm bit clueless start.
thanks in advance,
update 1: based on @inversefalcon came this, gives me results expect:
match (:subject {ref: '1'})-[ir:ingredient_rating]->(i:ingredient)-[:has_ingredient]-(r:recipe)-[:kitchen]->(k:kitchen)
match (r)-[has_ingredient]-(in:ingredient)
r, k, in, sum(ir.value) sum
sum > 10
return distinct r, collect(distinct in) ingredients, k kitchen, sum
order sum desc
the second match because without it, returns ingredients rating, need of them.
there 1 oddity , duplicate result tough use distinct on r.
sounds need avg()
aggregation function take average of multiple values. work you?
match (:subject {ref: 1})-[ir:ingredient_rating]->(:ingredient)<-[:has_ingredient]-(r:recipe) r, avg(ir.value) avg avg > 5 return r;
Comments
Post a Comment