使用OrientDB递归遍历有向边 [英] Traverse directed edges recursively with OrientDB
问题描述
我试图递归遍历给定节点的出站边缘,而不是入站边缘.我想在查询结果中同时包含边缘和顶点.
I am trying to recursively traverse outbound edges from a given node, but not the inbound ones. I want both out edges and out vertices in the result of my query.
在下图中,从(a)开始,我需要(a),(b),(c),(d),(e),包括边缘,但不包括(c)之后的部分,是<-- (x)
In the following graph, starting from (a), I need (a), (b), (c), (d), (e), including the edges, but not the part after (c), which is <-- (x)
(a) --> (b) --> (c) <-- (x)
˙--> (d) --> (e)
如果我尝试执行以下操作,则无论边缘方向如何,它都会递归遍历所有内容,因此也会返回(x):
If I try doing the following, then it traverses everything recursively, irrespective of edge direction, thus also returning (x):
TRAVERSE * FROM (SELECT FROM a) LIMIT -1`
如果我不这样做,则它仅检索起始节点及其直接邻居:(a),(b),(d),因此不进行递归.
If I dont traverse *, but
outE()`, it only retrieves the starting node and its direct neighbours: (a), (b), (d), so it does not do recursion.
traverse outE() from (SELECT FROM a) LIMIT -1
I also tried to follow the documentation at here, and traversed V.out, E.in
but it only returns (a) without traversing.
traverse V.out, E.in from (SELECT FROM a) LIMIT -1`
也尝试过使用WHILE $depth < 10
之类的变体,但这并没有什么区别,现在我被困住了.
Also tried playing with variants, like WHILE $depth < 10
, but that hasn't made any difference and now I'm stuck.
运行OrientDB 2.0.12
Running OrientDB 2.0.12
推荐答案
图:
从#33:289990开始,遍历查询仅递归获得传出边:
Traversal query to get only the outgoing edges recursively starting from #33:289990 :
traverse out('IsFriendsWith') from #33:289990
遍历查询以递归方式获得一个以上的边缘类传出顶点:
Traversal query to get more then one edge class outgoing vertices recursively :
traverse out('IsFriendsWith'), out('secondEdgeClassName') from #33:289990
遍历查询以递归获取边和顶点实例:
Traversal query to get the edge and vertex instances recursively :
traverse out('IsFriendsWith'), outE('IsFriendsWith') from #33:289990
这篇关于使用OrientDB递归遍历有向边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!