首页 > 解决方案 > 查找节点结果集的所有边

问题描述

我有一个返回一组节点的查询,如下所示:

g.V().as("a","node").has("prop1", true).out().as("b","node").hasLabel("device")
.in().as("c","node").hasLabel("lbl1").has("prop1", false).select("a","b","c").limit(200)

现在我想返回所有这些节点以及它们之间的任何边缘作为我的结果。我尝试了以下方法,但它总是空空如也:

g.V().(....)
.select("a","b","c").limit(200)
.select("node").dedup().fold().as('all')
.unfold().as('start').bothE().as('edge').otherV().as('end')
.where(within('all'))
.select('start', 'edge', 'end').dedup()

不幸的是,这总是空的。我认为我的 where 过滤器不正确。如何仅过滤那些节点“c”是“a”中的节点之一的结果?

我想保持这个通用性,这样我就可以用它来处理多个不同的查询,这些查询都返回一组节点。

标签: gremlintinkerpopjanusgraphtinkerpop3

解决方案


对于此查询,您应该检查 out 顶点是否在开始顶点的集合中。因此,您应该首先 fold() 开始集,然后在其中使用 within() 谓词对其进行检查,例如这里是查询g = TinkerFactory.createModern().traversal()

g.V().limit(3).fold().as('all').
    unfold().as('a').outE().as('b').otherV().as('c').
    where(within('all')).
    select('a', 'b', 'c')

请参阅此处的第二个示例:https ://tinkerpop.apache.org/docs/current/reference/#where-step


推荐阅读