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 Aviran Mordo <am...@infosciences.com> on 2003/04/14 21:41:58 UTC

Using doc.id() to sort

I've noticed that whenever I add document to the index the doc.id() gets
the next number.
I use this behavior in order to sort the results by sorting the
doc.id().
Let me explain: If I insert the documents in a specific order to the
index then the order is kept using the doc.id(). Now when I retrieve the
documents after search I can use the doc.id to sort the hits in the
order it was inserted to the index.
Now here comes my question. What happens if I want to merge two indexes.
Using IndexWriter.addIndexes(Directory[] dirs) method I would like to
add one index to another. Now my question is if the documents will get
added also in the order they were inserted.
Example: if
index 1 contains IDs: 10,11,12,13,14,15
and index 2 contains IDs: 1,2,3
 
After I use IndexWriter.addIndexes(Directory[] dirs) to add index 2 to
index 1 will I get: 10,11,12,13,14,15,16,17,18
Where document number 16 in the merged index is document number 1 in
index 2, and 17 in the merged index is 2 in index 2, and 18 in the
merged index is 3 in  index 2 ?
 
If this is not the case, how can I do that?

Re: Using doc.id() to sort

Posted by Che Dong <ch...@hotmail.com>.
Yes, here is my implement;
http://www.chedong.com/tech/lucene_ext.tar.gz
including a IndexOrderSearcher

Che, Dong
http://www.chedong.com/

----- Original Message ----- 
From: "Aviran Mordo" <am...@infosciences.com>
To: "Lucene Users List" <lu...@jakarta.apache.org>
Sent: Tuesday, April 15, 2003 3:41 AM
Subject: Using doc.id() to sort


> I've noticed that whenever I add document to the index the doc.id() gets
> the next number.
> I use this behavior in order to sort the results by sorting the
> doc.id().
> Let me explain: If I insert the documents in a specific order to the
> index then the order is kept using the doc.id(). Now when I retrieve the
> documents after search I can use the doc.id to sort the hits in the
> order it was inserted to the index.
> Now here comes my question. What happens if I want to merge two indexes.
> Using IndexWriter.addIndexes(Directory[] dirs) method I would like to
> add one index to another. Now my question is if the documents will get
> added also in the order they were inserted.
> Example: if
> index 1 contains IDs: 10,11,12,13,14,15
> and index 2 contains IDs: 1,2,3
>  
> After I use IndexWriter.addIndexes(Directory[] dirs) to add index 2 to
> index 1 will I get: 10,11,12,13,14,15,16,17,18
> Where document number 16 in the merged index is document number 1 in
> index 2, and 17 in the merged index is 2 in index 2, and 18 in the
> merged index is 3 in  index 2 ?
>  
> If this is not the case, how can I do that?
>