lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nadav Har'El" <...@math.technion.ac.il>
Subject Re: HitCollector and Sort Objects
Date Sun, 02 Jul 2006 06:57:35 GMT
On Thu, Jun 29, 2006, James Pine wrote about "HitCollector and Sort Objects":
> I have one type of search where I pass in a Query and
> a Sort (built with a SortField and Decompresses) and
> deal with the Hits object, and another which takes a
> Query and a HitCollector, which I then run my own
> sorting on the results.
> 
> I'd like to combine both into one call so that I can
> get the results sorted and have the collected data
> available. Is that crazy talk? Does the way document
> ids stream through the HitCollector prevent sorting
> them first?

The best thing for you to do without changing Lucene is to use the

	search(Query query, HitCollector results)

method. The collect() in the HitCollector you'll write will do what you
want it to do, and finally call collect() of a TopFieldDocCollector
object that you'll creat. TopFieldDocCollector collects the top-ranking
documents using a given Sort (see its documentation).

This will give you a "TopDocs", not a "Hits" object. But when you know
in advance how many results you want (which is almost always the case),
this is enough for you.

I raised the idea of having a search() method which returns a Hits and
calls a HitCollector, but was convinced that TopDocs+HitCollector is
actually better. See:

http://www.gossamer-threads.com/lists/lucene/java-dev/37277

Maybe this should be in the FAQ.

-- 
Nadav Har'El                        |        Sunday, Jul 2 2006, 6 Tammuz 5766
IBM Haifa Research Lab              |-----------------------------------------
                                    |Recursive, adj.: See Recursive
http://nadav.harel.org.il           |

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


Mime
View raw message