Reputation: 23
I have a graph but need to be sure that all nodes are in the path (but more than those nodes can exist in the path).
Here is an example (sorry, had to black some stuff out):
I want to find end2 and not end1 when I have the values of the same property in all three intermediary nodes in the list I pass in. But I can't get a query that will return end2 without end1. There can be more nodes out there that have the same routes but I will only every pass in distinct values that are not duplicated across the middle nodes. Anyone know of a query that will give me only the end node that has all the values from the intermediary nodes? There are also nodes that hang off of those end nodes and some of them interlink between end1 and end2. Some others do not and those are the nodes I do not want but because there is a path between the yellow and blue to that end1 I can't use ANY but because there other paths to those same nodes (not pictured) I can't use ALL either.
Thanks in advance for help.
[Update] Here is the current query I use but it only allows for one "end" node per a start node and I want multiple. I needed that id(eg)={eg_id} passed in but that limits it to one. I would much rather use the fact that every a in the path below needs to match up to the list of name properties in the middle node must be there to get to which end node. So if yellow and blue are htere then end1 and end2 would come back but if yellow, blue and purple are there then only end2 would come back.
start td = node({td_id})
match (td:Start)-[:Rel1]->(a)<-[:Rel2]-(eg:End)-[es:Rel3]->(n:WhatsPastEnd)
with collect(a.name) as pnl, n, td, eg, es
where id(eg) = {eg_id}
and all(param_needs in {param_name_list} where param_needs in pnl)
return n
order by es.order
[SOLVED]
Thank you very much InverseFalcon, got what I need from the solution below!
Upvotes: 0
Views: 428
Reputation: 30397
Okay, let's modify your query, and drop the matching of the endnode id.
start td = node({td_id})
// unwind your list of names so every row has a name
with td, {param_name_list} as param_names
unwind param_names as param_name
match (td:Start)-[:Rel1]->(a)
where a.name = param_name
// now a has all nodes with the required names
// collect then unwind so we have the full collection for each a
with collect(a) as requiredNodes
unwind requiredNodes as a
match (a)<-[:Rel2]-(eg:End)
where all(node in requiredNodes where (node)<-[:Rel2]-(eg))
with eg
match (eg)-[es:Rel3]->(n:WhatsPastEnd)
return n
order by es.order
Upvotes: 0