Index: src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java =================================================================== --- src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java (revision 958573) +++ src/main/java/org/apache/jackrabbit/core/query/lucene/ReadOnlyIndexReader.java (working copy) @@ -16,13 +16,13 @@ */ package org.apache.jackrabbit.core.query.lucene; +import java.io.IOException; +import java.util.BitSet; + +import org.apache.lucene.index.Term; import org.apache.lucene.index.TermDocs; -import org.apache.lucene.index.Term; import org.apache.lucene.index.TermPositions; -import java.util.BitSet; -import java.io.IOException; - /** * Overwrites the methods that would modify the index and throws an * {@link UnsupportedOperationException} in each of those methods. A @@ -240,10 +240,10 @@ /** * @inheritDoc */ - public boolean next() throws IOException { - boolean hasNext = super.next(); - while (hasNext && deleted.get(super.doc())) { - hasNext = super.next(); + public final boolean next() throws IOException { + boolean hasNext = in.next(); + while (hasNext && deleted.get(in.doc())) { + hasNext = in.next(); } return hasNext; } @@ -251,20 +251,37 @@ /** * @inheritDoc */ - public int read(int[] docs, int[] freqs) throws IOException { - int count; - for (count = 0; count < docs.length && next(); count++) { - docs[count] = doc(); - freqs[count] = freq(); + public final int read(int[] docs, int[] freqs) throws IOException { + for (;;) { + int num = in.read(docs, freqs); + if (num == 0) { + // no more docs + return 0; + } + // need to check for deleted docs + int numDeleted = 0; + for (int i = 0; i < num; i++) { + if (deleted.get(docs[i])) { + numDeleted++; + continue; + } + // check if we need to shift + if (numDeleted > 0) { + docs[i - numDeleted] = docs[i]; + freqs[i - numDeleted] = freqs[i]; + } + } + if (num != numDeleted) { + return num - numDeleted; + } } - return count; } /** * @inheritDoc */ - public boolean skipTo(int i) throws IOException { - boolean exists = super.skipTo(i); + public final boolean skipTo(int i) throws IOException { + boolean exists = in.skipTo(i); while (exists && deleted.get(doc())) { exists = next(); }