Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-23-2020 08:50 PM
Hi All,
I am learning about APOC spanning trees and about paths and have a question or two that I haven't been able to figure out from the documentation I've been reading/watching.
When I call my apoc spanning tree, currently I'm using the "yield path, return path" ending, because that's all I understand how to do so far (just beginning). It's been successful in returning to me all of the nodes that I wanted and all of the properties on those nodes. If, however, I am only interested in returning certain properties of each of the nodes that are returned within the path, is there a way for me to narrow it down? I feel comfortable doing this on a set of nodes, but not sure how it works with a path of nodes.
I would like to be able to capture the path length, as well as the ordinal position of each node within a particular path, regardless of the length of the path. So for example, if the shortest path is 25 hops, I'd like to know that, and I'd like to be able to see a list of the nodes, their assigned ids(a property I've given), as well as their position (1st-25th) on the path. Is there any documentation someone could point me to so I could figure this out?
Any insight would be appreciated!
-Isaac
11-24-2020 02:55 PM
1.
CALL apoc.path.spanningTree(d, {maxLevel:2}) YIELD path
WITH path
WHERE length(path) <> 0
with nodes(path) as n1, relationships(path) as r1
unwind n1 as n11
unwind r1 as r11
return labels(n11) as lbl, id(n11) as ID
Here you have the handles for nodes and relationships and you can extract any relevant information. Also, change the maxLevel number to extract data up to that level (or hops)
2. Use this to get count, node label at each hop:
CALL apoc.neighbors.athop(d, ">|<", 1) YIELD node
Number 1 indicates the hop level. Changing this 3 gives nodes up to 3 hops.
All the sessions of the conference are now available online