Hi chuck,

Thanks a lot this is really helpful.

Thanks,
Ramon

-----Original Message-----
From: Chuck Williams [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 04, 2004 10:05 PM
To: Lucene Users List
Subject: RE: Sorting in Lucene.

Ramon,

I'm not sure where a guide or tutorial might be, but you should be able
to see how to do it from the javadoc.  Look at classes Sort, SortField,
SortComparator.  I've also included a recent message from this group
below concerning sorting with multiple fields.  FYI, a number of people
have wanted to first sort by score and secondarily by another field.
This is tricky since scores are frequently different in low-order
decimal positions.

Good luck,

Chuck

-----Original Message-----
From: Erik Hatcher [mailto:[EMAIL PROTECTED] 
Sent: Thursday, November 04, 2004 1:33 AM
To: Lucene Users List
Subject: Re: sorting by score and an additional field

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"),
           SortField.FIELD_SCORE,
           new SortField("pubmonth", SortField.INT, true)
         });

        new Sort(new SortField[] {SortField.FIELD_SCORE, new 
SortField("category")})

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

> 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.

        Erik



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





  > -----Original Message-----
  > From: Ramon Aseniero [mailto:[EMAIL PROTECTED]
  > Sent: Thursday, November 04, 2004 9:53 PM
  > To: 'Lucene Users List'
  > Subject: RE: Sorting in Lucene.
  > 
  > Hi Chuck,
  > 
  > Can you please point me to some articles or FAQ about Sorting in
Lucene?
  > 
  > Thanks a lot for your reply.
  > 
  > Thanks,
  > Ramon
  > 
  > -----Original Message-----
  > From: Chuck Williams [mailto:[EMAIL PROTECTED]
  > Sent: Thursday, November 04, 2004 9:44 PM
  > To: Lucene Users List
  > Subject: RE: Sorting in Lucene.
  > 
  > Yes, by one or multiple criteria.
  > 
  > Chuck
  > 
  >   > -----Original Message-----
  >   > From: Ramon Aseniero [mailto:[EMAIL PROTECTED]
  >   > Sent: Thursday, November 04, 2004 6:21 PM
  >   > To: 'Lucene Users List'
  >   > Subject: Sorting in Lucene.
  >   >
  >   > Hi All,
  >   >
  >   >
  >   >
  >   > Does Lucene supports sorting on the search results?
  >   >
  >   >
  >   >
  >   > Thanks in advance.
  >   >
  >   > Ramon
  > 
  > 
  >
---------------------------------------------------------------------
  > To unsubscribe, e-mail: [EMAIL PROTECTED]
  > For additional commands, e-mail: [EMAIL PROTECTED]
  > 
  > 
  > 
  > 
  >
---------------------------------------------------------------------
  > To unsubscribe, e-mail: [EMAIL PROTECTED]
  > For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to