lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andre Rubin" <andre.ru...@gmail.com>
Subject Deleting and adding docs
Date Sat, 09 Aug 2008 01:27:09 GMT
I'm new to Lucene, and I've been reading a lot of messages regarding
deleting docs. But I think my problem is more basic. I can't delete docs
from my index and (after the index is created the first time and the writer
is closed) I can't add new documents to an existing index.

Sorry for the lengthy email, I'm trying to be thorough.

Here are some code snippets:

FIRST STEP, CREATE THE INDEX

Analyzer ANALYZER = new StandardAnalyzer();

Instantiating the Writer:
IndexWriter writer = new IndexWriter(indexFilename, ANALYZER, true);
writer.setMaxFieldLength(1000000);

Creation of Documents, a loop:
Document doc = new Document();
...
doc.add(new Field(ID_FIELD, id, Field.Store.YES, Field.Index.NO));
writer.addDocument(doc);

Close the Writer:
writer.optimize();
writer.close();

Up to this point, the index is created fine.

SECOND STEP, ADDING OR DELETING
Deleting Docs:
IndexWriter writer = new IndexWriter(indexFilename, ANALYZER, false);
writer.deleteDocuments(new Term(ID_FIELD, id));

I also tried using IndexReader:
reader = IndexReader.open(indexFilename);
int i = reader.deleteDocuments(new Term(ID_FIELD, id)); //i returns 0

Both failed. I try to delete one id value that I know for sure it was added
in the first step.

I add fields the same way that I did before, except that I use the new
IndexWriter (recreate = false)
IndexWriter writer = new IndexWriter(indexFilename, ANALYZER, false);

I then flush and close:
writer.flush();
writer.close();

THIRD STEP: QUERYING
I query the index from another field, but the docs added on the second step
don't show and the ones deleted on the second step still return in the
results.

Any ideas what I'm doing wrong?


Thanks


Andre

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message