我有这样的查询:
MATCH
(card:`card`),
(event:`event`),
(card)<-[:includes_card]-(event)
WHERE
card.id = "0000000978LBtZz08W5439Mvo"
OPTIONAL MATCH
(actor:`user`),
(card)-[includes_actor_rel:includes_actor]->(actor)
RETURN event, actor, includes_actor_rel
ORDER BY event.created_at DESC
SKIP 50
LIMIT 5
SKIP
和LIMIT
子句是否适用于返回的事件节点数?我问,因为虽然我想回归演员和关系,但我不希望演员和关系节点影响分页。
如果不是这种情况,那么对不同event
个节点进行正确分页的最佳方法是什么?
谢谢!
答案 0 :(得分:1)
我会用这样的方式编写这个查询:
MATCH
(card:card {id: "0000000978LBtZz08W5439Mvo"})
WITH
card
MATCH
(event)-[:includes_card]->(card:card)
WITH
card, event ORDER BY event.created_at DESC SKIP 50 LIMIT 5
MATCH
(card)-[includes_actor_rel:includes_actor]->(actor:user)
RETURN
event, actor, includes_actor_rel
答案 1 :(得分:1)
您的查询将为每个includes_actor_rel
关系返回一行(其中一些关系可以共享相同的event
值),这就是SKIP
和LIMIT
的真实情况条款适用于。
要将SKIP
和LIMIT
条款应用于event
,您可以执行以下操作:
MATCH
(card:card)<-[:includes_card]-(event:event)
WHERE
card.id = "0000000978LBtZz08W5439Mvo"
OPTIONAL MATCH
(card)-[includes_actor_rel:includes_actor]->(actor:user)
RETURN event, COLLECT({actor: actor, rel: includes_actor_rel}) AS data
ORDER BY event.created_at DESC
SKIP 50
LIMIT 5;
此查询的COLLECT()
aggregation函数使用event
作为分组键,为同一event
创建所有actor / rel对的集合。这导致每event
个结果行,这允许SKIP
和LIMIT
子句适用于event
。