lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joshua O'Madadhain <>
Subject Re: Sorting Options for Query Results
Date Fri, 16 Nov 2001 22:48:39 GMT
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 Per
    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:   <>
For additional commands, e-mail: <>

View raw message