You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2015/02/19 16:34:18 UTC

svn commit: r1660912 - in /lucene/dev/trunk/lucene: core/src/java/org/apache/lucene/search/TwoPhaseDocIdSetIterator.java test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java

Author: jpountz
Date: Thu Feb 19 15:34:17 2015
New Revision: 1660912

URL: http://svn.apache.org/r1660912
Log:
LUCENE-6261: TwoPhaseDocIdSetIterator.matches() should be called at most once per doc ID.

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TwoPhaseDocIdSetIterator.java
    lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TwoPhaseDocIdSetIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TwoPhaseDocIdSetIterator.java?rev=1660912&r1=1660911&r2=1660912&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TwoPhaseDocIdSetIterator.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TwoPhaseDocIdSetIterator.java Thu Feb 19 15:34:17 2015
@@ -73,9 +73,9 @@ public abstract class TwoPhaseDocIdSetIt
   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;
 
 }

Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java?rev=1660912&r1=1660911&r2=1660912&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java Thu Feb 19 15:34:17 2015
@@ -188,6 +188,7 @@ public class RandomApproximationQuery ex
 
     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 ex
 
     @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();
     }
 
   }