I'm having trouble writing a Cypher query for this social networking type of application. It involves users that add posts (essentially an image with a description), which users can review.
In Cypher the graph model is this:
(user)-[:WROTE_REVIEW]->(review)-[:EVALUATES]->(post)
The query I'm trying to write should return all the posts that a particular user has reviewed, along with some general information about the reviews of a post.
This includes:
- (the post's ID)
- the post's image
- the post's description
- the total number of reviews of this post
- the total number of reviewers of this post
- the avatars of the last 6 reviewers of this post, ordered by the date of the review, descending
I think I've managed to complete the first five items, but item 6 is giving me trouble. The query below gives me all of the avatars, while I only need the last 6.
START user=node(2515)
MATCH (user)-[:WROTE_REVIEW]->()-[:EVALUATES]->(post)
WITH distinct post
MATCH (review)-[:EVALUATES]->(post)
WITH post, count(review) as reviews
MATCH (reviewer)-[:WROTE_REVIEW]->()-[:EVALUATES]->(post)
WITH post, reviews, count(distinct reviewer) as reviewers, collect(distinct reviewer.Avatar) as avatars
ORDER BY post.CreationTime DESC
RETURN post.Id, post.Image, post.Description, reviews, reviewers, avatars;
Can someone show me how to order the avatars by review date (i.e. review.CreationTime
) descending, and take the first six items?
Thanks!