You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by tsuraan <ts...@gmail.com> on 2010/02/03 19:40:46 UTC

Sort and Collector

Is there any way to run a search where I provide a Query, a Sort, and
a Collector?  I have a case where it is sometimes, but rarely,
necessary to get all the results from a query, but usually I'm
satisfied with a smaller amount.  That part I can do with just a query
and a collector, but I'd like the results to be sorted as they are
submitted to the collector's collect method.  Is that possible?

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Sort and Collector

Posted by tsuraan <ts...@gmail.com>.
> It's not really possible.
> Lucene must iterate over all of the hits before it knows for sure that
> it has the top sorted by any criteria (other than docid).
> A Collector is called for every hit as it happens, and thus one can't
> specify a sort order (sorting itself is actually implemented with a
> sorting Collector).

Ok, so the sort doesn't actually affect the order in which a searcher
iterates over an index, it just gets used by a TopDocsCollector to
sort hits as they come in.  I guess that makes sense.  Thanks!

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Sort and Collector

Posted by Yonik Seeley <yo...@lucidimagination.com>.
On Wed, Feb 3, 2010 at 1:40 PM, tsuraan <ts...@gmail.com> wrote:
> Is there any way to run a search where I provide a Query, a Sort, and
> a Collector?  I have a case where it is sometimes, but rarely,
> necessary to get all the results from a query, but usually I'm
> satisfied with a smaller amount.  That part I can do with just a query
> and a collector, but I'd like the results to be sorted as they are
> submitted to the collector's collect method.  Is that possible?

It's not really possible.
Lucene must iterate over all of the hits before it knows for sure that
it has the top sorted by any criteria (other than docid).
A Collector is called for every hit as it happens, and thus one can't
specify a sort order (sorting itself is actually implemented with a
sorting Collector).

-Yonik
http://www.lucidimagination.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org