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 Jeff Kunkle <Je...@HERNDON-LAB.com> on 2001/11/16 23:01:20 UTC

Sorting Options for Query Results

Hello.  Does anyone know of a way to sort search results other than by
score?  It seems like it would be very useful to be able to sort by date or
maybe even by any field that has been indexed (which I guess would include a
date).  From what I can tell, Lucene does not provide any way to do this
beyond writing your own HitCollector.  Is this correct?  If so, has anyone
had any luck implementing alternate sorting methods?  I have just started
experimenting with Lucene so any help is greatly appreciated.

Thanks,
Jeff

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Sorting Options for Query Results

Posted by Joshua O'Madadhain <jm...@ics.uci.edu>.
On Fri, 16 Nov 2001, Jeff Kunkle wrote:

> Hello.  Does anyone know of a way to sort search results other than by
> score?  It seems like it would be very useful to be able to sort by
> date or maybe even by any field that has been indexed (which I guess
> would include a date).  From what I can tell, Lucene does not provide
> any way to do this beyond writing your own HitCollector.  Is this
> correct?  If so, has anyone had any luck implementing alternate
> sorting methods?  I have just started experimenting with Lucene so any
> help is greatly appreciated.

If what you want to do is to arrange matters so that the Hits object
returned by the search is sorted in some order other than that given by
the built-in score function, I personally don't know how to do this other
than rewriting the HitCollector.  If there *is* a way to do this, I'd also
be interested in knowing what it was.

However, if you're willing to re-sort the search results once you get
them, you should just be able to pull the Documents out of the Hits, copy
them into an array, and sort them according to whatever fields are in the
Document, using your favorite sorting algorithm.  (Or at least I don't see
why you should not be able to do this.)  This method would have the
advantage that you could allow the user the flexibility of being able to
re-sort the results ad hoc after the search returns, rather than forcing
them to choose a single ordering before the search.

Hope this helps...

Joshua

 jmadden@ics.uci.edu...Obscurium Per Obscurius...www.ics.uci.edu/~jmadden
    Joshua Madden: Information Scientist, Musician, Philosopher-At-Tall
 It's that moment of dawning comprehension that I live for--Bill Watterson
My opinions are too rational and insightful to be those of any organization.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>