Cypher - 在哪里交叉

时间:2016-06-01 10:48:16

标签: neo4j cypher

查询:

MATCH (movie:Movie {name:'The Matrix'})-[:has_tag]->(movie1Tag:Tag)
WITH movie, collect(movie1Tag) AS movie1Tags
MATCH (movie2:Movie)-[:has_tag]->(movie2Tag:Tag)
WITH movie, movie1Tags, collect(movie2Tag) AS movie2Tags, movie2
WHERE ANY(movieTag IN movie1Tags 
                  WHERE movieTag IN movie2Tags) 
      AND NOT movie.name = movie2.name
RETURN DISTINCT movie2.name

有没有办法从WHERE ANY声明返回交叉点?有没有办法修改查询以返回它们?

编辑: 由于Anomaly211的答案,我得到了它的工作。我还使用EXTRACT将交叉点应用于关系,我已将其包含在下面以备人们感兴趣

MATCH (movie:Movie {name:'The Matrix'})-[:has_tag]->(movie1Tag:Tag) 
WITH movie, collect(movie1Tag) AS movie1Tags 
MATCH (movie2:Movie)-[:has_tag]->(movie2Tag:Tag) 
WITH movie, movie1Tags, collect(movie2Tag) AS movie2Tags, movie2 
WITH movie, movie1Tags, collect(movie2Tag) AS movie2Tags, movie2 FILTER(x IN movie1Tags WHERE x IN movie2Tags) AS intersect 
    FILTER(x IN movie1Tags WHERE x IN movie2Tags) AS intersect
WHERE ANY(movieTag IN movie1Tags WHERE movieTag IN movie2Tags) AND NOT movie.name = movie2.name AS intersect 
CREATE UNIQUE (movie)-[:share_tags {shared:EXTRACT(x IN intersect | x.identifier)}]->(movie2)
RETURN DISTINCT movie2.name, intersect

1 个答案:

答案 0 :(得分:1)

您可以过滤结果并检查交叉点。

 FILTER(x IN movie1Tags.name WHERE x IN movie2Tags.name)

这应该只为您提供movie1tags和movie2tags

中都存在的标签