cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How do search for a node that has realtionship match against any element in an array

I have this query where I am trying to fetch clubs that matches as many tags in an array of tags as it can in order.

So far I have something like this (ClubTags is the array of tags):

WITH c
UNWIND (CASE $ClubTags WHEN then else $ClubTags end) AS tag
MATCH (c)-[r:HAS_TAG]->(t:ClubTag {name:tag})
RETURN c

This matches and returns clubs that match atleast one tag. But I cant seem to make out how I can expand on this to further count r (count of r always returns 1 from within UNWIND). Im guessing UNWIND is not what I should be using here but I am not sure how else I can match against all tags within the array.

edit : The squares in the abouve code are just open close of array that I am using to handle empty clubtags

1 ACCEPTED SOLUTION

clem
Graph Steward

I think... (still at intermediate level Cypher)

WITH c
MATCH (c)-[r:HAS_TAG]->(t:ClubTag)
WHERE t.name IN $ClubTags // assuming $ClubTags  is [] when there are no tags
RETURN c, count(r)

View solution in original post

2 REPLIES 2

clem
Graph Steward

I think... (still at intermediate level Cypher)

WITH c
MATCH (c)-[r:HAS_TAG]->(t:ClubTag)
WHERE t.name IN $ClubTags // assuming $ClubTags  is [] when there are no tags
RETURN c, count(r)

ooo I think this would work. I will try it out tomorrow but it makes a lot of sense. Thanks a lot.