lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <>
Subject Re: sorting by score and an additional field
Date Thu, 04 Nov 2004 09:33:12 GMT
On Nov 3, 2004, at 9:52 PM, Chris Fraschetti wrote:
> Has anyone had any luck using lucene's built in sort functions to sort
> first by the lucene hit score and secondarily by a Field in each
> document indexed as Keyword and in integer form?

I get multiple sort fields to work, here's two examples:

         new Sort(new SortField[]{
           new SortField("category"),
           new SortField("pubmonth", SortField.INT, true)

        new Sort(new SortField[] {SortField.FIELD_SCORE, new 

Both of these, on a tiny dataset of only 10 documents, works exactly as 

> I can only get it to sort by one or the other... but when it does one,
> it does sort correctly, but together in {score, custom_field} only the
> first sort seems to apply.
> Any ideas?

Are you using Lucene 1.4.2?  How did you index your integer field?  Are 
you simply using the .toString() of an Integer?  Or zero padding the 
field somehow?  You can use the .toString method, but you have to be 
sure that the sorting code does the right parsing of it - so you might 
need to specify SortField.INT as its type.  It will do automatic 
detection if the type is not specified, but that assumes that the first 
document it encounters parses properly, otherwise it will fall back to 
using a String sort.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message