首页 文章

通过边缘标签过滤Gremlin Traversal

提问于
浏览
0

我正在尝试使用Gremlin从起始节点向外遍历到连接点的所有连接节点 . 连接的方向无关紧要,所以我使用 both() 函数 . 我还希望能够防止遍历与特定标签交叉边缘 . 这是一个示例图 .

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()

到目前为止我的遍历看起来像这样:

gremlin> g.V(1).
......1>   repeat(both().filter(not(inE('edge3')))).
......2>   times(4).
......3>   emit().
......4>   simplePath().
......5>   dedup()

然而,这并不是我想要的 . 我想要的东西实际上会阻止遍历器撞到一个顶点,如果它必须越过指定的边缘 . 我当前的实现过滤了具有传入边缘的顶点,但在某些情况下,如果遍历器越过不同的边缘到达那里,我可能仍然希望该顶点出现在结果中 .

这有意义吗?简而言之,我试图专门过滤边缘而不是顶点与边缘的关系 .

1 回答

  • 1

    我想我跟着你说的话,你不能只使用 bothE() 并在遍历它们时过滤这些边缘:

    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]
    

相关问题