lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject svn commit: r1719124 [2/4] - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/index/ lucene/core/src/java/org/apache/lucene/search/ lucene/core/src/java/org/apache/lucene/search/spans/ lucene/core/src/te...
Date Thu, 10 Dec 2015 17:45:31 GMT
Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermScorer.java Thu Dec 10 17:45:29 2015
@@ -55,41 +55,17 @@ final class TermScorer extends Scorer {
     return postingsEnum.freq();
   }
 
-  /**
-   * Advances to the next document matching the query. <br>
-   *
-   * @return the document matching the query or NO_MORE_DOCS if there are no more documents.
-   */
   @Override
-  public int nextDoc() throws IOException {
-    return postingsEnum.nextDoc();
+  public DocIdSetIterator iterator() {
+    return postingsEnum;
   }
 
   @Override
   public float score() throws IOException {
-    assert docID() != NO_MORE_DOCS;
+    assert docID() != DocIdSetIterator.NO_MORE_DOCS;
     return docScorer.score(postingsEnum.docID(), postingsEnum.freq());
   }
 
-  /**
-   * Advances to the first match beyond the current whose document number is
-   * greater than or equal to a given target. <br>
-   * The implementation uses {@link org.apache.lucene.index.PostingsEnum#advance(int)}.
-   *
-   * @param target
-   *          The target document number.
-   * @return the matching document or NO_MORE_DOCS if none exist.
-   */
-  @Override
-  public int advance(int target) throws IOException {
-    return postingsEnum.advance(target);
-  }
-
-  @Override
-  public long cost() {
-    return postingsEnum.cost();
-  }
-
   /** Returns a string representation of this <code>TermScorer</code>. */
   @Override
   public String toString() { return "scorer(" + weight + ")[" + super.toString() + "]"; }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TwoPhaseIterator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TwoPhaseIterator.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TwoPhaseIterator.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TwoPhaseIterator.java Thu Dec 10 17:45:29 2015
@@ -21,7 +21,7 @@ import java.io.IOException;
 import java.util.Objects;
 
 /**
- * Returned by {@link Scorer#asTwoPhaseIterator()}
+ * Returned by {@link Scorer#twoPhaseIterator()}
  * to expose an approximation of a {@link DocIdSetIterator}.
  * When the {@link #approximation()}'s
  * {@link DocIdSetIterator#nextDoc()} or {@link DocIdSetIterator#advance(int)}
@@ -98,14 +98,4 @@ public abstract class TwoPhaseIterator {
    */
   public abstract float matchCost();
 
-  /**
-   * Returns a {@link TwoPhaseIterator} for this {@link DocIdSetIterator}
-   * when available, otherwise returns null.
-   */
-  public static TwoPhaseIterator asTwoPhaseIterator(DocIdSetIterator iter) {
-    return (iter instanceof Scorer)
-            ? ((Scorer) iter).asTwoPhaseIterator()
-            : null;
-  }
-
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java Thu Dec 10 17:45:29 2015
@@ -147,6 +147,8 @@ public abstract class Weight {
    *  @lucene.internal */
   protected static class DefaultBulkScorer extends BulkScorer {
     private final Scorer scorer;
+    private final DocIdSetIterator iterator;
+    private final TwoPhaseIterator twoPhase;
 
     /** Sole constructor. */
     public DefaultBulkScorer(Scorer scorer) {
@@ -154,30 +156,31 @@ public abstract class Weight {
         throw new NullPointerException();
       }
       this.scorer = scorer;
+      this.iterator = scorer.iterator();
+      this.twoPhase = scorer.twoPhaseIterator();
     }
 
     @Override
     public long cost() {
-      return scorer.cost();
+      return iterator.cost();
     }
 
     @Override
     public int score(LeafCollector collector, Bits acceptDocs, int min, int max) throws IOException {
       collector.setScorer(scorer);
-      final TwoPhaseIterator twoPhase = scorer.asTwoPhaseIterator();
       if (scorer.docID() == -1 && min == 0 && max == DocIdSetIterator.NO_MORE_DOCS) {
-        scoreAll(collector, scorer, twoPhase, acceptDocs);
+        scoreAll(collector, iterator, twoPhase, acceptDocs);
         return DocIdSetIterator.NO_MORE_DOCS;
       } else {
         int doc = scorer.docID();
         if (doc < min) {
           if (twoPhase == null) {
-            doc = scorer.advance(min);
+            doc = iterator.advance(min);
           } else {
             doc = twoPhase.approximation().advance(min);
           }
         }
-        return scoreRange(collector, scorer, twoPhase, acceptDocs, doc, max);
+        return scoreRange(collector, iterator, twoPhase, acceptDocs, doc, max);
       }
     }
 
@@ -185,14 +188,14 @@ public abstract class Weight {
      *  separate this from {@link #scoreAll} to help out
      *  hotspot.
      *  See <a href="https://issues.apache.org/jira/browse/LUCENE-5487">LUCENE-5487</a> */
-    static int scoreRange(LeafCollector collector, Scorer scorer, TwoPhaseIterator twoPhase,
+    static int scoreRange(LeafCollector collector, DocIdSetIterator iterator, TwoPhaseIterator twoPhase,
         Bits acceptDocs, int currentDoc, int end) throws IOException {
       if (twoPhase == null) {
         while (currentDoc < end) {
           if (acceptDocs == null || acceptDocs.get(currentDoc)) {
             collector.collect(currentDoc);
           }
-          currentDoc = scorer.nextDoc();
+          currentDoc = iterator.nextDoc();
         }
         return currentDoc;
       } else {
@@ -211,9 +214,9 @@ public abstract class Weight {
      *  separate this from {@link #scoreRange} to help out
      *  hotspot.
      *  See <a href="https://issues.apache.org/jira/browse/LUCENE-5487">LUCENE-5487</a> */
-    static void scoreAll(LeafCollector collector, Scorer scorer, TwoPhaseIterator twoPhase, Bits acceptDocs) throws IOException {
+    static void scoreAll(LeafCollector collector, DocIdSetIterator iterator, TwoPhaseIterator twoPhase, Bits acceptDocs) throws IOException {
       if (twoPhase == null) {
-        for (int doc = scorer.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = scorer.nextDoc()) {
+        for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) {
           if (acceptDocs == null || acceptDocs.get(doc)) {
             collector.collect(doc);
           }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package-info.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package-info.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package-info.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package-info.java Thu Dec 10 17:45:29 2015
@@ -427,13 +427,14 @@
  *     <p>The
  *         {@link org.apache.lucene.search.Scorer Scorer}
  *         abstract class provides common scoring functionality for all Scorer implementations and
- *         is the heart of the Lucene scoring process. The Scorer defines the following abstract (some of them are not
- *         yet abstract, but will be in future versions and should be considered as such now) methods which
- *         must be implemented (some of them inherited from {@link org.apache.lucene.search.DocIdSetIterator DocIdSetIterator}):
+ *         is the heart of the Lucene scoring process. The Scorer defines the following methods which
+ *         must be implemented:
  *         <ol>
  *             <li>
- *                 {@link org.apache.lucene.search.Scorer#nextDoc nextDoc()} &mdash; Advances to the next
- *                 document that matches this Query, returning true if and only if there is another document that matches.</li>
+ *                 {@link org.apache.lucene.search.Scorer#iterator iterator()} &mdash; Return a
+ *                 {@link org.apache.lucene.search.DocIdSetIterator DocIdSetIterator} that can iterate over all
+ *                 document that matches this Query.
+ *             </li>
  *             <li>
  *                 {@link org.apache.lucene.search.Scorer#docID docID()} &mdash; Returns the id of the
  *                 {@link org.apache.lucene.document.Document Document} that contains the match.
@@ -451,13 +452,6 @@
  *                 {@link org.apache.lucene.index.PostingsEnum#freq PostingsEnum.freq()}.
  *             </li>
  *             <li>
- *                 {@link org.apache.lucene.search.Scorer#advance advance()} &mdash; Skip ahead in
- *                 the document matches to the document whose id is greater than
- *                 or equal to the passed in value. In many instances, advance can be
- *                 implemented more efficiently than simply looping through all the matching documents until
- *                 the target document is identified.
- *             </li>
- *             <li>
  *                 {@link org.apache.lucene.search.Scorer#getChildren getChildren()} &mdash; Returns any child subscorers
  *                 underneath this scorer. This allows for users to navigate the scorer hierarchy and receive more fine-grained
  *                 details on the scoring process.
@@ -531,7 +525,7 @@
  * <p>Assuming a BooleanScorer2, we first initialize the Coordinator, which is used to apply the coord() 
  *   factor. We then get a internal Scorer based on the required, optional and prohibited parts of the query.
  *   Using this internal Scorer, the BooleanScorer2 then proceeds into a while loop based on the 
- *   {@link org.apache.lucene.search.Scorer#nextDoc Scorer.nextDoc()} method. The nextDoc() method advances 
+ *   {@link org.apache.lucene.search.DocIdSetIterator#nextDoc DocIdSetIterator.nextDoc()} method. The nextDoc() method advances 
  *   to the next document matching the query. This is an abstract method in the Scorer class and is thus 
  *   overridden by all derived  implementations. If you have a simple OR query your internal Scorer is most 
  *   likely a DisjunctionSumScorer, which essentially combines the scorers from the sub scorers of the OR'd terms.

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ConjunctionSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ConjunctionSpans.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ConjunctionSpans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ConjunctionSpans.java Thu Dec 10 17:45:29 2015
@@ -23,7 +23,6 @@ import java.util.List;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.ConjunctionDISI;
 import org.apache.lucene.search.TwoPhaseIterator;
-import org.apache.lucene.search.similarities.Similarity;
 
 /**
  * Common super class for multiple sub spans required in a document.
@@ -34,13 +33,12 @@ abstract class ConjunctionSpans extends
   boolean atFirstInCurrentDoc; // a first start position is available in current doc for nextStartPosition
   boolean oneExhaustedInCurrentDoc; // one subspans exhausted in current doc
 
-  ConjunctionSpans(List<Spans> subSpans, SpanWeight weight, Similarity.SimScorer docScorer) {
-    super(weight, docScorer);
+  ConjunctionSpans(List<Spans> subSpans) {
     if (subSpans.size() < 2) {
       throw new IllegalArgumentException("Less than 2 subSpans.size():" + subSpans.size());
     }
     this.subSpans = subSpans.toArray(new Spans[subSpans.size()]);
-    this.conjunction = ConjunctionDISI.intersect(subSpans);
+    this.conjunction = ConjunctionDISI.intersectSpans(subSpans);
     this.atFirstInCurrentDoc = true; // ensure for doc -1 that start/end positions are -1
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ContainSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ContainSpans.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ContainSpans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ContainSpans.java Thu Dec 10 17:45:29 2015
@@ -21,15 +21,13 @@ import java.io.IOException;
 import java.util.Arrays;
 import java.util.Objects;
 
-import org.apache.lucene.search.similarities.Similarity;
-
 abstract class ContainSpans extends ConjunctionSpans {
   Spans sourceSpans;
   Spans bigSpans;
   Spans littleSpans;
 
-  ContainSpans(SpanWeight weight, Similarity.SimScorer simScorer, Spans bigSpans, Spans littleSpans, Spans sourceSpans) {
-    super(Arrays.asList(bigSpans, littleSpans), weight, simScorer);
+  ContainSpans(Spans bigSpans, Spans littleSpans, Spans sourceSpans) {
+    super(Arrays.asList(bigSpans, littleSpans));
     this.bigSpans = Objects.requireNonNull(bigSpans);
     this.littleSpans = Objects.requireNonNull(littleSpans);
     this.sourceSpans = Objects.requireNonNull(sourceSpans);

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FilterSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FilterSpans.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FilterSpans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FilterSpans.java Thu Dec 10 17:45:29 2015
@@ -21,7 +21,6 @@ import java.io.IOException;
 import java.util.Objects;
 
 import org.apache.lucene.search.TwoPhaseIterator;
-import org.apache.lucene.search.similarities.Similarity;
 
 /**
  * A {@link Spans} implementation wrapping another spans instance,
@@ -36,8 +35,7 @@ public abstract class FilterSpans extend
   private int startPos = -1;
   
   /** Wrap the given {@link Spans}. */
-  protected FilterSpans(Spans in, Similarity.SimScorer docScorer) {
-    super((SpanWeight)in.getWeight(), docScorer);
+  protected FilterSpans(Spans in) {
     this.in = Objects.requireNonNull(in);
   }
   

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java Thu Dec 10 17:45:29 2015
@@ -20,8 +20,6 @@ package org.apache.lucene.search.spans;
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.lucene.search.similarities.Similarity;
-
 /**
  * A Spans that is formed from the ordered subspans of a SpanNearQuery
  * where the subspans do not overlap and have a maximum slop between them.
@@ -52,8 +50,8 @@ public class NearSpansOrdered extends Co
 
   private final int allowedSlop;
 
-  public NearSpansOrdered(SpanWeight weight, int allowedSlop, List<Spans> subSpans, Similarity.SimScorer simScorer) throws IOException {
-    super(subSpans, weight, simScorer);
+  public NearSpansOrdered(int allowedSlop, List<Spans> subSpans) throws IOException {
+    super(subSpans);
     this.atFirstInCurrentDoc = true; // -1 startPosition/endPosition also at doc -1
     this.allowedSlop = allowedSlop;
   }
@@ -152,10 +150,5 @@ public class NearSpansOrdered extends Co
     }
   }
 
-  @Override
-  public String toString() {
-    return "NearSpansOrdered("+weight.getQuery().toString()+")@"+docID()+": "+startPosition()+" - "+endPosition();
-  }
-
 }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java Thu Dec 10 17:45:29 2015
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.lucene.search.TwoPhaseIterator;
-import org.apache.lucene.search.similarities.Similarity;
 import org.apache.lucene.util.PriorityQueue;
 
 /**
@@ -38,9 +37,9 @@ public class NearSpansUnordered extends
 
   private SpanPositionQueue spanPositionQueue;
 
-  public NearSpansUnordered(SpanWeight weight, int allowedSlop, List<Spans> subSpans, Similarity.SimScorer simScorer)
+  public NearSpansUnordered(int allowedSlop, List<Spans> subSpans)
   throws IOException {
-    super(subSpans, weight, simScorer);
+    super(subSpans);
 
     this.subSpanCells = new ArrayList<>(subSpans.size());
     for (Spans subSpan : subSpans) { // sub spans in query order
@@ -77,7 +76,6 @@ public class NearSpansUnordered extends
     final Spans in;
 
     public SpansCell(Spans spans) {
-      super((SpanWeight) NearSpansUnordered.this.weight, NearSpansUnordered.this.docScorer);
       this.in = spans;
     }
 
@@ -267,13 +265,4 @@ public class NearSpansUnordered extends
     }
   }
 
-  @Override
-  public String toString() {
-    if (minPositionCell() != null) {
-      return getClass().getName() + "("+weight.getQuery().toString()+")@"+
-        (docID()+":"+startPosition()+"-"+endPosition());
-    } else {
-      return getClass().getName() + "("+weight.getQuery().toString()+")@ ?START?";
-    }
-  }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ScoringWrapperSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ScoringWrapperSpans.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ScoringWrapperSpans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ScoringWrapperSpans.java Thu Dec 10 17:45:29 2015
@@ -35,7 +35,6 @@ public class ScoringWrapperSpans extends
    * @param simScorer  the SimScorer to use for scoring
    */
   public ScoringWrapperSpans(Spans spans, Similarity.SimScorer simScorer) {
-    super((SpanWeight) spans.getWeight(), simScorer);
     this.in = spans;
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java Thu Dec 10 17:45:29 2015
@@ -172,7 +172,7 @@ public final class SpanBoostQuery extend
       }
 
       @Override
-      public Scorer scorer(LeafReaderContext context) throws IOException {
+      public SpanScorer scorer(LeafReaderContext context) throws IOException {
         return weight.scorer(context);
       }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainingQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainingQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainingQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainingQuery.java Thu Dec 10 17:45:29 2015
@@ -71,7 +71,7 @@ public final class SpanContainingQuery e
       Spans big = containerContained.get(0);
       Spans little = containerContained.get(1);
 
-      return new ContainSpans(this, getSimScorer(context), big, little, big) {
+      return new ContainSpans(big, little, big) {
 
         @Override
         boolean twoPhaseCurrentDocMatches() throws IOException {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java Thu Dec 10 17:45:29 2015
@@ -229,8 +229,8 @@ public class SpanNearQuery extends SpanQ
       }
 
       // all NearSpans require at least two subSpans
-      return (!inOrder) ? new NearSpansUnordered(this, slop, subSpans, getSimScorer(context))
-          : new NearSpansOrdered(this, slop, subSpans, getSimScorer(context));
+      return (!inOrder) ? new NearSpansUnordered(slop, subSpans)
+          : new NearSpansOrdered(slop, subSpans);
     }
 
     @Override
@@ -339,7 +339,6 @@ public class SpanNearQuery extends SpanQ
     final int width;
 
     GapSpans(int width) {
-      super(null, null);
       this.width = width;
     }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java Thu Dec 10 17:45:29 2015
@@ -135,7 +135,7 @@ public final class SpanNotQuery extends
       final TwoPhaseIterator excludeTwoPhase = excludeSpans.asTwoPhaseIterator();
       final DocIdSetIterator excludeApproximation = excludeTwoPhase == null ? null : excludeTwoPhase.approximation();
 
-      return new FilterSpans(includeSpans, getSimScorer(context)) {
+      return new FilterSpans(includeSpans) {
         // last document we have checked matches() against for the exclusion, and failed
         // when using approximations, so we don't call it again, and pass thru all inclusions.
         int lastApproxDoc = -1;

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java Thu Dec 10 17:45:29 2015
@@ -175,20 +175,20 @@ public final class SpanOrQuery extends S
         return new ScoringWrapperSpans(subSpans.get(0), getSimScorer(context));
       }
 
-      final DisiPriorityQueue<Spans> byDocQueue = new DisiPriorityQueue<>(subSpans.size());
+      final DisiPriorityQueue byDocQueue = new DisiPriorityQueue(subSpans.size());
       for (Spans spans : subSpans) {
-        byDocQueue.add(new DisiWrapper<>(spans));
+        byDocQueue.add(new DisiWrapper(spans));
       }
 
       final SpanPositionQueue byPositionQueue = new SpanPositionQueue(subSpans.size()); // when empty use -1
 
-      return new Spans(this, getSimScorer(context)) {
+      return new Spans() {
         Spans topPositionSpans = null;
 
         @Override
         public int nextDoc() throws IOException {
           topPositionSpans = null;
-          DisiWrapper<Spans> topDocSpans = byDocQueue.top();
+          DisiWrapper topDocSpans = byDocQueue.top();
           int currentDoc = topDocSpans.doc;
           do {
             topDocSpans.doc = topDocSpans.iterator.nextDoc();
@@ -200,7 +200,7 @@ public final class SpanOrQuery extends S
         @Override
         public int advance(int target) throws IOException {
           topPositionSpans = null;
-          DisiWrapper<Spans> topDocSpans = byDocQueue.top();
+          DisiWrapper topDocSpans = byDocQueue.top();
           do {
             topDocSpans.doc = topDocSpans.iterator.advance(target);
             topDocSpans = byDocQueue.updateTop();
@@ -210,7 +210,7 @@ public final class SpanOrQuery extends S
 
         @Override
         public int docID() {
-          DisiWrapper<Spans> topDocSpans = byDocQueue.top();
+          DisiWrapper topDocSpans = byDocQueue.top();
           return topDocSpans.doc;
         }
 
@@ -219,7 +219,7 @@ public final class SpanOrQuery extends S
           float sumMatchCost = 0; // See also DisjunctionScorer.asTwoPhaseIterator()
           long sumApproxCost = 0;
 
-          for (DisiWrapper<Spans> w : byDocQueue) {
+          for (DisiWrapper w : byDocQueue) {
             if (w.twoPhaseView != null) {
               long costWeight = (w.cost <= 1) ? 1 : w.cost;
               sumMatchCost += w.twoPhaseView.matchCost() * costWeight;
@@ -234,7 +234,7 @@ public final class SpanOrQuery extends S
 
           final float matchCost = sumMatchCost / sumApproxCost;
 
-          return new TwoPhaseIterator(new DisjunctionDISIApproximation<Spans>(byDocQueue)) {
+          return new TwoPhaseIterator(new DisjunctionDISIApproximation(byDocQueue)) {
             @Override
             public boolean matches() throws IOException {
               return twoPhaseCurrentDocMatches();
@@ -252,9 +252,9 @@ public final class SpanOrQuery extends S
         void computePositionsCost() {
           float sumPositionsCost = 0;
           long sumCost = 0;
-          for (DisiWrapper<Spans> w : byDocQueue) {
+          for (DisiWrapper w : byDocQueue) {
             long costWeight = (w.cost <= 1) ? 1 : w.cost;
-            sumPositionsCost += w.iterator.positionsCost() * costWeight;
+            sumPositionsCost += w.spans.positionsCost() * costWeight;
             sumCost += costWeight;
           }
           positionsCost = sumPositionsCost / sumCost;
@@ -271,7 +271,7 @@ public final class SpanOrQuery extends S
         int lastDocTwoPhaseMatched = -1;
 
         boolean twoPhaseCurrentDocMatches() throws IOException {
-          DisiWrapper<Spans> listAtCurrentDoc = byDocQueue.topList();
+          DisiWrapper listAtCurrentDoc = byDocQueue.topList();
           // remove the head of the list as long as it does not match
           final int currentDoc = listAtCurrentDoc.doc;
           while (listAtCurrentDoc.twoPhaseView != null) {
@@ -295,9 +295,9 @@ public final class SpanOrQuery extends S
         void fillPositionQueue() throws IOException { // called at first nextStartPosition
           assert byPositionQueue.size() == 0;
           // add all matching Spans at current doc to byPositionQueue
-          DisiWrapper<Spans> listAtCurrentDoc = byDocQueue.topList();
+          DisiWrapper listAtCurrentDoc = byDocQueue.topList();
           while (listAtCurrentDoc != null) {
-            Spans spansAtDoc = listAtCurrentDoc.iterator;
+            Spans spansAtDoc = listAtCurrentDoc.spans;
             if (lastDocTwoPhaseMatched == listAtCurrentDoc.doc) { // matched by DisjunctionDisiApproximation
               if (listAtCurrentDoc.twoPhaseView != null) { // matched by approximation
                 if (listAtCurrentDoc.lastApproxNonMatchDoc == listAtCurrentDoc.doc) { // matches() returned false

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java Thu Dec 10 17:45:29 2015
@@ -95,7 +95,7 @@ public abstract class SpanPositionCheckQ
     @Override
     public Spans getSpans(final LeafReaderContext context, Postings requiredPostings) throws IOException {
       Spans matchSpans = matchWeight.getSpans(context, requiredPostings);
-      return (matchSpans == null) ? null : new FilterSpans(matchSpans, getSimScorer(context)) {
+      return (matchSpans == null) ? null : new FilterSpans(matchSpans) {
         @Override
         protected AcceptStatus accept(Spans candidate) throws IOException {
           return acceptPosition(candidate);

Copied: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanScorer.java (from r1719081, lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/spans/SpanScorer.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanScorer.java?p2=lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanScorer.java&p1=lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/spans/SpanScorer.java&r1=1719081&r2=1719124&rev=1719124&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/spans/SpanScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanScorer.java Thu Dec 10 17:45:29 2015
@@ -53,7 +53,7 @@ public class SpanScorer extends Scorer {
   }
 
   @Override
-  public DocIdSetIterator iterator() {
+  public Spans iterator() {
     return spans;
   }
 
@@ -137,7 +137,7 @@ public class SpanScorer extends Scorer {
 
   /** Returns the intermediate "sloppy freq" adjusted for edit distance
    *  @lucene.internal */
-  final float sloppyFreq() throws IOException {
+  public final float sloppyFreq() throws IOException {
     ensureFreq();
     return freq;
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java Thu Dec 10 17:45:29 2015
@@ -119,7 +119,7 @@ public class SpanTermQuery extends SpanQ
 
       final PostingsEnum postings = termsEnum.postings(null, requiredPostings.getRequiredPostings());
       float positionsCost = termPositionsCost(termsEnum) * PHRASE_TO_SPAN_TERM_POSITIONS_COST;
-      return new TermSpans(this, getSimScorer(context), postings, term, positionsCost);
+      return new TermSpans(getSimScorer(context), postings, term, positionsCost);
     }
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java Thu Dec 10 17:45:29 2015
@@ -27,7 +27,6 @@ import org.apache.lucene.index.TermConte
 import org.apache.lucene.search.CollectionStatistics;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.TermStatistics;
 import org.apache.lucene.search.Weight;
 import org.apache.lucene.search.similarities.Similarity;
@@ -131,8 +130,13 @@ public abstract class SpanWeight extends
   }
 
   @Override
-  public Scorer scorer(LeafReaderContext context) throws IOException {
-    return getSpans(context, Postings.POSITIONS);
+  public SpanScorer scorer(LeafReaderContext context) throws IOException {
+    final Spans spans = getSpans(context, Postings.POSITIONS);
+    if (spans == null) {
+      return null;
+    }
+    final Similarity.SimScorer docScorer = getSimScorer(context);
+    return new SpanScorer(this, spans, docScorer);
   }
 
   /**
@@ -147,9 +151,9 @@ public abstract class SpanWeight extends
 
   @Override
   public Explanation explain(LeafReaderContext context, int doc) throws IOException {
-    Spans scorer = (Spans) scorer(context);
+    SpanScorer scorer = scorer(context);
     if (scorer != null) {
-      int newDoc = scorer.advance(doc);
+      int newDoc = scorer.iterator().advance(doc);
       if (newDoc == doc) {
         float freq = scorer.sloppyFreq();
         SimScorer docScorer = similarity.simScorer(simWeight, context);

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWithinQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWithinQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWithinQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWithinQuery.java Thu Dec 10 17:45:29 2015
@@ -72,7 +72,7 @@ public final class SpanWithinQuery exten
       Spans big = containerContained.get(0);
       Spans little = containerContained.get(1);
 
-      return new ContainSpans(this, getSimScorer(context), big, little, little) {
+      return new ContainSpans(big, little, little) {
 
         @Override
         boolean twoPhaseCurrentDocMatches() throws IOException {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java Thu Dec 10 17:45:29 2015
@@ -19,8 +19,9 @@ package org.apache.lucene.search.spans;
 
 import java.io.IOException;
 
+import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.similarities.Similarity;
+import org.apache.lucene.search.TwoPhaseIterator;
 import org.apache.lucene.search.similarities.Similarity.SimScorer;
 
 /** Iterates through combinations of start/end positions per-doc.
@@ -28,24 +29,10 @@ import org.apache.lucene.search.similari
  *  These are enumerated in order, by increasing document number, within that by
  *  increasing start position and finally by increasing end position.
  */
-public abstract class Spans extends Scorer {
+public abstract class Spans extends DocIdSetIterator {
 
   public static final int NO_MORE_POSITIONS = Integer.MAX_VALUE;
 
-  protected final Similarity.SimScorer docScorer;
-
-  protected Spans(SpanWeight weight, SimScorer docScorer) {
-    super(weight);
-    this.docScorer = docScorer;
-  }
-
-  /** accumulated sloppy freq (computed in setFreqCurrentDoc) */
-  protected float freq;
-  /** number of matches (computed in setFreqCurrentDoc) */
-  protected int numMatches;
-
-  private int lastScoredDoc = -1; // last doc we called setFreqCurrentDoc() for
-
   /**
    * Returns the next start position for the current doc.
    * There is always at least one start/end position per doc.
@@ -97,6 +84,16 @@ public abstract class Spans extends Scor
    */
   public abstract float positionsCost();
 
+  /**
+   * Optional method: Return a {@link TwoPhaseIterator} view of this
+   * {@link Scorer}. A return value of {@code null} indicates that
+   * two-phase iteration is not supported.
+   * @see Scorer#twoPhaseIterator()
+   */
+  public TwoPhaseIterator asTwoPhaseIterator() {
+    return null;
+  }
+
   @Override
   public String toString() {
     StringBuilder sb = new StringBuilder();
@@ -110,58 +107,6 @@ public abstract class Spans extends Scor
   }
 
   /**
-   * Ensure setFreqCurrentDoc is called, if not already called for the current doc.
-   */
-  private void ensureFreq() throws IOException {
-    int currentDoc = docID();
-    if (lastScoredDoc != currentDoc) {
-      setFreqCurrentDoc();
-      lastScoredDoc = currentDoc;
-    }
-  }
-
-  /**
-   * Sets {@link #freq} and {@link #numMatches} for the current document.
-   * <p>
-   * This will be called at most once per document.
-   */
-  protected final void setFreqCurrentDoc() throws IOException {
-    freq = 0.0f;
-    numMatches = 0;
-
-    doStartCurrentDoc();
-
-    assert startPosition() == -1 : "incorrect initial start position, " + this.toString();
-    assert endPosition() == -1 : "incorrect initial end position, " + this.toString();
-    int prevStartPos = -1;
-    int prevEndPos = -1;
-
-    int startPos = nextStartPosition();
-    assert startPos != Spans.NO_MORE_POSITIONS : "initial startPos NO_MORE_POSITIONS, " + this.toString();
-    do {
-      assert startPos >= prevStartPos;
-      int endPos = endPosition();
-      assert endPos != Spans.NO_MORE_POSITIONS;
-      // This assertion can fail for Or spans on the same term:
-      // assert (startPos != prevStartPos) || (endPos > prevEndPos) : "non increased endPos="+endPos;
-      assert (startPos != prevStartPos) || (endPos >= prevEndPos) : "decreased endPos="+endPos;
-      numMatches++;
-      if (docScorer == null) {  // scores not required, break out here
-        freq = 1;
-        return;
-      }
-      freq += docScorer.computeSlopFactor(width());
-      doCurrentSpans();
-      prevStartPos = startPos;
-      prevEndPos = endPos;
-      startPos = nextStartPosition();
-    } while (startPos != Spans.NO_MORE_POSITIONS);
-
-    assert startPosition() == Spans.NO_MORE_POSITIONS : "incorrect final start position, " + this.toString();
-    assert endPosition() == Spans.NO_MORE_POSITIONS : "incorrect final end position, " + this.toString();
-  }
-
-  /**
    * Called before the current doc's frequency is calculated
    */
   protected void doStartCurrentDoc() throws IOException {}
@@ -171,32 +116,4 @@ public abstract class Spans extends Scor
    */
   protected void doCurrentSpans() throws IOException {}
 
-  /**
-   * Score the current doc. The default implementation scores the doc
-   * with the similarity using the slop-adjusted {@link #freq}.
-   */
-  protected float scoreCurrentDoc() throws IOException {
-    assert docScorer != null : getClass() + " has a null docScorer!";
-    return docScorer.score(docID(), freq);
-  }
-
-  @Override
-  public final float score() throws IOException {
-    ensureFreq();
-    return scoreCurrentDoc();
-  }
-
-  @Override
-  public final int freq() throws IOException {
-    ensureFreq();
-    return numMatches;
-  }
-
-  /** Returns the intermediate "sloppy freq" adjusted for edit distance
-   *  @lucene.internal */
-  public final float sloppyFreq() throws IOException {
-    ensureFreq();
-    return freq;
-  }
-
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java Thu Dec 10 17:45:29 2015
@@ -39,9 +39,8 @@ public class TermSpans extends Spans {
   protected boolean readPayload;
   private final float positionsCost;
 
-  public TermSpans(SpanWeight weight, Similarity.SimScorer scorer,
+  public TermSpans(Similarity.SimScorer scorer,
                     PostingsEnum postings, Term term, float positionsCost) {
-    super(weight, scorer);
     this.postings = Objects.requireNonNull(postings);
     this.term = Objects.requireNonNull(term);
     this.doc = -1;

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java Thu Dec 10 17:45:29 2015
@@ -206,17 +206,7 @@ final class JustCompileSearch {
     }
 
     @Override
-    public int nextDoc() {
-      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
-    }
-    
-    @Override
-    public int advance(int target) {
-      throw new UnsupportedOperationException(UNSUPPORTED_MSG);
-    }
-
-    @Override
-    public long cost() {
+    public DocIdSetIterator iterator() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);
     }
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java Thu Dec 10 17:45:29 2015
@@ -824,7 +824,7 @@ public class TestBooleanCoord extends Lu
     Weight weight = searcher.createNormalizedWeight(query, true);
     Scorer scorer = weight.scorer(reader.leaves().get(0));
     assertTrue(scorer.docID() == -1 || scorer.docID() == DocIdSetIterator.NO_MORE_DOCS);
-    assertEquals(0, scorer.nextDoc());
+    assertEquals(0, scorer.iterator().nextDoc());
     assertEquals(expected, scorer.score(), 0.0001f);
 
     // test bulk scorer

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java Thu Dec 10 17:45:29 2015
@@ -372,7 +372,7 @@ public class TestBooleanQuery extends Lu
 
       // First pass: just use .nextDoc() to gather all hits
       final List<ScoreDoc> hits = new ArrayList<>();
-      while(scorer.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+      while(scorer.iterator().nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
         hits.add(new ScoreDoc(scorer.docID(), scorer.score()));
       }
 
@@ -399,12 +399,12 @@ public class TestBooleanQuery extends Lu
           if (left == 1 || random().nextBoolean()) {
             // next
             nextUpto = 1+upto;
-            nextDoc = scorer.nextDoc();
+            nextDoc = scorer.iterator().nextDoc();
           } else {
             // advance
             int inc = TestUtil.nextInt(random(), 1, left - 1);
             nextUpto = inc + upto;
-            nextDoc = scorer.advance(hits.get(nextUpto).doc);
+            nextDoc = scorer.iterator().advance(hits.get(nextUpto).doc);
           }
 
           if (nextUpto == hits.size()) {
@@ -673,7 +673,7 @@ public class TestBooleanQuery extends Lu
     final Weight weight = searcher.createNormalizedWeight(q.build(), random().nextBoolean());
     final Scorer scorer = weight.scorer(searcher.getIndexReader().leaves().get(0));
     assertTrue(scorer instanceof ConjunctionScorer);
-    assertNotNull(scorer.asTwoPhaseIterator());
+    assertNotNull(scorer.twoPhaseIterator());
 
     reader.close();
     w.close();
@@ -702,7 +702,7 @@ public class TestBooleanQuery extends Lu
     final Weight weight = searcher.createNormalizedWeight(q.build(), random().nextBoolean());
     final Scorer scorer = weight.scorer(reader.leaves().get(0));
     assertTrue(scorer instanceof DisjunctionScorer);
-    assertNotNull(scorer.asTwoPhaseIterator());
+    assertNotNull(scorer.twoPhaseIterator());
 
     reader.close();
     w.close();
@@ -733,7 +733,7 @@ public class TestBooleanQuery extends Lu
     final Weight weight = searcher.createNormalizedWeight(q.build(), random().nextBoolean());
     final Scorer scorer = weight.scorer(searcher.getIndexReader().leaves().get(0));
     assertTrue(scorer instanceof BoostedScorer || scorer instanceof ExactPhraseScorer);
-    assertNotNull(scorer.asTwoPhaseIterator());
+    assertNotNull(scorer.twoPhaseIterator());
 
     reader.close();
     w.close();
@@ -762,7 +762,7 @@ public class TestBooleanQuery extends Lu
     final Weight weight = searcher.createNormalizedWeight(q.build(), random().nextBoolean());
     final Scorer scorer = weight.scorer(reader.leaves().get(0));
     assertTrue(scorer instanceof ReqExclScorer);
-    assertNotNull(scorer.asTwoPhaseIterator());
+    assertNotNull(scorer.twoPhaseIterator());
 
     reader.close();
     w.close();
@@ -791,7 +791,7 @@ public class TestBooleanQuery extends Lu
     final Weight weight = searcher.createNormalizedWeight(q.build(), true);
     final Scorer scorer = weight.scorer(reader.leaves().get(0));
     assertTrue(scorer instanceof ReqOptSumScorer);
-    assertNotNull(scorer.asTwoPhaseIterator());
+    assertNotNull(scorer.twoPhaseIterator());
 
     reader.close();
     w.close();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanRewrites.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanRewrites.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanRewrites.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanRewrites.java Thu Dec 10 17:45:29 2015
@@ -91,7 +91,7 @@ public class TestBooleanRewrites extends
     query2.add(new TermQuery(new Term("field", "b")), Occur.SHOULD);
     final Weight weight = searcher.createNormalizedWeight(query2.build(), true);
     final Scorer scorer = weight.scorer(reader.leaves().get(0));
-    assertEquals(0, scorer.nextDoc());
+    assertEquals(0, scorer.iterator().nextDoc());
     assertTrue(scorer.getClass().getName(), scorer instanceof FilterScorer);
     assertEquals(0f, scorer.score(), 0f);
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java Thu Dec 10 17:45:29 2015
@@ -41,15 +41,9 @@ public class TestCachingCollector extend
     public int docID() { return 0; }
 
     @Override
-    public int nextDoc() throws IOException { return 0; }
-
-    @Override
-    public int advance(int target) throws IOException { return 0; }
-
-    @Override
-    public long cost() {
-      return 1;
-    } 
+    public DocIdSetIterator iterator() {
+      throw new UnsupportedOperationException();
+    }
   }
   
   private static class NoOpCollector extends SimpleCollector {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConjunctionDISI.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConjunctionDISI.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConjunctionDISI.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConjunctionDISI.java Thu Dec 10 17:45:29 2015
@@ -52,8 +52,8 @@ public class TestConjunctionDISI extends
   /**
    * Create a {@link Scorer} that wraps the given {@link DocIdSetIterator}. It
    * also accepts a {@link TwoPhaseIterator} view, which is exposed in
-   * {@link Scorer#asTwoPhaseIterator()}. When the two-phase view is not null,
-   * then {@link Scorer#nextDoc()} and {@link Scorer#advance(int)} will raise
+   * {@link Scorer#twoPhaseIterator()}. When the two-phase view is not null,
+   * then {@link DocIdSetIterator#nextDoc()} and {@link DocIdSetIterator#advance(int)} will raise
    * an exception in order to make sure that {@link ConjunctionDISI} takes
    * advantage of the {@link TwoPhaseIterator} view.
    */
@@ -61,40 +61,51 @@ public class TestConjunctionDISI extends
     return new Scorer(null) {
 
       @Override
-      public TwoPhaseIterator asTwoPhaseIterator() {
-        return twoPhaseIterator;
-      }
-
-      @Override
-      public int docID() {
-        if (twoPhaseIterator != null) {
-          throw new UnsupportedOperationException("ConjunctionDISI should call the two-phase iterator");
-        }
-        return it.docID();
-      }
+      public DocIdSetIterator iterator() {
+        return new DocIdSetIterator() {
 
-      @Override
-      public int nextDoc() throws IOException {
-        if (twoPhaseIterator != null) {
-          throw new UnsupportedOperationException("ConjunctionDISI should call the two-phase iterator");
-        }
-        return it.nextDoc();
+          @Override
+          public int docID() {
+            return it.docID();
+          }
+
+          @Override
+          public int nextDoc() throws IOException {
+            if (twoPhaseIterator != null) {
+              throw new UnsupportedOperationException("ConjunctionDISI should call the two-phase iterator");
+            }
+            return it.nextDoc();
+          }
+
+          @Override
+          public int advance(int target) throws IOException {
+            if (twoPhaseIterator != null) {
+              throw new UnsupportedOperationException("ConjunctionDISI should call the two-phase iterator");
+            }
+            return it.advance(target);
+          }
+
+          @Override
+          public long cost() {
+            if (twoPhaseIterator != null) {
+              throw new UnsupportedOperationException("ConjunctionDISI should call the two-phase iterator");
+            }
+            return it.cost();
+          }
+        };
       }
 
       @Override
-      public int advance(int target) throws IOException {
-        if (twoPhaseIterator != null) {
-          throw new UnsupportedOperationException("ConjunctionDISI should call the two-phase iterator");
-        }
-        return it.advance(target);
+      public TwoPhaseIterator twoPhaseIterator() {
+        return twoPhaseIterator;
       }
 
       @Override
-      public long cost() {
+      public int docID() {
         if (twoPhaseIterator != null) {
           throw new UnsupportedOperationException("ConjunctionDISI should call the two-phase iterator");
         }
-        return it.cost();
+        return it.docID();
       }
 
       @Override
@@ -154,13 +165,13 @@ public class TestConjunctionDISI extends
       final int maxDoc = TestUtil.nextInt(random(), 100, 10000);
       final int numIterators = TestUtil.nextInt(random(), 2, 5);
       final FixedBitSet[] sets = new FixedBitSet[numIterators];
-      final DocIdSetIterator[] iterators = new DocIdSetIterator[numIterators];
+      final Scorer[] iterators = new Scorer[numIterators];
       for (int i = 0; i < iterators.length; ++i) {
         final FixedBitSet set = randomSet(maxDoc);
         if (random().nextBoolean()) {
           // simple iterator
           sets[i] = set;
-          iterators[i] = new BitDocIdSet(set).iterator();
+          iterators[i] = new ConstantScoreScorer(null, 0f, new BitDocIdSet(set).iterator());
         } else {
           // scorer with approximation
           final FixedBitSet confirmed = clearRandomBits(set);
@@ -170,7 +181,7 @@ public class TestConjunctionDISI extends
         }
       }
 
-      final ConjunctionDISI conjunction = ConjunctionDISI.intersect(Arrays.asList(iterators));
+      final ConjunctionDISI conjunction = ConjunctionDISI.intersectScorers(Arrays.asList(iterators));
       assertEquals(intersect(sets), toBitSet(maxDoc, conjunction));
     }
   }
@@ -182,14 +193,14 @@ public class TestConjunctionDISI extends
       final int maxDoc = TestUtil.nextInt(random(), 100, 10000);
       final int numIterators = TestUtil.nextInt(random(), 2, 5);
       final FixedBitSet[] sets = new FixedBitSet[numIterators];
-      final DocIdSetIterator[] iterators = new DocIdSetIterator[numIterators];
+      final Scorer[] iterators = new Scorer[numIterators];
       boolean hasApproximation = false;
       for (int i = 0; i < iterators.length; ++i) {
         final FixedBitSet set = randomSet(maxDoc);
         if (random().nextBoolean()) {
           // simple iterator
           sets[i] = set;
-          iterators[i] = new BitDocIdSet(set).iterator();
+          iterators[i] = new ConstantScoreScorer(null, 0f, new BitDocIdSet(set).iterator());
         } else {
           // scorer with approximation
           final FixedBitSet confirmed = clearRandomBits(set);
@@ -200,7 +211,7 @@ public class TestConjunctionDISI extends
         }
       }
 
-      final ConjunctionDISI conjunction = ConjunctionDISI.intersect(Arrays.asList(iterators));
+      final ConjunctionDISI conjunction = ConjunctionDISI.intersectScorers(Arrays.asList(iterators));
       TwoPhaseIterator twoPhaseIterator = conjunction.asTwoPhaseIterator();
       assertEquals(hasApproximation, twoPhaseIterator != null);
       if (hasApproximation) {
@@ -216,15 +227,15 @@ public class TestConjunctionDISI extends
       final int maxDoc = TestUtil.nextInt(random(), 100, 10000);
       final int numIterators = TestUtil.nextInt(random(), 2, 5);
       final FixedBitSet[] sets = new FixedBitSet[numIterators];
-      DocIdSetIterator conjunction = null;
+      Scorer conjunction = null;
       boolean hasApproximation = false;
       for (int i = 0; i < numIterators; ++i) {
         final FixedBitSet set = randomSet(maxDoc);
-        final DocIdSetIterator newIterator;
+        final Scorer newIterator;
         if (random().nextBoolean()) {
           // simple iterator
           sets[i] = set;
-          newIterator = new BitDocIdSet(set).iterator();
+          newIterator = new ConstantScoreScorer(null, 0f, new BitDocIdSet(set).iterator());
         } else {
           // scorer with approximation
           final FixedBitSet confirmed = clearRandomBits(set);
@@ -237,17 +248,17 @@ public class TestConjunctionDISI extends
         if (conjunction == null) {
           conjunction = newIterator;
         } else {
-          final ConjunctionDISI conj = ConjunctionDISI.intersect(Arrays.asList(conjunction, newIterator));
+          final ConjunctionDISI conj = ConjunctionDISI.intersectScorers(Arrays.asList(conjunction, newIterator));
           conjunction = scorer(conj, conj.asTwoPhaseIterator());
         }
       }
 
-      TwoPhaseIterator twoPhaseIterator = ((Scorer) conjunction).asTwoPhaseIterator();
+      TwoPhaseIterator twoPhaseIterator = ((Scorer) conjunction).twoPhaseIterator();
       assertEquals(hasApproximation, twoPhaseIterator != null);
       if (hasApproximation) {
         assertEquals(intersect(sets), toBitSet(maxDoc, TwoPhaseIterator.asDocIdSetIterator(twoPhaseIterator)));
       } else {
-        assertEquals(intersect(sets), toBitSet(maxDoc, conjunction));
+        assertEquals(intersect(sets), toBitSet(maxDoc, conjunction.iterator()));
       }
     }
   }
@@ -258,47 +269,47 @@ public class TestConjunctionDISI extends
       final int maxDoc = TestUtil.nextInt(random(), 100, 10000);
       final int numIterators = TestUtil.nextInt(random(), 5, 10);
       final FixedBitSet[] sets = new FixedBitSet[numIterators];
-      final List<DocIdSetIterator> iterators = new LinkedList<>();
+      final List<Scorer> scorers = new LinkedList<>();
       for (int i = 0; i < numIterators; ++i) {
         final FixedBitSet set = randomSet(maxDoc);
         if (random().nextBoolean()) {
           // simple iterator
           sets[i] = set;
-          iterators.add(new BitDocIdSet(set).iterator());
+          scorers.add(new ConstantScoreScorer(null, 0f, new BitDocIdSet(set).iterator()));
         } else {
           // scorer with approximation
           final FixedBitSet confirmed = clearRandomBits(set);
           sets[i] = confirmed;
           final TwoPhaseIterator approximation = approximation(new BitDocIdSet(set).iterator(), confirmed);
-          iterators.add(scorer(approximation));
+          scorers.add(scorer(approximation));
         }
       }
 
       // make some sub sequences into sub conjunctions
       final int subIters = atLeast(3);
-      for (int subIter = 0; subIter < subIters && iterators.size() > 3; ++subIter) {
-        final int subSeqStart = TestUtil.nextInt(random(), 0, iterators.size() - 2);
-        final int subSeqEnd = TestUtil.nextInt(random(), subSeqStart + 2, iterators.size());
-        List<DocIdSetIterator> subIterators = iterators.subList(subSeqStart, subSeqEnd);
-        DocIdSetIterator subConjunction;
+      for (int subIter = 0; subIter < subIters && scorers.size() > 3; ++subIter) {
+        final int subSeqStart = TestUtil.nextInt(random(), 0, scorers.size() - 2);
+        final int subSeqEnd = TestUtil.nextInt(random(), subSeqStart + 2, scorers.size());
+        List<Scorer> subIterators = scorers.subList(subSeqStart, subSeqEnd);
+        Scorer subConjunction;
         if (wrapWithScorer) {
           subConjunction = new ConjunctionScorer(null, subIterators, Collections.<Scorer>emptyList());
         } else {
-          subConjunction = ConjunctionDISI.intersect(subIterators);
+          subConjunction = new ConstantScoreScorer(null, 0f, ConjunctionDISI.intersectScorers(subIterators));
         }
-        iterators.set(subSeqStart, subConjunction);
+        scorers.set(subSeqStart, subConjunction);
         int toRemove = subSeqEnd - subSeqStart - 1;
         while (toRemove-- > 0) {
-          iterators.remove(subSeqStart + 1);
+          scorers.remove(subSeqStart + 1);
         }
       }
-      if (iterators.size() == 1) {
+      if (scorers.size() == 1) {
         // ConjunctionDISI needs two iterators
-        iterators.add(DocIdSetIterator.all(maxDoc));
+        scorers.add(new ConstantScoreScorer(null, 0f, DocIdSetIterator.all(maxDoc)));
       }
 
 
-      final ConjunctionDISI conjunction = ConjunctionDISI.intersect(iterators);
+      final ConjunctionDISI conjunction = ConjunctionDISI.intersectScorers(scorers);
       assertEquals(intersect(sets), toBitSet(maxDoc, conjunction));
     }
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java Thu Dec 10 17:45:29 2015
@@ -237,7 +237,7 @@ public class TestConstantScoreQuery exte
 
     final Weight weight = searcher.createNormalizedWeight(q, true);
     final Scorer scorer = weight.scorer(searcher.getIndexReader().leaves().get(0));
-    assertNotNull(scorer.asTwoPhaseIterator());
+    assertNotNull(scorer.twoPhaseIterator());
 
     reader.close();
     w.close();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java Thu Dec 10 17:45:29 2015
@@ -179,7 +179,7 @@ public class TestDisjunctionMaxQuery ext
     final Weight dw = s.createNormalizedWeight(dq, true);
     LeafReaderContext context = (LeafReaderContext)s.getTopReaderContext();
     final Scorer ds = dw.scorer(context);
-    final boolean skipOk = ds.advance(3) != DocIdSetIterator.NO_MORE_DOCS;
+    final boolean skipOk = ds.iterator().advance(3) != DocIdSetIterator.NO_MORE_DOCS;
     if (skipOk) {
       fail("firsttime skipTo found a match? ... "
           + r.document(ds.docID()).get("id"));
@@ -196,7 +196,7 @@ public class TestDisjunctionMaxQuery ext
     LeafReaderContext context = (LeafReaderContext)s.getTopReaderContext();
     final Scorer ds = dw.scorer(context);
     assertTrue("firsttime skipTo found no match",
-        ds.advance(3) != DocIdSetIterator.NO_MORE_DOCS);
+        ds.iterator().advance(3) != DocIdSetIterator.NO_MORE_DOCS);
     assertEquals("found wrong docid", "d4", r.document(ds.docID()).get("id"));
   }
   

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java Thu Dec 10 17:45:29 2015
@@ -147,36 +147,40 @@ public class TestMinShouldMatch2 extends
   
   private void assertNext(Scorer expected, Scorer actual) throws Exception {
     if (actual == null) {
-      assertEquals(DocIdSetIterator.NO_MORE_DOCS, expected.nextDoc());
+      assertEquals(DocIdSetIterator.NO_MORE_DOCS, expected.iterator().nextDoc());
       return;
     }
     int doc;
-    while ((doc = expected.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
-      assertEquals(doc, actual.nextDoc());
+    DocIdSetIterator expectedIt = expected.iterator();
+    DocIdSetIterator actualIt = actual.iterator();
+    while ((doc = expectedIt.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
+      assertEquals(doc, actualIt.nextDoc());
       assertEquals(expected.freq(), actual.freq());
       float expectedScore = expected.score();
       float actualScore = actual.score();
       assertEquals(expectedScore, actualScore, CheckHits.explainToleranceDelta(expectedScore, actualScore));
     }
-    assertEquals(DocIdSetIterator.NO_MORE_DOCS, actual.nextDoc());
+    assertEquals(DocIdSetIterator.NO_MORE_DOCS, actualIt.nextDoc());
   }
   
   private void assertAdvance(Scorer expected, Scorer actual, int amount) throws Exception {
     if (actual == null) {
-      assertEquals(DocIdSetIterator.NO_MORE_DOCS, expected.nextDoc());
+      assertEquals(DocIdSetIterator.NO_MORE_DOCS, expected.iterator().nextDoc());
       return;
     }
+    DocIdSetIterator expectedIt = expected.iterator();
+    DocIdSetIterator actualIt = actual.iterator();
     int prevDoc = 0;
     int doc;
-    while ((doc = expected.advance(prevDoc+amount)) != DocIdSetIterator.NO_MORE_DOCS) {
-      assertEquals(doc, actual.advance(prevDoc+amount));
+    while ((doc = expectedIt.advance(prevDoc+amount)) != DocIdSetIterator.NO_MORE_DOCS) {
+      assertEquals(doc, actualIt.advance(prevDoc+amount));
       assertEquals(expected.freq(), actual.freq());
       float expectedScore = expected.score();
       float actualScore = actual.score();
       assertEquals(expectedScore, actualScore, CheckHits.explainToleranceDelta(expectedScore, actualScore));
       prevDoc = doc;
     }
-    assertEquals(DocIdSetIterator.NO_MORE_DOCS, actual.advance(prevDoc+amount));
+    assertEquals(DocIdSetIterator.NO_MORE_DOCS, actualIt.advance(prevDoc+amount));
   }
   
   /** simple test for next(): minShouldMatch=2 on 3 terms (one common, one medium, one rare) */
@@ -361,37 +365,48 @@ public class TestMinShouldMatch2 extends
     }
 
     @Override
-    public int nextDoc() throws IOException {
-      assert currentDoc != NO_MORE_DOCS;
-      for (currentDoc = currentDoc+1; currentDoc < maxDoc; currentDoc++) {
-        currentMatched = 0;
-        score = 0;
-        dv.setDocument(currentDoc);
-        long ord;
-        while ((ord = dv.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
-          if (ords.contains(ord)) {
-            currentMatched++;
-            score += sims[(int)ord].score(currentDoc, 1);
+    public DocIdSetIterator iterator() {
+      return new DocIdSetIterator() {
+        
+        @Override
+        public int nextDoc() throws IOException {
+          assert currentDoc != NO_MORE_DOCS;
+          for (currentDoc = currentDoc+1; currentDoc < maxDoc; currentDoc++) {
+            currentMatched = 0;
+            score = 0;
+            dv.setDocument(currentDoc);
+            long ord;
+            while ((ord = dv.nextOrd()) != SortedSetDocValues.NO_MORE_ORDS) {
+              if (ords.contains(ord)) {
+                currentMatched++;
+                score += sims[(int)ord].score(currentDoc, 1);
+              }
+            }
+            if (currentMatched >= minNrShouldMatch) {
+              return currentDoc;
+            }
           }
+          return currentDoc = NO_MORE_DOCS;
         }
-        if (currentMatched >= minNrShouldMatch) {
-          return currentDoc;
-        }
-      }
-      return currentDoc = NO_MORE_DOCS;
-    }
 
-    @Override
-    public int advance(int target) throws IOException {
-      int doc;
-      while ((doc = nextDoc()) < target) {
-      }
-      return doc;
-    }
+        @Override
+        public int advance(int target) throws IOException {
+          int doc;
+          while ((doc = nextDoc()) < target) {
+          }
+          return doc;
+        }
 
-    @Override
-    public long cost() {
-      return maxDoc;
+        @Override
+        public long cost() {
+          return maxDoc;
+        }
+        
+        @Override
+        public int docID() {
+          return currentDoc;
+        }
+      };
     }
   }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java Thu Dec 10 17:45:29 2015
@@ -43,19 +43,29 @@ public class TestPositiveScoresOnlyColle
 
     @Override public int docID() { return idx; }
 
-    @Override public int nextDoc() {
-      return ++idx != scores.length ? idx : NO_MORE_DOCS;
-    }
-    
-    @Override public int advance(int target) {
-      idx = target;
-      return idx < scores.length ? idx : NO_MORE_DOCS;
-    }
-
     @Override
-    public long cost() {
-      return scores.length;
-    } 
+    public DocIdSetIterator iterator() {
+      return new DocIdSetIterator() {
+        @Override
+        public int docID() {
+          return idx;
+        }
+
+        @Override public int nextDoc() {
+          return ++idx != scores.length ? idx : NO_MORE_DOCS;
+        }
+        
+        @Override public int advance(int target) {
+          idx = target;
+          return idx < scores.length ? idx : NO_MORE_DOCS;
+        }
+
+        @Override
+        public long cost() {
+          return scores.length;
+        } 
+      };
+    }
   }
 
   // The scores must have positive as well as negative values
@@ -90,7 +100,7 @@ public class TestPositiveScoresOnlyColle
     Collector c = new PositiveScoresOnlyCollector(tdc);
     LeafCollector ac = c.getLeafCollector(ir.leaves().get(0));
     ac.setScorer(s);
-    while (s.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
+    while (s.iterator().nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
       ac.collect(0);
     }
     TopDocs td = tdc.topDocs();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java Thu Dec 10 17:45:29 2015
@@ -446,23 +446,34 @@ public class TestQueryRescorer extends L
             }
 
             @Override
-            public long cost() {
-              return 1;
-            }
+            public DocIdSetIterator iterator() {
+              return new DocIdSetIterator() {
 
-            @Override
-            public int nextDoc() {
-              docID++;
-              if (docID >= context.reader().maxDoc()) {
-                return NO_MORE_DOCS;
-              }
-              return docID;
-            }
+                @Override
+                public int docID() {
+                  return docID;
+                }
 
-            @Override
-            public int advance(int target) {
-              docID = target;
-              return docID;
+                @Override
+                public long cost() {
+                  return 1;
+                }
+
+                @Override
+                public int nextDoc() {
+                  docID++;
+                  if (docID >= context.reader().maxDoc()) {
+                    return NO_MORE_DOCS;
+                  }
+                  return docID;
+                }
+
+                @Override
+                public int advance(int target) {
+                  docID = target;
+                  return docID;
+                }
+              };
             }
 
             @Override

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java Thu Dec 10 17:45:29 2015
@@ -219,7 +219,7 @@ public class TestQueryWrapperFilter exte
     final Query query = new QueryWrapperFilter(new RandomApproximationQuery(new TermQuery(new Term("foo", "bar")), random()));
     final Weight weight = searcher.createNormalizedWeight(query, random().nextBoolean());
     final Scorer scorer = weight.scorer(reader.leaves().get(0));
-    assertNotNull(scorer.asTwoPhaseIterator());
+    assertNotNull(scorer.twoPhaseIterator());
     reader.close();
     dir.close();
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java Thu Dec 10 17:45:29 2015
@@ -49,18 +49,25 @@ public class TestScoreCachingWrappingSco
 
     @Override public int docID() { return doc; }
 
-    @Override public int nextDoc() {
-      return ++doc < scores.length ? doc : NO_MORE_DOCS;
-    }
-    
-    @Override public int advance(int target) {
-      doc = target;
-      return doc < scores.length ? doc : NO_MORE_DOCS;
-    }
-
     @Override
-    public long cost() {
-      return scores.length;
+    public DocIdSetIterator iterator() {
+      return new DocIdSetIterator() {
+        @Override public int docID() { return doc; }
+
+        @Override public int nextDoc() {
+          return ++doc < scores.length ? doc : NO_MORE_DOCS;
+        }
+        
+        @Override public int advance(int target) {
+          doc = target;
+          return doc < scores.length ? doc : NO_MORE_DOCS;
+        }
+
+        @Override
+        public long cost() {
+          return scores.length;
+        }
+      };
     }
   }
   
@@ -116,7 +123,7 @@ public class TestScoreCachingWrappingSco
     
     // We need to iterate on the scorer so that its doc() advances.
     int doc;
-    while ((doc = s.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
+    while ((doc = s.iterator().nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
       scc.collect(doc);
     }
     

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java Thu Dec 10 17:45:29 2015
@@ -144,13 +144,13 @@ public class TestTermScorer extends Luce
     LeafReaderContext context = (LeafReaderContext) indexSearcher.getTopReaderContext();
     Scorer ts = weight.scorer(context);
     assertTrue("next did not return a doc",
-        ts.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
+        ts.iterator().nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
     assertTrue("score is not correct", ts.score() == 1.6931472f);
     assertTrue("next did not return a doc",
-        ts.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
+        ts.iterator().nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
     assertTrue("score is not correct", ts.score() == 1.6931472f);
     assertTrue("next returned a doc and it should not have",
-        ts.nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
+        ts.iterator().nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
   }
   
   public void testAdvance() throws Exception {
@@ -162,7 +162,7 @@ public class TestTermScorer extends Luce
     assertTrue(indexSearcher.getTopReaderContext() instanceof LeafReaderContext);
     LeafReaderContext context = (LeafReaderContext) indexSearcher.getTopReaderContext();
     Scorer ts = weight.scorer(context);
-    assertTrue("Didn't skip", ts.advance(3) != DocIdSetIterator.NO_MORE_DOCS);
+    assertTrue("Didn't skip", ts.iterator().advance(3) != DocIdSetIterator.NO_MORE_DOCS);
     // The next doc should be doc 5
     assertTrue("doc should be number 5", ts.docID() == 5);
   }
@@ -199,7 +199,7 @@ public class TestTermScorer extends Luce
     
     Weight weight = indexSearcher.createNormalizedWeight(termQuery, true);
     try {
-      weight.scorer(forbiddenNorms.getContext()).nextDoc();
+      weight.scorer(forbiddenNorms.getContext()).iterator().nextDoc();
       fail("Should load norms");
     } catch (AssertionError e) {
       // ok
@@ -207,6 +207,6 @@ public class TestTermScorer extends Luce
     
     weight = indexSearcher.createNormalizedWeight(termQuery, false);
     // should not fail this time since norms are not necessary
-    weight.scorer(forbiddenNorms.getContext()).nextDoc();
+    weight.scorer(forbiddenNorms.getContext()).iterator().nextDoc();
   }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java Thu Dec 10 17:45:29 2015
@@ -236,18 +236,8 @@ public class TestTopFieldCollector exten
                     }
 
                     @Override
-                    public int nextDoc() throws IOException {
-                      return scorer.nextDoc();
-                    }
-
-                    @Override
-                    public int advance(int target) throws IOException {
-                      return scorer.advance(target);
-                    }
-
-                    @Override
-                    public long cost() {
-                      return scorer.cost();
+                    public DocIdSetIterator iterator() {
+                      return scorer.iterator();
                     }
                     
                   };

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java Thu Dec 10 17:45:29 2015
@@ -34,10 +34,6 @@ final class JustCompileSearchSpans {
 
   static final class JustCompileSpans extends Spans {
 
-    JustCompileSpans() {
-      super(null, null);
-    }
-
     @Override
     public int docID() {
       throw new UnsupportedOperationException(UNSUPPORTED_MSG);

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFilterSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFilterSpans.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFilterSpans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFilterSpans.java Thu Dec 10 17:45:29 2015
@@ -18,8 +18,6 @@ package org.apache.lucene.search.spans;
  */
 
 import java.lang.reflect.Method;
-import java.util.HashSet;
-import java.util.Set;
 
 import org.apache.lucene.util.LuceneTestCase;
 import org.junit.Test;
@@ -29,14 +27,9 @@ public class TestFilterSpans extends Luc
   @Test
   public void testOverrides() throws Exception {
     // verify that all methods of Spans are overridden by FilterSpans,
-    // except those under the 'exclude' list
-    Set<Method> exclude = new HashSet<>();
-    exclude.add(FilterSpans.class.getMethod("freq"));
-    exclude.add(FilterSpans.class.getMethod("score"));
-    exclude.add(FilterSpans.class.getMethod("sloppyFreq"));
     for (Method m : FilterSpans.class.getMethods()) {
       if (m.getDeclaringClass() == Spans.class) {
-        assertTrue("method " + m.getName() + " not overridden!", exclude.contains(m));
+        fail("method " + m.getName() + " not overridden!");
       }
     }
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java Thu Dec 10 17:45:29 2015
@@ -194,7 +194,7 @@ public class TestNearSpansOrdered extend
     IndexReaderContext topReaderContext = searcher.getTopReaderContext();
     LeafReaderContext leave = topReaderContext.leaves().get(0);
     Scorer s = w.scorer(leave);
-    assertEquals(1, s.advance(1));
+    assertEquals(1, s.iterator().advance(1));
   }
 
   public void testOverlappedOrderedSpan() throws Exception {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java Thu Dec 10 17:45:29 2015
@@ -303,12 +303,12 @@ public class TestSpans extends LuceneTes
         searcher.setSimilarity(oldSim);
       }
       if (i == subIndex) {
-        assertTrue("first doc", spanScorer.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
+        assertTrue("first doc", spanScorer.iterator().nextDoc() != DocIdSetIterator.NO_MORE_DOCS);
         assertEquals("first doc number", spanScorer.docID() + ctx.docBase, 11);
         float score = spanScorer.score();
         assertTrue("first doc score should be zero, " + score, score == 0.0f);
       } else {
-        assertTrue("no second doc", spanScorer == null || spanScorer.nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
+        assertTrue("no second doc", spanScorer == null || spanScorer.iterator().nextDoc() == DocIdSetIterator.NO_MORE_DOCS);
       }
     }
   }

Modified: lucene/dev/branches/branch_5x/lucene/expressions/src/java/org/apache/lucene/expressions/FakeScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/expressions/src/java/org/apache/lucene/expressions/FakeScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/expressions/src/java/org/apache/lucene/expressions/FakeScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/expressions/src/java/org/apache/lucene/expressions/FakeScorer.java Thu Dec 10 17:45:29 2015
@@ -19,6 +19,7 @@ package org.apache.lucene.expressions;
 
 import java.io.IOException;
 
+import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.Scorer;
 
 class FakeScorer extends Scorer {
@@ -37,17 +38,7 @@ class FakeScorer extends Scorer {
   }
 
   @Override
-  public int nextDoc() throws IOException {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public int advance(int target) throws IOException {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public long cost() {
+  public DocIdSetIterator iterator() {
     throw new UnsupportedOperationException();
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValueSource.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValueSource.java (original)
+++ lucene/dev/branches/branch_5x/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValueSource.java Thu Dec 10 17:45:29 2015
@@ -128,17 +128,19 @@ public class TestExpressionValueSource e
     
     // everything
     ValueSourceScorer scorer = values.getRangeScorer(leaf.reader(), "4", "40", true, true);
-    assertEquals(-1, scorer.docID());
-    assertEquals(0, scorer.nextDoc());
-    assertEquals(1, scorer.nextDoc());
-    assertEquals(2, scorer.nextDoc());
-    assertEquals(DocIdSetIterator.NO_MORE_DOCS, scorer.nextDoc());
+    DocIdSetIterator iter = scorer.iterator();
+    assertEquals(-1, iter.docID());
+    assertEquals(0, iter.nextDoc());
+    assertEquals(1, iter.nextDoc());
+    assertEquals(2, iter.nextDoc());
+    assertEquals(DocIdSetIterator.NO_MORE_DOCS, iter.nextDoc());
 
     // just the first doc
     scorer = values.getRangeScorer(leaf.reader(), "4", "40", false, false);
+    iter = scorer.iterator();
     assertEquals(-1, scorer.docID());
-    assertEquals(0, scorer.nextDoc());
-    assertEquals(DocIdSetIterator.NO_MORE_DOCS, scorer.nextDoc());
+    assertEquals(0, iter.nextDoc());
+    assertEquals(DocIdSetIterator.NO_MORE_DOCS, iter.nextDoc());
   }
   
   public void testEquals() throws Exception {




Mime
View raw message