Reputation: 13
I need help to limit the nodes to show the graph hierarchy in cayley. Like in OrientDB we have a depth function to restrict the hierarchy to any level up to same level down.
Example: I have a below hierarchy:
A DependsOn B
B RunsOn C
C DependsOn D
D ConnectedTo E
Now, for the above example I have written a below query to show the graph hierarchy.
var path = g.M().Both();
g.V("B").FollowRecursive(path).ForEach( function(v) {
g.V(v.id).OutPredicates().ForEach( function(r){
g.V(v.id).Out().ForEach(function(t){
var node = {
source: v.id,
relation : r.id
target: t.id
}
g.Emit(node)
})
}
})
So, when I am passing B to the query it will return me the complete hierarchy but I want only A ,B & C nodes to show for 1 level hierarchy from B, same thing for 2 level hierarchy I want to show A,B,C & D as it should show 2 level up and 2 level down from the B node.
Upvotes: 0
Views: 97
Reputation: 2367
You can limit the depth by passing the max depth as second parameter to the FollowRecursive function:
g.V("B").FollowRecursive(path,2 )
Please not that you start a new path in the foreach which does not know about the max depth in the outer function.
A more detailed discussing about this use-case can be found at the 'cross-post' on the official Cayley forum: https://discourse.cayley.io/t/cayley-0-7-0-depth-function-issue/1066
Upvotes: 2