neo4j / cypher:查找某些集合中所有节点相邻的所有节点

时间:2015-02-24 17:50:21

标签: neo4j cypher

给定一个节点,s,与某个标签的> 1节点的集合C相邻。我想找到所有与C中每个元素相邻的节点。

更一般地说:

  • 如何在cypher中定义集合或组?
  • 如何找到与集合中所有节点相邻的节点?

这在密码中是否可行?

1 个答案:

答案 0 :(得分:1)

是的,绝对的,这在密码中是可行的。这是一个例子。

// start with finding the start node 's' and the adjacent nodes
match (s:Node {name: 's'} )-[:ADJ]->(C:Node)
// match only the adjacent nodes that have 'set C'
where C.set = 'C'
// pass C onto the remainder of the query
with s,C
// match the nodes that are adjacent to the nodes in 'set C'
match C-[:ADJ]->(adjacent)
// return all of the nodes in set C and a collection of the nodes
// adjacent to the set C nodes
return s.name, C.name, collect(adjacent.name)