简体   繁体   English

Cayley:如何设置极限/深度以在Cayley中显示图形层次结构?

[英]Cayley : How to put the limit/depth to show the graph hierarchy in cayley?

I need help to limit the nodes to show the graph hierarchy in cayley. 我需要帮助来限制节点以在cayley中显示图层次结构。 Like in OrientDB we have a depth function to restrict the hierarchy to any level up to same level down. 像在OrientDB中一样,我们有一个depth函数来将层次结构限制到同一级别的任何级别。

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. 因此,当我将B传递给查询时,它将返回完整的层次结构,但我只希望A,B和C节点显示B中的1级层次结构,而我想要显示2级层次结构的相同内容,则要显示A,B, C和D,因为它应该显示从B节点向上2级和向下2级。

You can limit the depth by passing the max depth as second parameter to the FollowRecursive function: 您可以通过将最大深度作为第二个参数传递给FollowRecursive函数来限制深度:

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. 请不要在foreach中开始一个新路径,该路径不知道外部函数的最大深度。

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 有关此用例的更详细讨论,请参见官方Cayley论坛上的“ cross-post”: https : //discourse.cayley.io/t/cayley-0-7-0-depth-function-issue / 1066

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM