简体   繁体   English

Neo4j和Cypher语法:匹配节点组/集合中的所有路径

[英]Neo4j and Cypher syntax: match all the paths among a group/collection of nodes

I'm trying to match all the paths (up to a certain length) among a group of nodes. 我试图匹配一组节点之间的所有路径(最大长度)。 I can successfully do so by issuing the following query: 我可以通过发出以下查询来成功完成此操作:

MATCH (n) WHERE ID(n) IN [1, 2, 3, 4, 5]
MATCH (m) WHERE ID(m) IN [1, 2, 3, 4, 5]
MATCH paths = allShortestPaths((n)-[*..3]-(m))
RETURN paths

I'm satisfied with both the result itself and its speed. 我对结果本身及其速度都感到满意。 What I don't understand is whether there is a way of defining a variable to define the collection [1, 2, 3, 4, 5] just once. 我不明白的是,是否有一种定义变量的方法来只定义一次集合[1、2、3、4、5]。 Sort of: 有点:

x = [1, 2, 3, 4, 5]
MATCH (n) WHERE ID(n) IN x
MATCH (m) WHERE ID(m) IN x
MATCH paths = allShortestPaths((n)-[*..3]-(m))
RETURN paths

Is this possible? 这可能吗? I've tried several alternatives (using WITH and AS) but with no luck. 我尝试了几种选择(使用WITH和AS),但是没有运气。

Thanks 谢谢

Use: 采用:

WITH [1, 2, 3, 4, 5] AS x

As in: 如:

WITH [1, 2, 3, 4, 5] AS x
MATCH (n) WHERE ID(n) IN x
MATCH (m) WHERE ID(m) IN x
MATCH paths = allShortestPaths((n)-[*..3]-(m))
RETURN paths

By the way, there seems to be a regression in neo4j-community-2.2.0-M03, which causes an error with the above query. 顺便说一句,neo4j-community-2.2.0-M03中似乎存在回归,这导致上述查询出错。 M02 seems to have no problems. M02似乎没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM