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 Luke Francl <lu...@stellent.com> on 2004/11/23 20:56:30 UTC

Re: modifying existing index

On Tue, 2004-11-23 at 13:59, Santosh wrote:
> I am using lucene for indexing, when I am creating Index the docuemnts are added. but when I want to modify the single existing document and reIndex again, it is taking as new document and adding one more time, so that I am getting same document twice in the results.
> To overcome this I am deleting existing Index and again recreating whole Index. but is it possibe to index  the modified document again and overwrite existing document without deleting and recreation. can I do this? If so how? 

You do not need to recreate the whole index. Just mark the document as
deleted using the IndexReader and then add it again with the
IndexWriter. Remember to close your IndexReader and IndexWriter after
doing this.

The deleted document will be removed the next time you optimize your
index.

Luke Francl


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


Re: modifying existing index

Posted by Cheolgoo Kang <ap...@gmail.com>.
On Wed, 24 Nov 2004 13:04:20 +0530, Santosh <sa...@softprosys.com> wrote:
> I have gon through IndexReader , I got method :     delete(int docNum)   ,
> but from where I will get document number? Is  this predifined? or we have
> to give a number prior  to indexing?

The number(aka doc-id) is given by lucene and is it's an internal sequential
integer. This number is usually retrieved from Hits.id(int) of your search.

Hits myHits = myIndexSearcher.search( myQuery );
for ( int i=0; i<myHits.length(); i++ ) {
  Document doc = myHits.doc( myHits.id( i ) );
  // myHits.id( i ) retrieves the i-th doc-id and
  // myHits.doc( myHits.id( i ) ) returns the desired i-th document
  // in the result myHits.
}

HTH

> 
> 
> ----- Original Message -----
> From: "Luke Francl" <lu...@stellent.com>
> To: "Lucene Users List" <lu...@jakarta.apache.org>
> Sent: Wednesday, November 24, 2004 1:26 AM
> Subject: Re: modifying existing index
> 
> > On Tue, 2004-11-23 at 13:59, Santosh wrote:
> > > I am using lucene for indexing, when I am creating Index the docuemnts
> are added. but when I want to modify the single existing document and
> reIndex again, it is taking as new document and adding one more time, so
> that I am getting same document twice in the results.
> > > To overcome this I am deleting existing Index and again recreating whole
> Index. but is it possibe to index  the modified document again and overwrite
> existing document without deleting and recreation. can I do this? If so how?
> >
> > You do not need to recreate the whole index. Just mark the document as
> > deleted using the IndexReader and then add it again with the
> > IndexWriter. Remember to close your IndexReader and IndexWriter after
> > doing this.
> >
> > The deleted document will be removed the next time you optimize your
> > index.
> >
> > Luke Francl
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 
> 


-- 
Cheolgoo, Kang

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


Re: modifying existing index

Posted by Santosh <sa...@softprosys.com>.
I have gon through IndexReader , I got method :     delete(int docNum)   ,
but from where I will get document number? Is  this predifined? or we have
to give a number prior  to indexing?
----- Original Message -----
From: "Luke Francl" <lu...@stellent.com>
To: "Lucene Users List" <lu...@jakarta.apache.org>
Sent: Wednesday, November 24, 2004 1:26 AM
Subject: Re: modifying existing index


> On Tue, 2004-11-23 at 13:59, Santosh wrote:
> > I am using lucene for indexing, when I am creating Index the docuemnts
are added. but when I want to modify the single existing document and
reIndex again, it is taking as new document and adding one more time, so
that I am getting same document twice in the results.
> > To overcome this I am deleting existing Index and again recreating whole
Index. but is it possibe to index  the modified document again and overwrite
existing document without deleting and recreation. can I do this? If so how?
>
> You do not need to recreate the whole index. Just mark the document as
> deleted using the IndexReader and then add it again with the
> IndexWriter. Remember to close your IndexReader and IndexWriter after
> doing this.
>
> The deleted document will be removed the next time you optimize your
> index.
>
> Luke Francl
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>


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