在 Cypher 中是否可以 'repeat' 超过一跳的模式?

Is it possible to 'repeat' a pattern of more than one hop in Cypher?

假设图中有两种关系::A:B。有像 (n1)-[:A]->(n2)->[:B]->(n3)->[:A]->(n4)->[:B]->(n5)->... 这样的模式。在这里,我只显示了这个“:A,然后是 :B”模式的 2 次重复,但它可以重复到任意深度。查询 'start with node X, then follow this A+B pattern as far as you can, then take the resulting node Y'.

之类的内容可能会很有趣

Gremlin中,可以使用repeat步来实现这样的查询。

在 Cypher 中,有可变长度的模式 https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-varlength ,因此我们可以为简单的重复模式编写类似 (x)-[:A*]->(y) 的内容,我们只重复一个跃点。

但是我们可以对更复杂的模式(如我描述的 A+B 模式)做同样的事情吗?

我在他们推荐使用过程的地方找到了这个 ,但它不是纯 Cypher(它是 Neo4J 的非标准扩展,在其他实现 Cypher 的系统中不可用)。

目前只有关系序列的 APOC 方法。

MATCH (start:Node {id:123})
CALL apoc.path.expandConfig(start, {relationshipFilter:'A,B'}) YIELD path

我们绝对希望能够捕获重复序列,无论是在这个更简单的示例中还是在更复杂的用例中,并且已经围绕它们进行了设计讨论。所以这还不是现在,但设计和实施一个好的解决方案只是时间问题。