我有一个这样的查询:
MATCH (a)-[:Shout]->(b)
WHERE a.user_id=1
WITH b.post_id as b_post_id, a, b.post as b_post
MATCH (a)-[:Friend]->(c)-[:Shout]->(d)
WITH d.post_id as d_post_id, b_post_id, d.post as d_post, b_post
order by d_post_id desc, b_post_id desc
RETURN collect(distinct d_post) + collect(distinct b_post) as p
我想返回来自用户和朋友的所有帖子,所以我结合了 2 个匹配,第一个匹配(a)-[:Shout]->(b)
将返回来自用户的帖子,第二个匹配(a)-[:Friend]->(c)-[:Shout]->(d)
将返回来自朋友的帖子。
的帖子(a)-[:Shout]->(b)
是
post_id: 5, post: nana
post_id: 2, post: hi
的帖子(a)-[:Friend]->(c)-[:Shout]->(d)
是
post_id: 6, post: lala
post_id: 4, post: hello
post_id: 3, post: hanson
所以,当我RETURN collect(distinct d_post) + collect(distinct b_post) as p
,它将是
P: nana, hi, lala, hello, hanson
它应该是:lala, nana, hello, hanson, hi
或6,5,4,3,2
请帮我。谢谢。