Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

cypher - Subqueries in neo4j 3.5 (for Pagination)

I am trying to implement a pagination using neo4j 3.5 and I realized that subqueries (such as Call {}) is not supported in this version. The common approach for pagination in this particular version is (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}

This works if the block where we get the count is just a single type. I have a complex query that has nested matches like:

MATCH (px:Type1)-[:Relationship1]->(pvx:Type2 { prop:'somevalue'})-[:Relationship2]->(bx:Type3)                     
     MATCH (px)-[:Rel3]->(ptx:Type4)
// and so on

To get the value of this complex query, I had to enclose the query inside "apoc.cypher.run", which I was able to successfully get with this:

CALL apoc.cypher.run("MATCH (x:Type1) return count(*) as total", {})
YIELD value
return value.total

Is there a way to pass the result of this apoc.cypher.run to the second query, so I may be able to return the total number of records, as a variable in the second query?

question from:https://stackoverflow.com/questions/65930337/subqueries-in-neo4j-3-5-for-pagination

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Something like this?

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}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...