3
votes

I am having a a traversal use case as follows .Does orientDb supports it?

1)Find all paths from node1 to node2 .ONLY TRAVERSE those nodes which has property xyz="val1" 2)Find shortest path .ONLY TRAVERSE those nodes which has property xyz="val1" 3)Find longest path .ONLY TRAVERSE those nodes which has property xyz="val1"

abstract class TraversGraph{
     public  Path getPath(Node src,Node dest, Propery property,Value value);
}

Note :Please note the condition which i mentioned in caps

1

1 Answers

7
votes

You can use Gremlin to get paths between two nodes. You can firstly find all the paths, so the shortest and the longest are included in all these paths. Here is an example: enter image description here As you can see in the image, from A to B there are three paths(A->B, A->F->C->B, A->E->D->C->B), but node F doesn't have property "xyz" with value "val1", so this paths should not be included.

Code:

gremlin> g = new TinkerGraph()
==>tinkergraph[vertices:0 edges:0]
gremlin> a = g.addVertex(null,[name: "A", xyz: "val1"])
==>v[0]
gremlin> b = g.addVertex(null,[name: "B", xyz: "val1"])
==>v[1]
gremlin> c = g.addVertex(null,[name: "C", xyz: "val1"])
==>v[2]
gremlin> d = g.addVertex(null,[name: "D", xyz: "val1"])
==>v[3]
gremlin> e = g.addVertex(null,[name: "E", xyz: "val1"])
==>v[4]
gremlin> f = g.addVertex(null,[name: "F"])
==>v[5]
gremlin> g.addEdge(a, b, "KNOWS")
==>e[6][0-KNOWS->1]
gremlin> g.addEdge(a, e, "KNOWS")
==>e[7][0-KNOWS->4]
gremlin> g.addEdge(a, f, "KNOWS")
==>e[8][0-KNOWS->5]
gremlin> g.addEdge(f, c, "KNOWS")
==>e[9][5-KNOWS->2]
gremlin> g.addEdge(e, d, "KNOWS")
==>e[10][4-KNOWS->3]
gremlin> g.addEdge(d, c, "KNOWS")
==>e[11][3-KNOWS->2]
gremlin> g.addEdge(c, b, "KNOWS")
==>e[12][2-KNOWS->1]

And traversel between node A and node B(Here we do not filter the property "xyz"), so we get three paths:

gremlin> a.out('KNOWS').loop(1){it.loops<100}{true}.has('name', 'B').path{it.name}
==>[A, B]
==>[A, F, C, B]
==>[A, E, D, C, B]

And add the filter of property "xyz"

gremlin> a.out('KNOWS').loop(1){it.loops<100 && it.object.hasNot('xyz', null)}{true}.has('name', 'B').path{it.name}
==>[A, B]
==>[A, E, D, C, B]

Thus we get the shortest path: [A, B] and the longest path: [A, E, D, C, B]

English is not my mother language, so if any confusion, feel free to contact me.