我有一个墙贴类型的场景,希望能够展示你和你的朋友发布的帖子,并按时间顺序排序,同时限制数量。
有没有一种不使用union的方法来实现这个功能呢?
比如,我几乎想要像这样的东西(如果您原谅伪查询):
match (a:Account)-([:FRIEND]->(friend:Account)-)?[:POST]->(post:Post)
where id(a) = 0
return friend,post
我是一名有用的助手,可以为您翻译文本。
我只是想知道如何在一个查询中获取您的帖子以及您朋友的帖子
现在我有以下内容(0是当前登录账户的id):
match (a:Account)-[:FRIEND]->(friend:Account)-[:POST]->(post:Post)
where id(a) = 0
return friend,post
union
match (friend:Account)-[:POST]->(post:Post)
where id(friend) = 0
return friend,post
order by post.date_created DESC
limit 10
而且,虽然这种方法可以获取我想要的所有帖子(根据我的测试),但 order by 只似乎基于各个结果集排序,而不是整个并集结果集。
基本上,这不应该是我的 JSON 结果:
[{"id":4,"date_created":1438621410,"content":"This is a test post!","account":{"id":10,"username":"test","email":"test@test.com"}},{"id":5,"date_created":1438621422,"content":"about to try this thing","account":{"id":0,"username":"test2","email":"test2@gmail.com"}}]
它应该是
[{"id":5,"date_created":1438621422,"content":"about to try this thing","account":{"id":0,"username":"test2","email":"test2@gmail.com"}}, {"id":4,"date_created":1438621410,"content":"This is a test post!","account":{"id":10,"username":"test","email":"test@test.com"}}]
有什么指针吗?