cancel
Showing results for 
Search instead for 
Did you mean: 

Finding variable sized paths based on nodes properties

sswamp
Node

Hello,
I only want to get/return paths between City (red) nodes, that go through Cable (blue) nodes and have property state:"working" Image here is only an example; path lengths between cities can be longer.

3X_2_0_208c942f795937c886b1ed7b75a1365f3365e86d.png

I mean something like this (not working):

MATCH p=(c1:City)-[*]-(c2:City) WHERE (x in nodes(p) WHERE x.state="working") RETURN p

This gives almost what I want:
match p=(c1:City {name:"Oslo"})-[*]-(c2:City {name:"Copenhagen"}) with nodes(p) as ns unwind [x in ns where x.state IS NOT NULL and x.state="working"] as ss return distinct(ss)
but I would like to get whole paths between to cities (with relationships).

1 REPLY 1

glilienfield
Ninja
Ninja

Try this.

MATCH p=(c1:City)-[*]-(c2:City)
with p, [x in nodes(p) where x:Cable] as cableNodes
WHERE all (x in cableNodes WHERE x.state="working")
and c1<>c2
RETURN p

Note, you will probably get all kinds of unexpected paths because your pattern is not very restricted. For instance, in your example, you could get paths that traverse the c1 and c2 nodes multiple times, form loops, and terminate on the same starting node (I added a constraint against that in the query). The only restriction will be that a path will not traverse the same relationship twice.