Neo4j检查物业密码

时间:2016-08-02 23:36:41

标签: neo4j

我有一组节点,如下面的示例图片。是否有一个密码查询可以检查节点是“关闭”还是“打开”(绿色);如果它是“on”,它返回“on”节点连接的节点和连接到“on”的原始节点。如果节点“关闭”,它只返回连接到它的节点。在此示例中,它应返回label1和label2,但不返回label3。

example

2 个答案:

答案 0 :(得分:1)

您可以将optional matchwith组合使用union

// Is the starting node
MATCH (S {name: 'label1'})
WITH S
  // Get the nodes to which have access through a pattern of "ON"
  OPTIONAL MATCH (S)-[:connect]->({on: true})-[:connect]->(onC)
WITH S, collect(distinct onC) as onConnect
  // Get the nodes to which have access through a pattern of "OFF"
  OPTIONAL MATCH (S)-[:connect]->({on: false})<-[:connect]-(offC)
WITH S, onConnect, collect(distinct offC) as offConnect
  // Remove possible duplicates
  UNWIND S + onConnect + offConnect as N
RETURN collect(distinct N) as result

答案 1 :(得分:0)

我假设&#39; on&#39;并且&#39;关闭&#39;是一个参数的状态。我将在代码中将其称为State。 我也假设您想要从特定节点开始。我不知道你是如何得到这个节点所以我假设你有ID,它等于1

MATCH(a) - [r:connect * ..] - &gt;(b)其中ID(n)= 1 b.State =&#39; on&#39;返回b