Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-24-2019 04:37 PM
I want to return one row for each segment in a path. This is the Cypher code I've devised so far. There must be a better way.
match ... --> (i:IMAGE)
match p = (i)-[*]->(f:IMAGE) where NOT (f)-->(:IMAGE)
with nodes(p) as q
with [[q[0],q[1]], [q[1],q[2]], [q[2],q[3]], [q[3],q[4]], [q[4],q[5]], [q[5],q[6]]] as tuples
unwind tuples as seg
return seg[0].name as from, seg[1].name as to
My biggest problem is that it only goes six levels deep. Another inconvenience is that it returns lots of null rows for shallow paths.
04-24-2019 05:02 PM
APOC Procedures can help here, notably the function apoc.coll.pairsMin()
, which takes a list, such as [1,2,3,4,5]
, and breaks it down to a list of adjacent pairs, in this example case: [[1,2], [2,3], [3,4], [4,5]]
You can use this to get pairs of adjacent nodes in the list:
...
UNWIND apoc.coll.pairsMin(nodes(p)) as pair
RETURN pair[0].name as from, pair[1].name as to
04-24-2019 08:38 PM
Thank you. This is what I had hoped to find.
All the sessions of the conference are now available online