Easily illustrated bug, the getTotalNumItems() returns ONLY the results returned up to the current page. I saw a link that said the issue was fixed in Enterprise…has anyone fixed (or know how to fix) Community 4.2.f? If so, could you please share the fix? I believe this is the same issue: https://issues.alfresco.com/jira/browse/MNT-2839 (marked fixed in Enterprise).
int reqPageNum = 0; ItemIterable<QueryResult> results = session.query(cql, false, context).skipTo(reqPageNum * maxItemsPerPage).getPage(maxItemsPerPage); long total = results.getTotalNumItems(); println("========== total: "+total); // will be WRONG and return 10
reqPageNum = 1; results = session.query(cql, false, context).skipTo(reqPageNum * maxItemsPerPage).getPage(maxItemsPerPage); total = results.getTotalNumItems(); println("========== total: "+total); // will be WRONG and return 20
this isn't a simple fix that you can just apply/backport to a single line of code. In order to solve this, internal result set interfaces had to be changed to expose previously internal information (as stated in the comment of Andrew Hind). You should find the fix included in Alfresco 5.0 Community. The essential change is in this line: https://github.com/Alfresco/community-edition/blob/24ae86da33534a90fc10a693f48bc45556fd9d9d/projects... But in 4.2.f you'd need to change a bit to actually be able to call getNumberFound.