I have a schema like: Topics have posts and users write topics and posts. I would like to find recommended topics. In my example I return count(topics) and count(rec_topics). How is possible to return difference bewteen these sets? Like [1,2] - [1] = [2]
Thank you
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);
You can use collect
to build up a collection for topics and rec_topics. In a second step a list comprehension can be used to return only those topics not being part of 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With