Since jackrabbit 2.0, calling getSize() on a NodeIterator which results of an unordered query yields -1 (it's because of access limitation, the NodeIterator may skip results on the fly when iterating).
A jackrabbit-only workaround exists: a getTotalSize() method exists in the QueryResultImpl class, which returns the total node count (introduced in https://issues.apache.org/jira/browse/JCR-1073), but may not be accurate for the reason of access limitation.
In our case, as we do not use access limitation, the result should be exact. We could build our NodeIteratorIterable providing the getTotalSize from the query and return this size instead of the iterator's getSize if the latter is -1.