gpt4 book ai didi

Neo4j 密码 : Using LIMIT and COLLECT (or using LIMIT twice in the same query)

转载 作者:行者123 更新时间:2023-12-04 22:06:15 24 4
gpt4 key购买 nike

我有一个时间线类型查询,可以检索帖子和“喜欢”帖子的用户。

START me=node:node_auto_index(UserIdentifier='USER0')
MATCH me-[rels:FOLLOWS*0..1]-myfriend
WITH myfriend
MATCH myfriend-[:POSTED*]-statusupdates<-[r?:LIKE]-likers
WHERE myfriend <> statusupdates
RETURN distinct statusupdates, FILTER (x in collect(distinct likers) : x <> null), myfriend
ORDER BY statusupdates.PostTime DESC
LIMIT 25;

我将检索到的帖子数量限制为 25。我还想限制点赞帖子的用户数量。有没有办法在查询中使用多个限制子句?理想情况下,我想做以下事情:
START me=node:node_auto_index(UserIdentifier='USER0')
MATCH me-[rels:FOLLOWS*0..1]-myfriend
WITH myfriendMATCH myfriend-[:POSTED*]-statusupdates<-[r?:LIKE]-likers
WHERE myfriend <> statusupdates
RETURN distinct statusupdates, LIMIT FILTER (x in collect(distinct likers) : x <> null) 6, myfriend
ORDER BY statusupdates.PostTime DESC
LIMIT 25;

或者:
START me=node:node_auto_index(UserIdentifier='USER0')
MATCH me-[rels:FOLLOWS*0..1]-myfriend
WITH myfriendMATCH myfriend-[:POSTED*]-statusupdates<-[r?:LIKE]-likers
WHERE myfriend <> statusupdates
RETURN distinct statusupdates, FILTER (x in collect(distinct likers) : x <> null), myfriend
LIMIT likers 6
ORDER BY statusupdates.PostTime DESC
LIMIT 25;

这会将每个帖子的返回点赞数限制为 6。我怎样才能做到这一点?

最佳答案

限制喜欢者的问题在于它位于查询的另一端,因此无法对其进行优化。你基本上必须做两场比赛。此外,WITH 之后的 LIMIT 仅在 1.9.M01 中可用

所以,我认为这种做你想要的:

START me=node:node_auto_index(UserIdentifier='USER0')
MATCH me-[rels:FOLLOWS*0..1]-myfriend-[:POSTED*]-statusupdates<-[r?:LIKE]-likers
WITH distinct likers
// you can also order by something here, if you want.
LIMIT 6
START me=node:node_auto_index(UserIdentifier='USER0')
// at this point, likers is already bound, so it's limited to the 6
MATCH me-[rels:FOLLOWS*0..1]-myfriend-[:POSTED*]-statusupdates<-[r?:LIKE]-likers
RETURN distinct statusupdates, likers, myfriend
ORDER BY statusupdates.postTime
LIMIT 25;

未经测试的代码。希望它有效——下次在控制台中为我们构建一个示例,这样我们就可以玩了。 :)

关于Neo4j 密码 : Using LIMIT and COLLECT (or using LIMIT twice in the same query),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13408111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com