neo4j为什么在结果集中找不到启动节点?

时间:2013-11-23 17:35:17

标签: neo4j match cypher

我没有在Neo4j手册中找到有关此问题或发现任何评论。

此查询返回起始节点:

start n = node:node_auto_index(subject_id='A1')
match (n)-[]->()<-[]-(n)
return distinct n.subject_id;
==> +--------------+
==> | n.subject_id |
==> +--------------+
==> | "A1" |
==> +--------------+
==> 1 row 

但此查询不返回起始节点。有没有办法让它与其他匹配节点一起返回起始节点?

start n = node:node_auto_index(subject_id='A1')
match (n)-[]->()<-[]-(s)
where s.subject_id = 'A1'
return distinct s.subject_id;
==> +--------------+
==> | s.subject_id |
==> +--------------+
==> +--------------+
==> 0 row

为了确保我的语法正确,以前的查询适用于除起始节点以外的节点:

start n = node:node_auto_index(subject_id='A1')
match (n)-[]->()<-[]-(s)
where s.subject_id = 'B2'
return distinct s.subject_id;
==> +--------------+
==> | s.subject_id |
==> +--------------+
==> | "B2" |
==> +--------------+
==> 1 row

1 个答案:

答案 0 :(得分:2)

我认为你在密码路径中遇到了标识符唯一性。

在同一路径中,两个不同的标识符(如果没有预先绑定)将不会指向同一个节点。

在你的第一个例子中,路径的两边都绑定(到同一个节点),在最后一个例子中,你有两个不同的节点,一个绑定到n另一个绑定到s。< / p>

在第二个示例中,您最终会将同一节点绑定到ns,而cypher在路径中不会这样做。