neo4j 3.5 中的子查询(用于分页)
Subqueries in neo4j 3.5 (for Pagination)
我正在尝试使用 neo4j 3.5 实现分页,我意识到此版本不支持子查询(例如 Call {})。此特定版本中分页的常用方法是 (cypher pagination total result count):
// -------------------------------------
// FIRST QUERY
// -------------------------------------
MATCH (x:Brand)
WITH count(*) as total
// -------------------------------------
// SECOND QUERY
// -------------------------------------
MATCH (o:Brand)
WITH total, o
ORDER BY o.name SKIP 5 LIMIT 5
WITH total, collect({uuid:o.uuid, name:o.name}) AS brands
RETURN {total:total, brands:brands}
如果我们获取计数的块只是单一类型,则此方法有效。我有一个复杂的查询,其中包含嵌套的匹配项,例如:
MATCH (px:Type1)-[:Relationship1]->(pvx:Type2 { prop:'somevalue'})-[:Relationship2]->(bx:Type3)
MATCH (px)-[:Rel3]->(ptx:Type4)
// and so on
为了获得这个复杂查询的值,我必须将查询包含在“apoc.cypher.run”中,我可以通过以下方式成功获得:
CALL apoc.cypher.run("MATCH (x:Type1) return count(*) as total", {})
YIELD value
return value.total
有没有办法将这个 apoc.cypher.run 的结果传递给第二个查询,这样我就可以 return 记录总数,作为第二个查询中的变量?
是这样的吗?
CALL apoc.cypher.run("MATCH (x:Type1) return count(*) as total", {})
YIELD value AS total
WITH total
MATCH (o:Brand)
WITH total, o
ORDER BY o.name SKIP 5 LIMIT 5
WITH total, collect({uuid:o.uuid, name:o.name}) AS brands
RETURN {total:total, brands:brands}
我正在尝试使用 neo4j 3.5 实现分页,我意识到此版本不支持子查询(例如 Call {})。此特定版本中分页的常用方法是 (cypher pagination total result count):
// -------------------------------------
// FIRST QUERY
// -------------------------------------
MATCH (x:Brand)
WITH count(*) as total
// -------------------------------------
// SECOND QUERY
// -------------------------------------
MATCH (o:Brand)
WITH total, o
ORDER BY o.name SKIP 5 LIMIT 5
WITH total, collect({uuid:o.uuid, name:o.name}) AS brands
RETURN {total:total, brands:brands}
如果我们获取计数的块只是单一类型,则此方法有效。我有一个复杂的查询,其中包含嵌套的匹配项,例如:
MATCH (px:Type1)-[:Relationship1]->(pvx:Type2 { prop:'somevalue'})-[:Relationship2]->(bx:Type3)
MATCH (px)-[:Rel3]->(ptx:Type4)
// and so on
为了获得这个复杂查询的值,我必须将查询包含在“apoc.cypher.run”中,我可以通过以下方式成功获得:
CALL apoc.cypher.run("MATCH (x:Type1) return count(*) as total", {})
YIELD value
return value.total
有没有办法将这个 apoc.cypher.run 的结果传递给第二个查询,这样我就可以 return 记录总数,作为第二个查询中的变量?
是这样的吗?
CALL apoc.cypher.run("MATCH (x:Type1) return count(*) as total", {})
YIELD value AS total
WITH total
MATCH (o:Brand)
WITH total, o
ORDER BY o.name SKIP 5 LIMIT 5
WITH total, collect({uuid:o.uuid, name:o.name}) AS brands
RETURN {total:total, brands:brands}