lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chuck Williams" <ch...@manawiz.com>
Subject RE: modifying existing index
Date Wed, 24 Nov 2004 18:15:21 GMT
I haven't tried it but believe this should work:

    IndexReader reader;
    void delete(long id) {
        reader.delete(new Term("id", Long.toString(id)));
    }

This also has the benefit that it does binary search rather than
sequential search.

You will want to pad you id's with leading zeroes if you are going to do
incremental indexing (both when storing them and when looking them up).
Sorting is by lexicographic order, not numerical order, and incremental
indexing is much faster if the id's are kept sorted (as is done in
IndexHTML).

Chuck


  > -----Original Message-----
  > From: Santosh [mailto:santosh.s@softprosys.com]
  > Sent: Wednesday, November 24, 2004 9:54 AM
  > To: Lucene Users List
  > Subject: Re: modifying existing index
  > 
  > I am able to delete now the Index using the following
  > 
  > if(indexDir.exists())
  > 
  > {
  > 
  > 
  > IndexReader reader = IndexReader.open( indexDir );
  > 
  > uidIter = reader.terms(new Term("id", ""));
  > 
  > while (uidIter.term() != null && uidIter.term().field() == "id") {
  > 
  > 
  > reader.delete(uidIter.term());
  > 
  > uidIter.next();
  > 
  > }
  > 
  > reader.close();
  > 
  > }
  > 
  > where "id"  is the keyword field. But here also all the documents
are
  > deleted. How can I modify my code and delete particular document
with
  > given
  > id
  > 
  > 
  > 
  > 
  > 
  > Iam creating the index in the following way
  > 
  > Document doc = new Document();
  > 
  > doc.add(Field.Text("text",text));
  > 
  > doc.add(Field.Keyword("id",Long.toString(id)));
  > 
  > doc.add(Field.Keyword("title",title));
  > 
  > doc.add(Field.Keyword("keywords",keywords));
  > 
  > doc.add(Field.Keyword("type",type));
  > 
  > writer.addDocument(doc);
  > 
  > 
  > 
  > 
  > 
  > 
  > 
  > 
  > 
  > ----- Original Message -----
  > From: "Chuck Williams" <chuck@manawiz.com>
  > To: "Lucene Users List" <lucene-user@jakarta.apache.org>
  > Sent: Wednesday, November 24, 2004 1:06 PM
  > Subject: RE: modifying existing index
  > 
  > 
  > A good way to do this is to add a keyword field with whatever unique
id
  > you have for the document.  Then you can delete the term containing
a
  > unique id to delete the document from the index (look at
  > IndexReader.delete(Term)).  You can look at the demo class IndexHTML
to
  > see how it does incremental indexing for an example.
  > 
  > Chuck
  > 
  >   > -----Original Message-----> From: Santosh
  > [mailto:santosh.s@softprosys.com]> Sent: Tuesday, November 23, 2004
  > 11:34
  > PM> To: Lucene Users List> Subject: Re: modifying existing index> >
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" <luke.francl@stellent.com>> To:
  > "Lucene
  > Users List" <lucene-user@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
  > 
  > 
  >
---------------------------------------------------------------------
  > 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


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


Mime
View raw message