【发布时间】:2022-12-10 07:41:08
【问题描述】:
我在创建一个非常简单的查询时遇到问题:
让我们假设一个图,其中的节点代表人,边缘类型为“有孩子”。
我以一部分人为起点,我需要找到所有后代(递归)。更具体地说,我只对边缘感兴趣:
例子:
a -> b -> c
d -> b
(starting points = [c]) => []
(starting points = [b]) => [b->c]
(starting points = [a,b,c]) => [a->b, b->c]
(starting points = [d]) => [d->b, b->c]
到目前为止,我得到了这个查询:
g.V().has('name', 'something'). // this line gets replaced by various filters
repeat(outE('child').dedup().inV()).
until(
outE('child').count().is(eq(0))
).
path(). // get all paths
unfold(). // flatten the list of lists
filter(hasLabel('child')). // filter out only edges
dedup()
但是,如果我们在同一路径上选择更多起点(例如可以通过执行 g.V().... 选择所有顶点),则此查询无法正常工作。
【问题讨论】:
-
因此,为了澄清一下,您想取回在到达叶节点之前在起始顶点之间交叉的所有边的去重列表吗?
-
我根据该假设添加了一个答案。
标签: database graph gremlin tinkerpop