NEO4J 1.9.x
我正在尝试创建一个检索用户帖子的查询语句。目前我只提取通过友情关系创建的帖子。这很好,但是,我想插入请求者创建的帖子。结果是包含作者帖子以及朋友帖子的Feed。在我的生活中,我不能弄清楚如何去做。
START
requestor=node:node_auto_index(UID = '19')
MATCH
(requestor)-[:Are_Connected]-(friends)-[:Wrote|Shared]-(post)<-[?:Included_With]-(link)
WHERE
post.type! = "Post"
RETURN DISTINCT post, link
ORDER BY post.createdzulu DESC
这正是我需要的东西。试试这个...
START
requestor=node:node_auto_index(UID = '19')
MATCH
(requestor)-[:Are_Connected]-(friends)-[:Wrote|Shared]-(post)<-[?:Included_With]-(link),
(requestor)-[:Wrote|Shared]-(post)<-[?:Included_With]-(link)
WHERE
post.type! = "Post"
RETURN DISTINCT post, link
ORDER BY post.createdzulu DESC
...不返回任何内容,因为此处的匹配是 AND 而不是 OR
我可以通过执行两个查询并合并结果来以编程方式解决此问题,但这对我的口味来说有点过于苛刻。任何帮助将不胜感激。
答案 0 :(得分:1)
START
requestor=node:node_auto_index(UID = '19')
MATCH
(requestor)-[:Are_Connected]-(friends)-[:Wrote|Shared]-(post)<-[?:Included_With]-(link)
WHERE
post.type! = "Post"
RETURN DISTINCT post, link
ORDER BY post.createdzulu DESC
UNION
MATCH
(requestor)-[:Wrote|Shared]-(post)<-[?:Included_With]-(link)
WHERE
post.type! = "Post"
RETURN DISTINCT post, link
ORDER BY post.createdzulu DESC
答案 1 :(得分:0)
据我所知和理解,我认为我有一个与我想做的查询类似的问题。我记得最后一件事就是在两场比赛中都使用了where子句。
START
requestor=node:node_auto_index(UID = '19')
WHERE
((requestor)-[:Are_Connected]-(friends)-[:Wrote|Shared]-(post)<-[?:Included_With]-(link)
OR
(requestor)-[:Wrote|Shared]-(post)<-[?:Included_With]-(link))
AND WHERE
post.type! = "Post"
RETURN DISTINCT post, link
ORDER BY post.createdzulu DESC
我不确定效率,因为在我使用neo4j的测试中,匹配子句通常更快,但你可以试试。
希望有所帮助