假设这是你的图表:
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> addE('supplies').from('1').to('2').
......7> addE('supplies').from('1').to('3').
......8> addE('required').from('2').to('4').
......9> addE('required').from('3').to('4').
.....10> addE('required').from('3').to('5').
.....11> addE('required').from('6').to('5').iterate()
,这是预期的输出:
gremlin> g.V(1).
......1> out().
......2> outE().
......3> aggregate('edges').
......4> inV().
......5> where(inE('required').
......6> where(not(within('edges'))).
......7> count().is(eq(0))).
......8> dedup()
==>v[4]
然后聚集边缘已经走过边缘可能是最好的办法。 (它总是最好的,包括一个示例图表作为您的问题一个小鬼脚本)我想这是值得注意的是,你不需要在你的is()
和not(without(...))
的eq()
只是without
:
gremlin> g.V(1).
......1> out().
......2> outE().
......3> aggregate('edges').
......4> inV().
......5> where(inE('required').
......6> where(without('edges')).
......7> count().is(0)).
......8> dedup()
==>v[4]
或者只是所有计数一起做掉,因为你想那些不返回新边的顶点穿越:
gremlin> g.V(1).
......1> out().
......2> outE().
......3> aggregate('edges').
......4> inV().
......5> not(inE('required').
......6> where(without('edges'))).
......7> dedup()
==>v[4]
上述方法可能是因为只有一个边缘从 立即返回你的inE('required').where(not(within('edges')))
过滤器会立即过滤更好顶点出来,你不必等待所有边的计数。
你的假设是正确的。本来希望添加一个示例图,但不知道我会如何去做这件事。我们花了很多时间尝试一些类似的东西,但无法使其发挥作用。用你的解决方案就可以。感谢您的建议,我认为这改善了我们的查询。 – Mischa