lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Lea <ian....@blackwell.co.uk>
Subject Re: deleting documents
Date Thu, 27 Dec 2001 13:41:51 GMT
According to the javadoc for IndexReader maxDoc "returns one greater than
the largest possible document number" so doesn't necessarily bear much
resemblance to the actual number of undeleted documents in the index.

IndexReader.isDeleted(i) says whether a particular document has
been deleted and can be called before IndexReader.document(i) to
avoid Exceptions being thrown.

I don't think your index is corrupt.  If you read the javadoc for
IndexReader.delete() you will see that deleted documents don't disappear
immediately (unless you call optimize() as you are) but will disappear
as the index gets modified further.


Hope that helps.


--
Ian.
ian.lea@blackwell.co.uk


Uro¹ Jurgliè wrote:
> 
> I had a following problem:
> I filled index like this:
>         iw = new IndexWriter(index, new SimpleAnalyzer(), false);
>         iw.addDocument(assetToDoc(asset)); // assetToDoc return Document
> instance
>         iw.close();
> 
> and deleted one document as follows:
>         ir = IndexReader.open(index);
>         Term uidTerm = new Term("uid", assetUid);       // uid is primary
> key
>         int count = ir.delete(uidTerm);
>         ir.close();
> 
> When I next wanted to print index's content:
>         IndexReader ir = IndexReader.open(indexPath);
>         for (int i=0; i<ir.maxDoc(); i++) {
>                 System.out.println(i);
>                 Document doc = ir.document(i);
>                 Enumeration fields = doc.fields();
> 
>                 while (fields.hasMoreElements()) {
>                         System.out.println(fields.nextElement());
>                 }
>                 System.out.println();
>         }
> 
> 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

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


Mime
View raw message