On Wed, Apr 14, 2010 at 12:40, Gadbury <[email protected]> wrote: > But no real answer as to why with a where clause the getSize() returns -1.
The thing is that the spec allows the implementation to return -1. This makes it free to optimize certain queries so that they are fetched on demand (iteration over the result) without having to know the entire result and thus it's count in advance. Jackrabbit's search implementation was improved for 2.0 so that the -1 is seen more often now. Which queries trigger a -1 or the actual size can change any time, so client code should not rely on it (or be prepared to change). Counting yourself by iterating over the result set is an option, albeit it can be slower. A trick is to sort the result set (order by in xpath or sql), which will be slower than not sorting, but can be faster than manual counting (for large result sets). Regards, Alex -- Alexander Klimetschek [email protected]
