【发布时间】:2020-08-13 14:58:12
【问题描述】:
Gremlin: Count connections ignoring edges with a parallel edge in the opposing direction 在这个问题中,我想知道是否有办法找到从给定顶点以两种方式连接的顶点。我们知道 dedup() 是为了避免重复。但是有什么方法可以找到具有平行边的顶点吗?
【问题讨论】:
Gremlin: Count connections ignoring edges with a parallel edge in the opposing direction 在这个问题中,我想知道是否有办法找到从给定顶点以两种方式连接的顶点。我们知道 dedup() 是为了避免重复。但是有什么方法可以找到具有平行边的顶点吗?
【问题讨论】:
搜索具有平行边的顶点是循环检测的一种特殊情况。
您可以找到循环检测的配方here。
与您的情况相匹配的代码的简化版本:
g.V().as('a').
out().simplePath().where(out().as('a')).
path().dedup().by(unfold().
order().by(id).
dedup().fold())
【讨论】:
g.V(x.id()).as('a').out('label').where(out('label').as('a')),注意这个查询也会返回第一个顶点,如果它连接到自己