Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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)

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` 

If I dont traverse *, butoutE()`, 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`

Also tried playing with variants, like WHILE $depth < 10, but that hasn't made any difference and now I'm stuck.

Running OrientDB 2.0.12

like image 702
PEER Avatar asked Oct 24 '25 17:10

PEER


1 Answers

Graph : graph friend model representation

Traversal query to get only the outgoing edges recursively starting from #33:289990 :

traverse out('IsFriendsWith') from #33:289990

output of the traversal query

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
like image 128
AlexB Avatar answered Oct 26 '25 20:10

AlexB