lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rob Outar" <rou...@ideorlando.org>
Subject RE: java.lang.IllegalArgumentException: attempt to access a deleted document
Date Thu, 05 Jun 2003 18:30:56 GMT
I added the following code:

   for (int i = 0; i < numOfDocs; i++) {
                if ( !reader.isDeleted(i)) {
                    doc = reader.document(i);
                    docs[i] =
doc.get(SearchEngineConstants.REPOSITORY_PATH);
                }
            }
            return docs;

but it never goes in the if statement, for every value of i, isDeleted(i) is
returning true?!?  Am I doing something wrong?  I was trying to do what Doug
outlined below.


Thanks,

Rob
-----Original Message-----
From: Doug Cutting [mailto:cutting@lucene.com]
Sent: Wednesday, June 04, 2003 12:34 PM
To: Lucene Users List
Subject: Re: java.lang.IllegalArgumentException: attempt to access a
deleted document


Rob Outar wrote:
>  public synchronized String[] getDocuments() throws IOException {
>
>         IndexReader reader = null;
>         try {
>             reader = IndexReader.open(this.indexLocation);
>             int numOfDocs      = reader.numDocs();
>             String[] docs      = new String[numOfDocs];
>             Document doc       = null;
>
>             for (int i = 0; i < numOfDocs; i++) {
>                 doc = reader.document(i);
>                 docs[i] = doc.get(SearchEngineConstants.REPOSITORY_PATH);
>             }
>             return docs;
>         }
>         finally {
>             if (reader != null) {
>                 reader.close();
>             }
>         }
>     }

The limit of your iteration should be IndexReader.maxDoc(), not
IndexReader.numDocs():

http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/index/IndexReade
r.html#maxDoc()

Also, you should first check that each document is not deleted before
calling IndexReader.document(int):

http://jakarta.apache.org/lucene/docs/api/org/apache/lucene/index/IndexReade
r.html#isDeleted(int)

Doug


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


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


Mime
View raw message