Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-21-2020 02:51 AM
Hello,
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
Solved! Go to Solution.
09-21-2020 03:53 AM
You should convert to float all your numbers.
Otherwise:
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
09-21-2020 03:02 AM
Hello @engr.muzamilshah
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
Regards,
Cobra
09-21-2020 03:25 AM
Thank you so much for your fast response.
09-21-2020 03:44 AM
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"
As you can see it lists up also those restaurant which have review count less than 50.
Thanks
09-21-2020 03:53 AM
You should convert to float all your numbers.
Otherwise:
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
09-21-2020 03:56 AM
Thank you so much.
Your assistance is really appreciable.
All the sessions of the conference are now available online