0
votes

I have the following statement:

MATCH path=(p:Person {person_id: '123'})-[:ASSOCIATED_WITH]-(:Person)
where exists((p)-[:BELONGS]-(:Face)-[:CORRESPONDS]-(:Image)-[:HAS_ACCESS_TO]-(:Dias {group_name: 'group'}))
RETURN path

It returns 3 nodes, 2 relationships. This is what I would like to happen but the group_name I will actually be passing is an array. How do I add the condition to check for the value in the array while still maintaining 3 nodes and two relationships? The only relationship I want to return back is ASSOCIATED_WITH. The 3 nodes being, the main person_id of "123" and the two associated persons.

1
1. Do you need the EXISTS test to pass for ALL the names in the list, or simply ANY name in the list? 2. It is only reasonable to expect the exact same 3 nodes and relationships to be returned as long the actual data in your DB allows that to happen.cybersam

1 Answers

1
votes

I will assume you pass the list of group names in a names parameter.

If you want to get the paths in which the EXISTS test succeeds for ANY name in the list:

MATCH (p:Person {person_id: '123'})
WHERE ANY(x IN $names WHERE
  EXISTS((p)-[:BELONGS]-(:Face)-[:CORRESPONDS]-(:Image)-[:HAS_ACCESS_TO]-(:Dias {group_name: x})))
MATCH path=(p)-[:ASSOCIATED_WITH]-(:Person)
RETURN path

Or, if you want to get the paths in which the EXISTS test succeeds for ALL names in the list, just replace ANY in the above request with ALL:

MATCH (p:Person {person_id: '123'})
WHERE ALL(x IN $names WHERE
  EXISTS((p)-[:BELONGS]-(:Face)-[:CORRESPONDS]-(:Image)-[:HAS_ACCESS_TO]-(:Dias {group_name: x})))
MATCH path=(p)-[:ASSOCIATED_WITH]-(:Person)
RETURN path