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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]