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.
[EMAIL PROTECTED]


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:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to