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 Ganesh <em...@yahoo.co.in> on 2012/07/17 12:53:51 UTC

Multiple sort field

Hello all,

I have more than one record having same time stamp. When i sort by date time in decending order, the set of records which have same time stamp are displayed in the order of insertion. Basically it is displayed with asscending order of docid. But i want the reverse of that.

Consider the below set of records.
record_1  201207170101
record_2  201207170101
record_3  201207170102
record_4  201207170102

After search, it displays the results in below order
record_3  201207170102
record_4  201207170102
record_1  201207170101
record_2  201207170101

But i want, sort on date time and again sort on docid in reverse order.
record_4  201207170102
record_3  201207170102
record_2  201207170101
record_1  201207170101

Is it good to use multiple sort fields? Using sort on docid will consume any memory? Is there any other way out to acheive this.

Regards
Ganesh

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Multiple sort field

Posted by Erick Erickson <er...@gmail.com>.
Lucene certainly supports multiple sort criteria, see
IndexSearcher.search, any one that takes a Sort
object. The Sort object can contain a list of fields where
any ties in the first N field(s) are decided by looking
at field N+1.

But, Ganesh, be a little careful about resolving by internal
Lucene doc ID. Not only do they change during merges, but
some policies re-order them. I'd put in an ordinal number
that was the insertion order.

Best
Erick

On Wed, Jul 18, 2012 at 8:34 AM, googoo <li...@gmail.com> wrote:
> I don't think lucene will support multi sort.
> If you look into org.apache.lucene.search.TopScoreDocCollector you may get
> some feeling.
> It use max heap to sort the document, and the score is one time calculate,
> it it not first sort by time, then sort again by id.
>
> When lucene sort below documents:
> record_1  201207170101
> record_2  201207170101
> record_3  201207170102
> record_4  201207170102
>
> first get record_1, and it score is 201207170101, then record_1 on top of
> the heap
> tehn get record_2, and it score is 201207170101, then will put record_2
> after record_1
> then get record_3, and it score is 201207170102, this score > current top
> value 201207170101, then the max heap change to record_3, record_1, record_2
> last get record_3, and it score is 201207170102, is score = current top male
> 201207170102, , then the max heap change to record_3, record_4, record_1,
> record_2
>
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Multiple-sort-field-tp3995502p3995699.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Multiple sort field

Posted by googoo <li...@gmail.com>.
I don't think lucene will support multi sort.
If you look into org.apache.lucene.search.TopScoreDocCollector you may get
some feeling.
It use max heap to sort the document, and the score is one time calculate,
it it not first sort by time, then sort again by id. 

When lucene sort below documents:
record_1  201207170101 
record_2  201207170101 
record_3  201207170102 
record_4  201207170102 

first get record_1, and it score is 201207170101, then record_1 on top of
the heap
tehn get record_2, and it score is 201207170101, then will put record_2 
after record_1
then get record_3, and it score is 201207170102, this score > current top
value 201207170101, then the max heap change to record_3, record_1, record_2
last get record_3, and it score is 201207170102, is score = current top male
201207170102, , then the max heap change to record_3, record_4, record_1,
record_2




--
View this message in context: http://lucene.472066.n3.nabble.com/Multiple-sort-field-tp3995502p3995699.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Multiple sort field

Posted by Ian Lea <ia...@gmail.com>.
> Any thoughts on this?

Patience ...

> Is it good to use multiple sort fields?

Absolutely, if that's what you need.  On the other hand, if you don't
need it then it's a bad idea.

> Using sort on docid will consume any memory?

Don't know.  Certainly won't use less than not sorting this way.

> Is there any other way out to acheive this.

If you could get a full timestamp you could index it as a NumericField
and sort on that.  Or you could add some value to the existing
timestamp to make each one unique.  Probably other ways too but that's
all I can think of right now.


--
Ian.


On Wed, Jul 18, 2012 at 6:34 AM, Ganesh <em...@yahoo.co.in> wrote:
> Any thoughts on this?
>
> Regards
> Ganesh
>
> ----- Original Message -----
> From: "Ganesh" <em...@yahoo.co.in>
> To: <ja...@lucene.apache.org>
> Sent: Tuesday, July 17, 2012 4:23 PM
> Subject: [Bulk] Multiple sort field
>
>
> Hello all,
>
> I have more than one record having same time stamp. When i sort by date time in decending order, the set of records which have same time stamp are displayed in the order of insertion. Basically it is displayed with asscending order of docid. But i want the reverse of that.
>
> Consider the below set of records.
> record_1  201207170101
> record_2  201207170101
> record_3  201207170102
> record_4  201207170102
>
> After search, it displays the results in below order
> record_3  201207170102
> record_4  201207170102
> record_1  201207170101
> record_2  201207170101
>
> But i want, sort on date time and again sort on docid in reverse order.
> record_4  201207170102
> record_3  201207170102
> record_2  201207170101
> record_1  201207170101
>
> Is it good to use multiple sort fields? Using sort on docid will consume any memory? Is there any other way out to acheive this.
>
> Regards
> Ganesh
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Multiple sort field

Posted by Ganesh <em...@yahoo.co.in>.
Any thoughts on this?

Regards
Ganesh

----- Original Message ----- 
From: "Ganesh" <em...@yahoo.co.in>
To: <ja...@lucene.apache.org>
Sent: Tuesday, July 17, 2012 4:23 PM
Subject: [Bulk] Multiple sort field


Hello all,

I have more than one record having same time stamp. When i sort by date time in decending order, the set of records which have same time stamp are displayed in the order of insertion. Basically it is displayed with asscending order of docid. But i want the reverse of that.

Consider the below set of records.
record_1  201207170101
record_2  201207170101
record_3  201207170102
record_4  201207170102

After search, it displays the results in below order
record_3  201207170102
record_4  201207170102
record_1  201207170101
record_2  201207170101

But i want, sort on date time and again sort on docid in reverse order.
record_4  201207170102
record_3  201207170102
record_2  201207170101
record_1  201207170101

Is it good to use multiple sort fields? Using sort on docid will consume any memory? Is there any other way out to acheive this.

Regards
Ganesh

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org