LUCENE-6261: TwoPhaseDocIdSetIterator.matches() should be called at most once per doc ID.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1660912 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrien Grand 2015-02-19 15:34:17 +00:00
parent 0e203d5637
commit ae3f1abbe3
2 changed files with 11 additions and 3 deletions

View File

@ -73,9 +73,9 @@ public abstract class TwoPhaseDocIdSetIterator {
public abstract DocIdSetIterator approximation();
/** Return whether the current doc ID that the iterator is on matches. This
* method should only be called when the iterator is positionned, ie. not
* method should only be called when the iterator is positionned -- ie. not
* when {@link DocIdSetIterator#docID()} is {@code -1} or
* {@link DocIdSetIterator#NO_MORE_DOCS}. */
* {@link DocIdSetIterator#NO_MORE_DOCS} -- and at most once. */
public abstract boolean matches() throws IOException;
}

View File

@ -188,6 +188,7 @@ public class RandomApproximationQuery extends Query {
private final DocIdSetIterator disi;
private final RandomApproximation approximation;
private int lastDoc = -1;
RandomTwoPhaseView(Random random, DocIdSetIterator disi) {
this.disi = disi;
@ -201,7 +202,14 @@ public class RandomApproximationQuery extends Query {
@Override
public boolean matches() throws IOException {
return approximation.doc == disi.docID();
if (approximation.docID() == -1 || approximation.docID() == DocIdSetIterator.NO_MORE_DOCS) {
throw new AssertionError("matches() should not be called on doc ID " + approximation.doc);
}
if (lastDoc == approximation.docID()) {
throw new AssertionError("matches() has been called twice on doc ID " + approximation.doc);
}
lastDoc = approximation.docID();
return approximation.docID() == disi.docID();
}
}