问题
Currently Pagination isn't supported in SDN4 (Ref: Paging and sorting in Spring Data Neo4j 4)
It's possible to specify the SKIP and LIMIT clauses ourselves to retrieve parts of the results, however for our system we also need the getTotalPages(), isFirst() and isLast() values from the Page returned when performing a custom paging query.
Is there an alternative way for us to retrieve these values using SDN4 / OGM? Alternatively, are there any recommendations / references to code that can be provided for us to implement this ourselves (perhaps in the construction of the Page object)?
Thanks!
回答1:
As you have gathered, the Pagination object in the OGM which backs Spring's Page object does not use a page count or return one. Spring's Page object provides a method to return the total number of pages, but it is up to the underlying implementation - Mongo, JPA, Neo4j, etc to implement this. Spring's Page object uses this value to determine whether or not a "next" page exists. Our implementation "cheats" by telling Spring that it always does - until a request for a new page returns fewer than a page worth of results.
Unfortunately there is no generalised way to return a page count that doesn't involve finding all of the results first and then counting them. Doing this for custom queries that may potentially return many thousands of rows runs the obvious risk of running out of heap space on the server. (Note that the underlying implementation in Neo4j using SKIP and LIMIT does not have to pre-load all the results into memory so it does not run into this problem).
来源:https://stackoverflow.com/questions/32011358/sdn4-custom-query-pagination-alternative-for-page-contents