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


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to