Hi all,
we are trying to use Neo4j to provide users feed. For this we are using specific user relations and trying to give weights on these relations. We want also to sum the weights for identical posts to sort them up in the results.
Can someone point us in way to achieve this scenario ?
Relations and weights
// (5) Post by users you follow
OPTIONAL MATCH (p:Post {public: true})-[:BELONGS]->(:User)<-[:FOLLOWS]-(:User {userId: "LeCNgLeKqkPND1eSaZH3y47mZsM2"})
WITH CASE WHEN p IS NOT NULL THEN collect({post:p, w: 5}) ELSE [] END as posts
// (5) Post you have been tagged on
OPTIONAL MATCH (p:Post {public: true})-[:MENTION]->(:User {userId: "LeCNgLeKqkPND1eSaZH3y47mZsM2"})
WITH CASE WHEN p IS NOT NULL THEN posts + collect({post:p, w: 5}) ELSE posts END as posts
// (4) Post by users from communities/clans you belong to
OPTIONAL MATCH (p:Post {public: true})-[:BELONGS]->()<-[:IS_MEMBER {isPending: false}]-(:User {userId: "LeCNgLeKqkPND1eSaZH3y47mZsM2"})
WITH CASE WHEN p IS NOT NULL THEN posts + collect({post:p, w: 4}) ELSE posts END as posts
// (3) Posts by users playing the same games as you
OPTIONAL MATCH (p:Post {public: true})-[:BELONGS]->(:User)-[:LIKES]->(:Game)<-[:LIKES]-(:User {userId: "LeCNgLeKqkPND1eSaZH3y47mZsM2"})
WITH CASE WHEN p IS NOT NULL THEN posts + collect({post:p, w: 3}) ELSE posts END as posts
// (3) Post by user who follows you
OPTIONAL MATCH (p:Post {public: true})-[:BELONGS]->(:User)-[:FOLLOWS]->(:User {userId: "LeCNgLeKqkPND1eSaZH3y47mZsM2"})
WITH CASE WHEN p IS NOT NULL THEN posts + collect({post:p, w: 3}) ELSE posts END as posts
// (1) Post by followers of people you follow
OPTIONAL MATCH (p:Post {public: true})-[:BELONGS]->(:User)-[:FOLLOWS]->(:User)<-[:FOLLOW]-(:User {userId: "LeCNgLeKqkPND1eSaZH3y47mZsM2"})
WITH CASE WHEN p IS NOT NULL THEN posts + collect({post:p, w: 1}) ELSE posts END as posts
// (1) Some other random post (fillers)
MATCH (p:Post {public: true})
WITH CASE WHEN p IS NOT NULL THEN posts + collect({post:p, w: 1}) ELSE posts END as posts
UNWIND posts as row
RETURN row.w as w, row.post.postId, row.post.name, row.post.createdAt as createdAt
order by w DESC
skip 0
limit 10