lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@lucene.com>
Subject Re: java.lang.IllegalArgumentException: attempt to access a deleted document
Date Wed, 04 Jun 2003 16:34:03 GMT
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/IndexReader.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/IndexReader.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


Mime
View raw message