简体   繁体   English

Neo4j密码查询以查看给定节点是否已连接

[英]Neo4j cypher query to see whether given nodes are connected

Given the following nodes B,E,F,G,H,J,K. 给定以下节点B,E,F,G,H,J,K。 I have to write a neo4j query to check how these nodes are connected each other. 我必须编写一个neo4j查询来检查这些节点如何相互连接。

For example, suppose this is the pattern I want to display. 例如,假设这是我要显示的图案。

B-H-F 
  |
  G-J-K-E   

What is the query to display this graph? 显示该图的查询是什么? I don't want to display all other nodes which are connected to these nodes. 我不想显示连接到这些节点的所有其他节点。

You need to find the paths between each pair of source nodes. 您需要找到每对源节点之间的路径。

Make sure that each path consists of only those nodes that are included in the source set. 确保每个路径仅包含源集中包含的那些节点。

You can do this with a cypher: 您可以使用密码进行此操作:

WITH {GIVEN_NODES} as NDS // The source array of node IDs
UNWIND RANGE(0, size(NDS)-2) as i
UNWIND RANGE(i+1, size(NDS)-1) as j
WITH NDS,
     NDS[i] as N1,
     NDS[j] as N2
MATCH path = (N1)-[*]-(N2) 
      WHERE length(path)+1 <= size(NDS) AND
      ALL(n in nodes(path) WHERE n in NDS)
RETURN path

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

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