我有一个架构:主题有帖子,用户写主题和帖子。我想找到推荐的主题。在我的例子中,我返回count(主题)和count(rec_topics)。如何在这些集合之间返回差异?像[1,2] - [1] = [2]
谢谢
MATCH (user:User {first_name: 'Hlavní' }),
user<-[:wrote_by]-(posts:Post)<-[:TOPIC]-(topics:Topic)-[:TOPIC]->(all_posts:Post)-[:wrote_by]->(friends:User)<-[:wrote_by]-(friends_posts:Post)<-[:TOPIC]-(rec_topics:Topic)
WHERE NOT(topics=rec_topics)
RETURN count(DISTINCT topics),count(DISTINCT rec_topics);
答案 0 :(得分:3)
您可以使用collect
为主题和rec_topics构建集合。在第二步中,列表推导可用于仅返回那些不属于rec_topics的主题:
MATCH (user:User {first_name: 'Hlavní' }),
user<-[:wrote_by]-(posts:Post)<-[:TOPIC]-(topics:Topic)-[:TOPIC]->
(all_posts:Post)-[:wrote_by]->(friends:User)<-[:wrote_by]-
(friends_posts:Post)<-[:TOPIC]-(rec_topics:Topic)
WHERE NOT(topics=rec_topics)
WITH collect(DISTINCT topics) as topics, collect(distinct rec_topics) as rec_topics
RETURN [x in topics WHERE not(x in rec_topics)] as delta,
length(topics), length(rec_topics)