How to put the limit/depth to show the graph hierarchy in cayley?


#1

Hi All

I want to know like how 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.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.

var path = g.M().Both();
g.V(“B”).FollowRecursive(path).ForEach( function(v){
g.V(v.id).OutPredicates().ForEach( function®{
g.V(v.id).Out().ForEach( function(t){
var node = {
source: v.id,
relation : r.id
target: t.id
}
g.Emit(node)
})
})
})

Please help me out .Thanks in advance.


#2

Hi @amritsingh

I have seen similar kind of question posted by you when it was not implemented. Can you please help me out with the syntax, how we can limit the loading of the schema using depth function or anything else.

Thanks in advance.


#3

Hey @Chaitanya,
I use cayley as library. The schema package has functions to control depth. But in your case, FollowRecursive method allows a second argument to control the depth.
So, please try the following code. I have not tested it, but it should work.

    var path = g.M().Both();
    var depth=10;
    g.V("B").FollowRecursive(path,depth).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)
            })
        })
    })
 

I hope this helps.


#4

Hi @amritsingh

I have tried this syntax but it showing below error :

ERROR: The requested URL could not be retrieved

I think FollowRecursive is not accepting more then one parameter.

Please help me out. Thanks.


#5

@Chaitanya you need to update your cayley package. Depth is surely accepted as second parameter.
You can have a look at the following example or the commit . One of the test case from above link is:

{
	message: "recursive follow tag",
	query: `
		g.V("<charlie>").FollowRecursive("<follows>", "depth").All();
	`,
	tag:    "depth",
	expect: []string{intVal(1), intVal(1), intVal(2), intVal(2)},

},


#6

Hi @amritsingh

Thanks for the quick response.

I am using latest version of cayley database (v0.6.1) but still facing the same error when i am running the same query from the cayley UI console (http://localhost:64210/)

Please find the screenshot for the same.


FollowRecursive is not a function
#7

The latest pre-built binary for cayley was created from this source code. So it does not have all the latest features. You have to build cayley from source. The instructions are https://github.com/cayleygraph/cayley/blob/master/docs/Contributing.md. That will resolve your problem.


#8

As a note, I narrowed down a scope of v0.7 to release all these features in upcoming weeks. It will push this feature to binary releases.