You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Donna L Gresh <gr...@us.ibm.com> on 2007/07/19 14:08:46 UTC

question about flush(), optimize(), and deleted documents

I have run into problems with an error that I am trying to access a 
deleted document when doing something along the lines below; my brief 
question is, what is necessary to avoid "seeing" deleted documents? Is an 
optimize() necessary? Or will a flush() or close() accomplish the same 
thing? 

IndexReader ireader = IndexReader.open(directoryName);
int numdocs = ireader.numDocs();
for (int i=0; i<numdocs; i++) {
        Document doc = ireader.document(i);
        Field field = doc.getField("id");



Donna L. Gresh
Services Research, Mathematical Sciences Department
IBM T.J. Watson Research Center
(914) 945-2472
http://www.research.ibm.com/people/g/donnagresh
gresh@us.ibm.com

Re: question about flush(), optimize(), and deleted documents

Posted by Donna L Gresh <gr...@us.ibm.com>.
Thank you-- this is what appeared to be the case, but I wanted to check if 
there 
was something simple I wasn't understanding--

>All deletes should be removed after an optimize. Otherwise, I think 
you'll
>have to call isDeleted before trying to access the document. numDocs does
>not include deletes, but the document() call will retrieve deletes. You
>might try using maxDoc() instead of numDocs().


Donna L. Gresh
Services Research, Mathematical Sciences Department
IBM T.J. Watson Research Center
(914) 945-2472
http://www.research.ibm.com/people/g/donnagresh
gresh@us.ibm.com

Re: question about flush(), optimize(), and deleted documents

Posted by Mark Miller <ma...@gmail.com>.
All deletes should be removed after an optimize. Otherwise, I think you'll
have to call isDeleted before trying to access the document. numDocs does
not include deletes, but the document() call will retrieve deletes. You
might try using maxDoc() instead of numDocs().

- Mark