Reputation: 695
I have written below query using lucene indexing . I know UNION doesn't have pagination support in neo4j . I want to post process the final result of this query to paginate the result .
START user=node:peopleSearch('username:abhay*') RETURN user , user.createdDate as time UNION START rel= Relationship:peopleSearch('skillName:Java23') RETURN StartNode(rel) as user , StartNode(rel).createdDate as time
I have followed this link . But it giving me error on UNION RESULT .
I need to post process the union final result to paginate it
Upvotes: 2
Views: 348
Reputation: 39905
The referenced github issue is not yet resolved, so post processing of UNION
is not yet possible.
As a workaround in the meantime you can split up your query into two queries. The first one combines the index lookups and returns node ids:
START user=node:peopleSearch('username:abhay*') RETURN id(user) as id
UNION
START rel= Relationship:peopleSearch('skillName:Java23') RETURN id(StartNode(rel)) as id
On client side, collect the returned IDs into an array and submit the second query using a cypher parameter:
MATCH (n)
WHERE ID(n) IN {myIdArray}
WITH n
// placeholder for rest of this query
where the parameter value of myIdArray
is the returned IDs from step1.
I had a similar question a few weeks ago, and it turns out Cypher currently does not support post-UNION processing.
This means that you should filter both inputs of the union using the same condition.
Alternatively (as mentioned in this answer), if you can use APOC, you can post-process the results of a query:
CALL apoc.cypher.run("... UNION ...", NULL) YIELD n, r, x
WHERE ...
RETURN n, r, x;
Update: this is now possible in Neo4j 4.0 using the CALL {subquery}
construct.
Upvotes: 2