Red*_*ile 3 union neo4j cypher
有一个墙贴类型的场景,我想把你和你的朋友的帖子按时间顺序排列,有限制
有没有办法在不使用联合的情况下做到这一点?
就像,我几乎喜欢这样的东西(如果你能原谅伪查询):
match (a:Account)-([:FRIEND]->(friend:Account)-)?[:POST]->(post:Post)
where id(a) = 0
return friend,post
Run Code Online (Sandbox Code Playgroud)
我只是想知道如何在一个查询中获取您的帖子以及您朋友的帖子
现在我有(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
Run Code Online (Sandbox Code Playgroud)
虽然这适用于获取我想要的所有所需帖子(根据我的测试),但 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"}}]
Run Code Online (Sandbox Code Playgroud)
它应该是
[{"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"}}]
Run Code Online (Sandbox Code Playgroud)
任何指针?
布赖恩·安德伍德 (Brian Underwood) 的回答恰好将我引向了正确的方向,但最终尝试的解决方案产生了不太正确的结果
然而,经过一番修补后,我确实偶然发现了这个获胜的查询:
MATCH (a:Account)-[:FRIEND*0..1]->(friend:Account)-[:POST]->(post:Post)
WHERE id(a) = 0
RETURN friend,post
ORDER BY post.date_created DESC
LIMIT 10
Run Code Online (Sandbox Code Playgroud)
希望这有助于其他使用 Neo 的人获取 Facebook “Wall” 之类的更新,其中包括您自己的帖子。
对此查询的任何改进都是受欢迎的,但是,我不知道它到底有多有效,只知道它确实排序正确,并且据我所知,到目前为止也有相应的限制