I am trying to get all the Restaurants that User has not yet reviewed based on the Category condition but I am getting the following error:
ERROR:
In a WITH/RETURN with DISTINCT or an aggregation, it is not possible to access variables declared before the WITH/RETURN: user (line 3, column 12 (offset: 241))
HERE IS MY QUERY:
> MATCH(user:User{user_id:"u-Gcx8OEYpT85qddaoiFw3Gw"})-[:WROTE]->(review:Review)-[:REVIEWS_FOR]->(rest1:Restaurant)-[c1:IN_CATEGORY]->(cat:Category)-[c2:IN_CATEGORY]-(rest2:Restaurant)
> WITH AVG(toFloat(review.stars)) AS avg_rating
> WHERE NOT (user)--(rest2) AND review.stars > avg_rating AND rest2.stars > avg_rating
> RETURN rest2 LIMIT 15
It's because user, rest2, review and rest2 must be specified in the previous WITH clause to be used.
An easy and dirty solution:
MATCH (user:User{user_id:"u-Gcx8OEYpT85qddaoiFw3Gw"})-[:WROTE]->(review:Review)
WITH AVG(toFloat(review.stars)) AS avg_rating
MATCH (user:User{user_id:"u-Gcx8OEYpT85qddaoiFw3Gw"})-[:WROTE]->(review:Review)-[:REVIEWS_FOR]->(rest1:Restaurant)-[c1:IN_CATEGORY]->(cat:Category)-[c2:IN_CATEGORY]-(rest2:Restaurant)
WHERE NOT (user)--(rest2)
AND review.stars > avg_rating
AND rest2.stars > avg_rating
RETURN rest2 LIMIT 15
Can you please figure out what is the problem in this query..
MATCH(user:User{user_id:"u-Gcx8OEYpT85qddaoiFw3Gw"})-[:WROTE]->(review:Review)-[:REVIEWS_FOR]->(rest1:Restaurant)-[c1:IN_CATEGORY]->(cat:Category)-[c2:IN_CATEGORY]-(rest2:Restaurant)
WHERE NOT (user)--(rest2) AND rest2.stars > "3.5" AND rest2.review_count > "50"
RETURN rest2 LIMIT 15
This condition is not working... rest2.review_count > "50"
MATCH (user:User{user_id:"u-Gcx8OEYpT85qddaoiFw3Gw"})-[:WROTE]->(review:Review)-[:REVIEWS_FOR]->(rest1:Restaurant)-[c1:IN_CATEGORY]->(cat:Category)-[c2:IN_CATEGORY]-(rest2:Restaurant)
WHERE NOT (user)--(rest2) AND toFloat(rest2.stars) > 3.5 AND toFloat(rest2.review_count) > 50
RETURN rest2 LIMIT 15