FollowRecursive / Morphism Path


#1

I would like to make a suggestion to add a parameter to FollowRecursive / Morphism where the results will return an array of nodes which represent the path taken to each result. This will also allow calculation of a count which will represent depth.

Here is my use case.

A follows B follows C follows D
B follows D status OK
C follows E follows F status OK

My search would be something like

g.V(‘A’).FollowRecursive(g.M().Out(‘follows’)).Has(‘status’, ‘OK’).All()

with an expected result set of

{ result: [ { id: ‘D’ }, {id: ‘F’ }}

Now, I can enhance the query to save and tag so that I can get a parent and a meaningful attibute, but I can’t currently get the entire path each final result.

With this parameter, I would hope to get something like this:

{ result: [
{ id: ‘D’, path: [ {id: ‘A’}, { id: ‘B’} ] }, // I went from A to B to get to D
{ id: ‘F’, path: [ {id: ‘A’}, { id: ‘B’}, { id: ‘C’}, { id: ‘E’} ] } // I went from A to B to C to E to get to F
]
}

… assuming those were the paths it took to get to D and F that is.

I can also get that count which will tell me that it took 2 hops to get from A to D or 4 hops to get from A to F

Perhaps the parameter could be injected into the morphism like so:

g.V(‘A’).FollowRecursive(g.M(true).Out(‘follows’)).Has(‘status’, ‘OK’).All()

where true represents adding the path to each result.


#2

Yes, this is something we want to consider for v0.8. Currently it’s not possible to pass arrays from TagResults, thus it will not work unless you can call some new method on RecursiveIterator itself.

Opened an issue to track progress: https://github.com/cayleygraph/cayley/issues/715