mirror of https://github.com/apache/lucene.git
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:
parent
0e203d5637
commit
ae3f1abbe3
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue