chris
chris

Reputation: 35

get row count before pagination in neo4j cypher query

I have a little problem with displaying the results from neo4j. I'm using a server side jquery datatable, in which I need to define the iTotalDisplayRecords, which is the number of records that resulted after the filtering. My cypher query is like this:

UNWIND {json} as data
WITH data
WHERE (data.entry =~ {searchText} OR ....)
RETURN { entry: data.entry, name: data.name, .... }
ORDER BY {field} ASC SKIP {offset} LIMIT {number}

So, I need the number of records before the LIMIT is applied, but I can't manage to retrieve that number, anyone can help me with this?

Thank you in advance

Upvotes: 1

Views: 757

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39915

Naive idea: you can add a WITH doing count(*) as aggregation and collecting data into a collection that gets UNWINDed later on:

UNWIND {json} as data
WITH data
WHERE (data.entry =~ {searchText} OR ....)
WITH count(*) as count, collect(data) as dataColl
UNWIND dataColl as d
RETURN { entry: d.entry, name: d.name, .... , count: count}
ORDER BY {field} ASC SKIP {offset} LIMIT {number}

Upvotes: 1

Related Questions