提取物在Cypher过滤

时间:2014-05-13 08:36:33

标签: filter neo4j cypher

我正在尝试解决这个问题,但它仍有问题..好吧,我的查询有点复杂,因为我使用提取,短路径和过滤器。当我在下面尝试此代码时,它返回过滤器需要在哪里..

match (actor:Actor{name:"XXXX"}),(reeves:Actor{name:"YYYY"}),  
p= shortestPath ((actor)-[*..20]-(reeves))
where "Reeves, Keanu"=filter(n2 in nodes(p):n.name)
return distinct extract(n in nodes(p)|n.name) as Names;

但正如你所看到的那样,"其中"关键字。

我尝试了那样

match (actor:Actor{name:"XXXX"}),(reeves:Actor{name:"YYYY"}),  
p= shortestPath ((actor)-[*..20]-(reeves))
WHERE NOT ALL (x IN  nodes(p)
       WHERE x.name<> "YYYY")
return distinct extract(n in nodes(p)|n.name) as Names;

但是这一次,我仍然得到了&#34; Reeves,Keanu&#34; name ..我想从我的结果中过滤此名称..

我在哪里犯了错误?

1 个答案:

答案 0 :(得分:2)

如果要查找包含名称“YYYY”的最短路径,请尝试:

MATCH (actor:Actor{name:"XXXX"}), (reeves:Actor{name:"YYYY"}),  
  p = shortestPath ((actor)-[*..20]-(reeves))
WHERE any(n2 in nodes(p) WHERE n2.name="YYYY")
RETURN distinct extract(n in nodes(p) | n.name) as Names;

另一方面,如果你想忽略包含名称“YYYY”的最短路径:

MATCH (actor:Actor{name:"XXXX"}), (reeves:Actor{name:"YYYY"}),  
  p = shortestPath ((actor)-[*..20]-(reeves))
WHERE none(n2 in nodes(p) WHERE n2.name="YYYY")
RETURN distinct extract(n in nodes(p) | n.name) as Names;

顺便提一下,请注意anynone谓词在内部需要WHERE clause的方式。