我在为这种社交网络类型的应用程序编写 Cypher 查询时遇到问题。它涉及用户添加帖子(本质上是带有描述的图像),用户可以查看这些帖子。
在 Cypher 中,图模型是这样的:(user)-[:WROTE_REVIEW]->(review)-[:EVALUATES]->(post)
我尝试编写的查询应返回特定用户已审阅的所有帖子,以及有关帖子评论的一些一般信息。
这包括:
- (帖子ID)
- 帖子的图片
- 帖子的描述
- 该帖子的评论总数
- 该帖子的审阅者总数
- 该帖子最后6位评论者的头像,按评论日期排序,降序排列
我想我已经完成了前五项,但第六项给我带来了麻烦。下面的查询给出了所有头像,而我只需要最后 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;
有人可以告诉我如何按审核日期订购头像(即review.CreationTime
) 下降,并取前六项?
Thanks!
您可以先对行进行排序,然后获取审阅者集合的前 6 行,而不是对集合进行排序。所以将最后一个 match-with 更改为这样的内容,
MATCH (reviewer)-[:WROTE_REVIEW]->(review)-[:EVALUATES]->(post)
With distinct post, reviewer, review
ORDER BY post.CreationTime DESC, review.CreationTime DESC
Return post, count(reviewer) as reviewers, collect(reviewer.Avatar)[0..5] as avatars
访问索引如[0..5]的集合需要2.0 M5的版本。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)