lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Uroš Jurglič <>
Subject deleting documents
Date Thu, 27 Dec 2001 11:25:39 GMT
I had a following problem:
I filled index like this:
	iw = new IndexWriter(index, new SimpleAnalyzer(), false);
	iw.addDocument(assetToDoc(asset)); // assetToDoc return Document

and deleted one document as follows:
	ir =;
	Term uidTerm = new Term("uid", assetUid);	// uid is primary
	int count = ir.delete(uidTerm);

When I next wanted to print index's content:
	IndexReader ir =;
	for (int i=0; i<ir.maxDoc(); i++) {
		Document doc = ir.document(i);
		Enumeration fields = doc.fields();

		while (fields.hasMoreElements()) {

the ir.maxDoc() went beyond true number of docs in index and I got stucked
with Exception telling me that I'm trying to access deleted document. 

Now I always, after deleting a document, open an IndexWriter and call
optimize() and close it and it works okay then, the index doesn't get
currupted anymore. But I haven't noticed anywhere that this is a standard
procedure after deleting a document, so am I doing something wrong?
Has anyone experienced something similiar? If true, please let me know how
did you solve it.

Happy y2k+2

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