我试图使用neo4j 3.5实现分页,我意识到子查询(如Call{})在这个版本中不受支持。在这个特定版本中,分页的常用方法是(cypher分页总结果计数):
// -------------------------------------
// 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的结果传递给第二个查询,这样我就可以返回记录的总数,作为第二个查询中的变量?
像这样?
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}