如何在Cypher中返回集合联盟的唯一元素?

时间:2013-09-26 11:19:01

标签: neo4j cypher

我有以下问题:我想要回复评论家评论过的所有独特瓶子,如果他们评论的任何瓶子目前在特定商店出售。 问题是我在两个集合中都有重复项,虽然我可以单独过滤它们,但我无法过滤连接结果:

START shop=node:shops('SHOP_ID:...') 
MATCH (shop)-[:SELLS]->(bottle)<-[:REVIEWED]-(critic)-[:REVIEWED]->(other_bottle)  
WITH  critic, COLLECT(DISTINCT(bottle))) + COLLECT(DISTINCT(other_bottle))) as all_bottles 
RETURN wine_critic, all_bottles

1 个答案:

答案 0 :(得分:3)

尝试:

START shop=node:shops('SHOP_ID:...') 
MATCH (shop)-[:SELLS]->(bottle)<-[:REVIEWED]-(critic)
WITH critic
MATCH (critic)-[:REVIEWED]->(other_bottle)  
RETURN  critic, COLLECT(other_bottle) as all_bottles