lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <DCutt...@grandcentral.com>
Subject RE: ordering of results (alphabetical?)
Date Fri, 19 Oct 2001 15:55:53 GMT
> From: Tom Barrett [mailto:barrett_tom@yahoo.com]
> 
> I am wondering if it is possible to change the ordering of 
> results from
> search. Specifically, we need to sort results alphabetically 
> by a given
> field, rather then by term frequency. I assume there is a way 
> to do this
> with HitCollector, but given the warning about performance in 
> the javadoc
> I'm not sure of the best way to approach this. Any help would be
> appreciated.

The best way might be the obvious way, and it's slow: to enumerate all of
the matching hits and re-sort them.  This requires a disk read for every
document.  If a query has a lot of hits, more than you intend to display,
you can end up doing a lot of extra i/o.

The only hit ordering that can be efficiently generated, besides by score,
is by document number.  Document numbers correspond to the order the
documents were added to the index.  So if you can somehow add documents to
your index alphabetically, then you can very efficiently get hits sorted
alphabetically.  Currently the best way to do this is through the low-level
HitCollector-based search API.  Just collect the highest or lowest N
document IDs.  This way you can avoid retrieving the Document objects for
hits that you don't intend to display.  I plan to add a friendlier API to
this feature when I get a chance.  Could this approach work for you?

Doug

Mime
View raw message