Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-17-2020 02:02 AM
Hello neo4j,
Hope you guys having a nice day today.
By the way, I made some queries for showing the place is associated with some city.
So, I want to limit the result place of each city. for example,
if location A is related with 10 City and location B is related with 10 cities, I just want to reduce the number of each result as 6. ( location A is related with 6 places, and location B is related with 6 places)
For my business logic, I use where any()
clause for showing variety Possibility of results.
here is my code.
MATCH (place)<-[:IS_Location]-(location:Location)
WHERE any (
filters IN ['ALL', 'B', 'C', 'D', 'E']
WHERE (place)<-[:IS_Location]-(location{name : filters})
with distinct location // I add this statement
limit 10 // and this statement
)
I add two statements, but it doesn't work.
I really need some help and also any comments would be appriciated.
Thanks!
09-18-2020 12:27 AM
Hello @gjtnwjd40
You can use a subquery:
MATCH (place)
CALL {
WITH place
MATCH (place)<-[:IS_Location]-(location:Location)
WHERE any(filter IN ['ALL', 'B', 'C', 'D', 'E'] WHERE location.name = filter)
RETURN DISTINCT location, place
LIMIT 10
}
RETURN location, place
Regards,
Cobra
09-21-2020 12:20 AM
Hi, @Cobra
Thank you for your help.
But I got an error like below.
Invalid input '{': expected whitespace, comment, namespace of a procedure or a procedure name (line 8, column 6 (offset: 227))
"CALL {"
^
So I search for this error,
And I found that it occurs because of the neo4j version.
I had a neo4j 3.5.x version, but if I would like to use CALL {}
, I have to use neo4j version 4.1.
But I can't upgrade the neo4j version right now, because there is a code that communicated with python. ( yeah, it's python driver code )
so, It would be appreciated if you suggest a solution when using a version of 3.5.x in neo4j.
Warmest Regards,
Sujeong 🙂
09-18-2020 04:44 AM
Thanks for your reply!
I'll try and adapt that in my code.
Regards,
sujeong
09-21-2020 12:29 AM
Hi @gjtnwjd40
Sure, I'm sorry, since you didn't specify the neo4j version, I thought you were on 4.0
MATCH (place)
WITH id(place) AS idp
CALL apoc.cypher.run('
MATCH (place)<-[:IS_Location]-(location:Location)
WHERE id(place) = $idp
AND any(filter IN $filters WHERE location.name = filter)
RETURN DISTINCT location, place
LIMIT 10
', {idp:idp, filters:['ALL', 'B', 'C', 'D', 'E']}) YIELD value
RETURN value.location AS location, value.place AS place
Documentation:
Regards,
Cobra
All the sessions of the conference are now available online