Reputation: 547
I am trying to use Gremlin to traverse outwards from a starting node to all connected nodes within X degrees of connection. The direction of the connection does not matter, so I am using the both()
function. I also want to be able to prevent the traversal from crossing edges with specific labels. Here's a sample graph.
gremlin> g.addV().property(id,1).as('1').
......1> addV().property(id,2).as('2').
......2> addV().property(id,3).as('3').
......3> addV().property(id,4).as('4').
......4> addV().property(id,5).as('5').
......5> addV().property(id,6).as('6').
......6> addV().property(id,7).as('7').
......7> addE('edge1').from('1').to('2').
......8> addE('edge2').from('1').to('3').
......9> addE('edge2').from('2').to('4').
.....10> addE('edge3').from('3').to('5').
.....11> addE('edge3').from('4').to('6').
.....12> addE('edge4').from('7').to('6').iterate()
The traversal that I have so far looks like this:
gremlin> g.V(1).
......1> repeat(both().filter(not(inE('edge3')))).
......2> times(4).
......3> emit().
......4> simplePath().
......5> dedup()
However this is not quite what I am looking for. I want something which will actually prevent the traverser from hitting a vertex if it has to cross the specified edge. My current implementation filters vertices which have the incoming edge, but in some cases I may still want that vertex to appear in the results if the traverser crossed a different edge to get there.
Does this make sense? In short, I am trying to specifically filter on an edge rather than on a vertex's relationship to its edges.
Upvotes: 1
Views: 2925
Reputation: 46206
I think I followed what you were saying, couldn't you just use bothE()
and filter those edges while traversing them:
gremlin> g.V(1).
......1> repeat(bothE().not(hasLabel('edge3')).otherV()).
......2> times(4).
......3> emit().
......4> simplePath().
......5> dedup()
==>v[2]
==>v[3]
==>v[4]
Upvotes: 2