jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Klimetschek <aklim...@day.com>
Subject Re: NodeIterator.getSize() returns -1 for query with order by clause
Date Wed, 14 Apr 2010 13:17:44 GMT
On Wed, Apr 14, 2010 at 12:40, Gadbury <gadbury@googlemail.com> 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
alexander.klimetschek@day.com

Mime
View raw message