SKIP和LIMIT是否基于ORDER子句?

时间:2016-04-12 20:40:58

标签: neo4j

我有这样的查询:

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

SKIPLIMIT子句是否适用于返回的事件节点数?我问,因为虽然我想回归演员和关系,但我不希望演员和关系节点影响分页。

如果不是这种情况,那么对不同event个节点进行正确分页的最佳方法是什么?

谢谢!

2 个答案:

答案 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值),这就是SKIPLIMIT的真实情况条款适用于。

要将SKIPLIMIT条款应用于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个结果行,这允许SKIPLIMIT子句适用于event