traversal - find path between vertices using edge properties in OrientDB -
is there way find path between 2 vertices including edges having property specific value in orient db ?
i able find path between 2 vertices not able filter out based on edge properties.
if want paths between 2 vertices, can do:
select $path path ( traverse oute(), inv() #13:1 ) @rid == '14:2'
this goes through out edges #13:1, building path. keep end rid #14:2. 1 thing note that, return several paths, if 2 two paths share common track 1 of retrieved (thats thing traverse command preventing loops , efficiency that)
if have further conditions want apply traversal, can put them in while. want take consideration value of test attribute edges:
select $path path ( traverse oute(), inv() #13:1 while (@class == 'v') or (@class == 'e' , test == 3) ) @rid == '14:2'
here need 2 conditions because traversing both vertices , edges, if edge want check on test attribute, if vertex, no condition, keep traversing.
note:
there's caveat traverse command cannot possible paths between 2 vertices (excluding paths cicles), because traverse avoids traversing node more once, $path have 1 path containing target vertex. since filtering paths checking id of traversed node, 1 path cause doesnt traverse node more once. need way find paths without relying on traversed nodes....
we've got edges! here workaround:
begin; let target = select @rid rid, ine() ins <target_id> let paths = select $path path (traverse oute(), inv() <source_id>) @rid in $target['ins']; if ($paths.size() > 0) { let result = select path.append(".inv(").append($target['rid'][0]).append(")") $paths; } if ($paths.size() == 0) { let result = select $paths; } commit; return $result;
so traverse source every path, filter includes incomming edges our target. if path starting source includes incomming edge target, valid path between both. little trick include target vertex in path can return nice , complete path string.
this return paths between 2 vertices, including rels. may pretty greedy way found possible paths.
Comments
Post a Comment