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/12/10 18:45:31 UTC

svn commit: r1719124 [1/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...

Author: jpountz
Date: Thu Dec 10 17:45:29 2015
New Revision: 1719124

URL: http://svn.apache.org/viewvc?rev=1719124&view=rev
Log:
LUCENE-6919: Make Scorer expose an iterator instead of extending DocIdSetIterator.

Added:
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanScorer.java
      - copied, changed from r1719081, lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/spans/SpanScorer.java
Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/core/   (props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/BufferedUpdatesStream.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanTopLevelScorers.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BulkScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingCollector.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionDISI.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiPriorityQueue.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiWrapper.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ExactPhraseScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FakeScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MinShouldMatchSumScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Scorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/SloppyPhraseScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TwoPhaseIterator.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Weight.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/package-info.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ConjunctionSpans.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ContainSpans.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/FilterSpans.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansOrdered.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/NearSpansUnordered.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/ScoringWrapperSpans.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanBoostQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanContainingQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNearQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanOrQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanPositionCheckQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanTermQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWeight.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/SpanWithinQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/Spans.java
    lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/spans/TermSpans.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanCoord.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestBooleanRewrites.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestCachingCollector.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConjunctionDISI.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestConstantScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestDisjunctionMaxQuery.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestPositiveScoresOnlyCollector.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryRescorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestQueryWrapperFilter.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestScoreCachingWrappingScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTermScorer.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollector.java   (contents, props changed)
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/JustCompileSearchSpans.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestFilterSpans.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestNearSpansOrdered.java
    lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/spans/TestSpans.java
    lucene/dev/branches/branch_5x/lucene/expressions/   (props changed)
    lucene/dev/branches/branch_5x/lucene/expressions/src/java/org/apache/lucene/expressions/FakeScorer.java
    lucene/dev/branches/branch_5x/lucene/expressions/src/test/org/apache/lucene/expressions/TestExpressionValueSource.java
    lucene/dev/branches/branch_5x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/DrillSidewaysScorer.java
    lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRange.java
    lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/DoubleRangeFacetCounts.java
    lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/LongRange.java
    lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/range/LongRangeFacetCounts.java
    lucene/dev/branches/branch_5x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/FakeScorer.java
    lucene/dev/branches/branch_5x/lucene/grouping/   (props changed)
    lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java
    lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/FakeScorer.java
    lucene/dev/branches/branch_5x/lucene/join/   (props changed)
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/BaseGlobalOrdinalScorer.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/FakeScorer.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsQuery.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/GlobalOrdinalsWithScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/QueryBitSetProducer.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/TermsIncludingScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToChildBlockJoinQuery.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinIndexSearcher.java
    lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinQuery.java
    lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
    lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoinValidation.java
    lucene/dev/branches/branch_5x/lucene/misc/   (props changed)
    lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/index/PKIndexSplitter.java
    lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/index/Sorter.java
    lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/search/BlockJoinComparatorSource.java
    lucene/dev/branches/branch_5x/lucene/misc/src/test/org/apache/lucene/index/TestBlockJoinSorter.java
    lucene/dev/branches/branch_5x/lucene/queries/   (props changed)
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/BoostingQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/CustomScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/FunctionRangeQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSourceScorer.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/QueryValueSource.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadNearQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadScoreQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/payloads/PayloadTermQuery.java
    lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/payloads/SpanPayloadCheckQuery.java
    lucene/dev/branches/branch_5x/lucene/sandbox/   (props changed)
    lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/search/TermAutomatonScorer.java
    lucene/dev/branches/branch_5x/lucene/sandbox/src/test/org/apache/lucene/search/TestDocValuesRangeQuery.java
    lucene/dev/branches/branch_5x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/composite/CompositeVerifyQuery.java
    lucene/dev/branches/branch_5x/lucene/test-framework/   (props changed)
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/AssertingScorer.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/BulkScorerWrapperScorer.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/RandomApproximationQuery.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/ScorerIndexSearcher.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/spans/AssertingSpanWeight.java
    lucene/dev/branches/branch_5x/lucene/test-framework/src/java/org/apache/lucene/search/spans/AssertingSpans.java
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/LatLonType.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/CollapsingQParserPlugin.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/function/ValueSourceRangeFilter.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/search/TestRankQueryPlugin.java

Modified: lucene/dev/branches/branch_5x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/CHANGES.txt?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/lucene/CHANGES.txt Thu Dec 10 17:45:29 2015
@@ -21,6 +21,10 @@ API Changes
 * LUCENE-6900: Grouping sortWithinGroup variables used to allow null to mean
   Sort.RELEVANCE.  Null is no longer permitted.  (David Smiley)
 
+* LUCENE-6919: The Scorer class has been refactored to expose an iterator
+  instead of extending DocIdSetIterator. asTwoPhaseIterator() has been renamed
+  to twoPhaseIterator() for consistency. (Adrien Grand)
+
 Optimizations
 
 * LUCENE-6889: BooleanQuery.rewrite now performs some query optimization, in

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/BufferedUpdatesStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/BufferedUpdatesStream.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/BufferedUpdatesStream.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/index/BufferedUpdatesStream.java Thu Dec 10 17:45:29 2015
@@ -31,6 +31,7 @@ import java.util.concurrent.atomic.Atomi
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Weight;
 import org.apache.lucene.store.IOContext;
 import org.apache.lucene.util.Accountable;
@@ -696,8 +697,9 @@ class BufferedUpdatesStream implements A
       final IndexSearcher searcher = new IndexSearcher(readerContext.reader());
       searcher.setQueryCache(null);
       final Weight weight = searcher.createNormalizedWeight(query, false);
-      final DocIdSetIterator it = weight.scorer(readerContext);
-      if (it != null) {
+      final Scorer scorer = weight.scorer(readerContext);
+      if (scorer != null) {
+        final DocIdSetIterator it = scorer.iterator();
         final Bits liveDocs = readerContext.reader().getLiveDocs();
         while (true)  {
           int doc = it.nextDoc();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanTopLevelScorers.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanTopLevelScorers.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanTopLevelScorers.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BooleanTopLevelScorers.java Thu Dec 10 17:45:29 2015
@@ -123,22 +123,25 @@ class BooleanTopLevelScorers {
       this.coordReq = coordReq;
       this.coordBoth = coordBoth;
     }
-    
+
     @Override
     public float score() throws IOException {
+      // TODO: sum into a double and cast to float if we ever send required clauses to BS1
       int curDoc = reqScorer.docID();
-      float reqScore = reqScorer.score();
-      if (optScorer == null) {
-        return reqScore * coordReq;
+      float score = reqScorer.score();
+
+      int optScorerDoc = optIterator.docID();
+      if (optScorerDoc < curDoc) {
+        optScorerDoc = optIterator.advance(curDoc);
       }
       
-      int optScorerDoc = optScorer.docID();
-      if (optScorerDoc < curDoc && (optScorerDoc = optScorer.advance(curDoc)) == NO_MORE_DOCS) {
-        optScorer = null;
-        return reqScore * coordReq;
+      if (optScorerDoc == curDoc) {
+        score = (score + optScorer.score()) * coordBoth;
+      } else {
+        score = score * coordReq;
       }
       
-      return optScorerDoc == curDoc ? (reqScore + optScorer.score()) * coordBoth : reqScore * coordReq;
+      return score;
     }
   }
 
@@ -155,22 +158,25 @@ class BooleanTopLevelScorers {
       this.requiredCount = requiredCount;
       this.coords = coords;
     }
-    
+
     @Override
     public float score() throws IOException {
+      // TODO: sum into a double and cast to float if we ever send required clauses to BS1
       int curDoc = reqScorer.docID();
-      float reqScore = reqScorer.score();
-      if (optScorer == null) {
-        return reqScore * coords[requiredCount];
+      float score = reqScorer.score();
+
+      int optScorerDoc = optIterator.docID();
+      if (optScorerDoc < curDoc) {
+        optScorerDoc = optIterator.advance(curDoc);
       }
       
-      int optScorerDoc = optScorer.docID();
-      if (optScorerDoc < curDoc && (optScorerDoc = optScorer.advance(curDoc)) == NO_MORE_DOCS) {
-        optScorer = null;
-        return reqScore * coords[requiredCount];
+      if (optScorerDoc == curDoc) {
+        score = (score + optScorer.score()) * coords[requiredCount + optScorer.freq()];
+      } else {
+        score = score * coords[requiredCount];
       }
       
-      return optScorerDoc == curDoc ? (reqScore + optScorer.score()) * coords[requiredCount + optScorer.freq()] : reqScore * coords[requiredCount];
+      return score;
     }
   }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BulkScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BulkScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BulkScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/BulkScorer.java Thu Dec 10 17:45:29 2015
@@ -84,7 +84,7 @@ public abstract class BulkScorer {
   public abstract int score(LeafCollector collector, Bits acceptDocs, int min, int max) throws IOException;
 
   /**
-   * Same as {@link Scorer#cost()} for bulk scorers.
+   * Same as {@link DocIdSetIterator#cost()} for bulk scorers.
    */
   public abstract long cost();
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingCollector.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingCollector.java Thu Dec 10 17:45:29 2015
@@ -62,23 +62,21 @@ public abstract class CachingCollector e
     private CachedScorer() { super(null); }
 
     @Override
-    public final float score() { return score; }
+    public DocIdSetIterator iterator() {
+      throw new UnsupportedOperationException();
+    }
 
     @Override
-    public final int advance(int target) { throw new UnsupportedOperationException(); }
+    public final float score() { return score; }
 
     @Override
-    public final int docID() { return doc; }
+    public int docID() {
+      return doc;
+    }
 
     @Override
     public final int freq() { throw new UnsupportedOperationException(); }
 
-    @Override
-    public final int nextDoc() { throw new UnsupportedOperationException(); }
-
-    @Override
-    public long cost() { return 1; }
-
   }
 
   private static class NoScoreCachingCollector extends CachingCollector {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/CachingWrapperQuery.java Thu Dec 10 17:45:29 2015
@@ -132,7 +132,7 @@ public class CachingWrapperQuery extends
           if (scorer == null) {
             docIdSet = DocIdSet.EMPTY;
           } else {
-            docIdSet = cacheImpl(scorer, context.reader());
+            docIdSet = cacheImpl(scorer.iterator(), context.reader());
           }
           cache.put(key, docIdSet);
         } else {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionDISI.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionDISI.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionDISI.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionDISI.java Thu Dec 10 17:45:29 2015
@@ -23,6 +23,7 @@ import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 
+import org.apache.lucene.search.spans.Spans;
 import org.apache.lucene.util.CollectionUtil;
 
 /** A conjunction of DocIdSetIterators.
@@ -32,16 +33,34 @@ import org.apache.lucene.util.Collection
  */
 public class ConjunctionDISI extends DocIdSetIterator {
 
-  /** Create a conjunction over the provided iterators, taking advantage of
-   *  {@link TwoPhaseIterator}. */
-  public static ConjunctionDISI intersect(List<? extends DocIdSetIterator> iterators) {
+  /** Create a conjunction over the provided {@link Scorer}s, taking advantage
+   *  of {@link TwoPhaseIterator}. */
+  public static ConjunctionDISI intersectScorers(List<Scorer> scorers) {
+    if (scorers.size() < 2) {
+      throw new IllegalArgumentException("Cannot make a ConjunctionDISI of less than 2 iterators");
+    }
+    final List<DocIdSetIterator> allIterators = new ArrayList<>();
+    final List<TwoPhaseIterator> twoPhaseIterators = new ArrayList<>();
+    for (Scorer scorer : scorers) {
+      addScorer(scorer, allIterators, twoPhaseIterators);
+    }
+
+    if (twoPhaseIterators.isEmpty()) {
+      return new ConjunctionDISI(allIterators);
+    } else {
+      return new TwoPhase(allIterators, twoPhaseIterators);
+    }
+  }
+
+  /** Create a conjunction over the provided DocIdSetIterators. */
+  public static ConjunctionDISI intersectIterators(List<DocIdSetIterator> iterators) {
     if (iterators.size() < 2) {
       throw new IllegalArgumentException("Cannot make a ConjunctionDISI of less than 2 iterators");
     }
     final List<DocIdSetIterator> allIterators = new ArrayList<>();
     final List<TwoPhaseIterator> twoPhaseIterators = new ArrayList<>();
-    for (DocIdSetIterator iter : iterators) {
-      addIterator(iter, allIterators, twoPhaseIterators);
+    for (DocIdSetIterator iterator : iterators) {
+      addIterator(iterator, allIterators, twoPhaseIterators);
     }
 
     if (twoPhaseIterators.isEmpty()) {
@@ -51,12 +70,48 @@ public class ConjunctionDISI extends Doc
     }
   }
 
-  /** Adds the iterator, possibly splitting up into two phases or collapsing if it is another conjunction */
+  /** Create a conjunction over the provided {@link Scorer}s, taking advantage
+   *  of {@link TwoPhaseIterator}. */
+  public static ConjunctionDISI intersectSpans(List<Spans> spanList) {
+    if (spanList.size() < 2) {
+      throw new IllegalArgumentException("Cannot make a ConjunctionDISI of less than 2 iterators");
+    }
+    final List<DocIdSetIterator> allIterators = new ArrayList<>();
+    final List<TwoPhaseIterator> twoPhaseIterators = new ArrayList<>();
+    for (Spans spans : spanList) {
+      addSpans(spans, allIterators, twoPhaseIterators);
+    }
+
+    if (twoPhaseIterators.isEmpty()) {
+      return new ConjunctionDISI(allIterators);
+    } else {
+      return new TwoPhase(allIterators, twoPhaseIterators);
+    }
+  }
+
+  /** Adds the scorer, possibly splitting up into two phases or collapsing if it is another conjunction */
+  private static void addScorer(Scorer scorer, List<DocIdSetIterator> allIterators, List<TwoPhaseIterator> twoPhaseIterators) {
+    TwoPhaseIterator twoPhaseIter = scorer.twoPhaseIterator();
+    if (twoPhaseIter != null) {
+      addTwoPhaseIterator(twoPhaseIter, allIterators, twoPhaseIterators);
+    } else { // no approximation support, use the iterator as-is
+      addIterator(scorer.iterator(), allIterators, twoPhaseIterators);
+    }
+  }
+
+  /** Adds the Spans. */
+  private static void addSpans(Spans spans, List<DocIdSetIterator> allIterators, List<TwoPhaseIterator> twoPhaseIterators) {
+    TwoPhaseIterator twoPhaseIter = spans.asTwoPhaseIterator();
+    if (twoPhaseIter != null) {
+      addTwoPhaseIterator(twoPhaseIter, allIterators, twoPhaseIterators);
+    } else { // no approximation support, use the iterator as-is
+      addIterator(spans, allIterators, twoPhaseIterators);
+    }
+  }
+
   private static void addIterator(DocIdSetIterator disi, List<DocIdSetIterator> allIterators, List<TwoPhaseIterator> twoPhaseIterators) {
     // Check for exactly this class for collapsing. Subclasses can do their own optimizations.
-    if (disi.getClass() == ConjunctionScorer.class) {
-      addIterator(((ConjunctionScorer) disi).disi, allIterators, twoPhaseIterators);
-    } else if (disi.getClass() == ConjunctionDISI.class || disi.getClass() == TwoPhase.class) {
+    if (disi.getClass() == ConjunctionDISI.class || disi.getClass() == TwoPhase.class) {
       ConjunctionDISI conjunction = (ConjunctionDISI) disi;
       // subconjuctions have already split themselves into two phase iterators and others, so we can take those
       // iterators as they are and move them up to this conjunction
@@ -67,16 +122,15 @@ public class ConjunctionDISI extends Doc
         Collections.addAll(twoPhaseIterators, twoPhase.twoPhaseView.twoPhaseIterators);
       }
     } else {
-      TwoPhaseIterator twoPhaseIter = TwoPhaseIterator.asTwoPhaseIterator(disi);
-      if (twoPhaseIter != null) {
-        allIterators.add(twoPhaseIter.approximation());
-        twoPhaseIterators.add(twoPhaseIter);
-      } else { // no approximation support, use the iterator as-is
-        allIterators.add(disi);
-      }
+      allIterators.add(disi);
     }
   }
 
+  private static void addTwoPhaseIterator(TwoPhaseIterator twoPhaseIter, List<DocIdSetIterator> allIterators, List<TwoPhaseIterator> twoPhaseIterators) {
+    addIterator(twoPhaseIter.approximation(), allIterators, twoPhaseIterators);
+    twoPhaseIterators.add(twoPhaseIter);
+  }
+
   final DocIdSetIterator lead;
   final DocIdSetIterator[] others;
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConjunctionScorer.java Thu Dec 10 17:45:29 2015
@@ -29,27 +29,27 @@ class ConjunctionScorer extends Scorer {
   final Scorer[] scorers;
   final float coord;
 
-  ConjunctionScorer(Weight weight, List<? extends DocIdSetIterator> required, List<Scorer> scorers) {
+  ConjunctionScorer(Weight weight, List<Scorer> required, List<Scorer> scorers) {
     this(weight, required, scorers, 1f);
   }
 
   /** Create a new {@link ConjunctionScorer}, note that {@code scorers} must be a subset of {@code required}. */
-  ConjunctionScorer(Weight weight, List<? extends DocIdSetIterator> required, List<Scorer> scorers, float coord) {
+  ConjunctionScorer(Weight weight, List<Scorer> required, List<Scorer> scorers, float coord) {
     super(weight);
     assert required.containsAll(scorers);
     this.coord = coord;
-    this.disi = ConjunctionDISI.intersect(required);
+    this.disi = ConjunctionDISI.intersectScorers(required);
     this.scorers = scorers.toArray(new Scorer[scorers.size()]);
   }
 
   @Override
-  public TwoPhaseIterator asTwoPhaseIterator() {
+  public TwoPhaseIterator twoPhaseIterator() {
     return disi.asTwoPhaseIterator();
   }
 
   @Override
-  public int advance(int target) throws IOException {
-    return disi.advance(target);
+  public DocIdSetIterator iterator() {
+    return disi;
   }
 
   @Override
@@ -58,11 +58,6 @@ class ConjunctionScorer extends Scorer {
   }
 
   @Override
-  public int nextDoc() throws IOException {
-    return disi.nextDoc();
-  }
-
-  @Override
   public float score() throws IOException {
     double sum = 0.0d;
     for (Scorer scorer : scorers) {
@@ -77,11 +72,6 @@ class ConjunctionScorer extends Scorer {
   }
 
   @Override
-  public long cost() {
-    return disi.cost();
-  }
-
-  @Override
   public Collection<ChildScorer> getChildren() {
     ArrayList<ChildScorer> children = new ArrayList<>();
     for (Scorer scorer : scorers) {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreScorer.java Thu Dec 10 17:45:29 2015
@@ -54,18 +54,13 @@ public final class ConstantScoreScorer e
   }
 
   @Override
-  public TwoPhaseIterator asTwoPhaseIterator() {
-    return twoPhaseIterator;
-  }
-
-  @Override
-  public float score() throws IOException {
-    return score;
+  public DocIdSetIterator iterator() {
+    return disi;
   }
 
   @Override
-  public int freq() throws IOException {
-    return 1;
+  public TwoPhaseIterator twoPhaseIterator() {
+    return twoPhaseIterator;
   }
 
   @Override
@@ -74,18 +69,14 @@ public final class ConstantScoreScorer e
   }
 
   @Override
-  public int nextDoc() throws IOException {
-    return disi.nextDoc();
+  public float score() throws IOException {
+    return score;
   }
 
   @Override
-  public int advance(int target) throws IOException {
-    return disi.advance(target);
+  public int freq() throws IOException {
+    return 1;
   }
 
-  @Override
-  public long cost() {
-    return disi.cost();
-  }
 }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ConstantScoreWeight.java Thu Dec 10 17:45:29 2015
@@ -82,9 +82,9 @@ public abstract class ConstantScoreWeigh
     if (s == null) {
       exists = false;
     } else {
-      final TwoPhaseIterator twoPhase = s.asTwoPhaseIterator();
+      final TwoPhaseIterator twoPhase = s.twoPhaseIterator();
       if (twoPhase == null) {
-        exists = s.advance(doc) == doc;
+        exists = s.iterator().advance(doc) == doc;
       } else {
         exists = twoPhase.approximation().advance(doc) == doc && twoPhase.matches();
       }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiPriorityQueue.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiPriorityQueue.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiPriorityQueue.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiPriorityQueue.java Thu Dec 10 17:45:29 2015
@@ -28,8 +28,7 @@ import org.apache.lucene.util.PriorityQu
  * pluggable comparison function makes the rebalancing quite slow.
  * @lucene.internal
  */
-public final class DisiPriorityQueue<Iter extends DocIdSetIterator>
-implements Iterable<DisiWrapper<Iter>> {
+public final class DisiPriorityQueue implements Iterable<DisiWrapper> {
 
   static int leftNode(int node) {
     return ((node + 1) << 1) - 1;
@@ -43,10 +42,9 @@ implements Iterable<DisiWrapper<Iter>> {
     return ((node + 1) >>> 1) - 1;
   }
 
-  private final DisiWrapper<Iter>[] heap;
+  private final DisiWrapper[] heap;
   private int size;
 
-  @SuppressWarnings({"unchecked","rawtypes"})
   public DisiPriorityQueue(int maxSize) {
     heap = new DisiWrapper[maxSize];
     size = 0;
@@ -56,15 +54,15 @@ implements Iterable<DisiWrapper<Iter>> {
     return size;
   }
 
-  public DisiWrapper<Iter> top() {
+  public DisiWrapper top() {
     return heap[0];
   }
 
   /** Get the list of scorers which are on the current doc. */
-  public DisiWrapper<Iter> topList() {
-    final DisiWrapper<Iter>[] heap = this.heap;
+  public DisiWrapper topList() {
+    final DisiWrapper[] heap = this.heap;
     final int size = this.size;
-    DisiWrapper<Iter> list = heap[0];
+    DisiWrapper list = heap[0];
     list.next = null;
     if (size >= 3) {
       list = topList(list, heap, size, 1);
@@ -76,14 +74,14 @@ implements Iterable<DisiWrapper<Iter>> {
   }
 
   // prepend w1 (iterator) to w2 (list)
-  private DisiWrapper<Iter> prepend(DisiWrapper<Iter> w1, DisiWrapper<Iter> w2) {
+  private DisiWrapper prepend(DisiWrapper w1, DisiWrapper w2) {
     w1.next = w2;
     return w1;
   }
 
-  private DisiWrapper<Iter> topList(DisiWrapper<Iter> list, DisiWrapper<Iter>[] heap,
+  private DisiWrapper topList(DisiWrapper list, DisiWrapper[] heap,
                                     int size, int i) {
-    final DisiWrapper<Iter> w = heap[i];
+    final DisiWrapper w = heap[i];
     if (w.doc == list.doc) {
       list = prepend(w, list);
       final int left = leftNode(i);
@@ -98,8 +96,8 @@ implements Iterable<DisiWrapper<Iter>> {
     return list;
   }
 
-  public DisiWrapper<Iter> add(DisiWrapper<Iter> entry) {
-    final DisiWrapper<Iter>[] heap = this.heap;
+  public DisiWrapper add(DisiWrapper entry) {
+    final DisiWrapper[] heap = this.heap;
     final int size = this.size;
     heap[size] = entry;
     upHeap(size);
@@ -107,9 +105,9 @@ implements Iterable<DisiWrapper<Iter>> {
     return heap[0];
   }
 
-  public DisiWrapper<Iter> pop() {
-    final DisiWrapper<Iter>[] heap = this.heap;
-    final DisiWrapper<Iter> result = heap[0];
+  public DisiWrapper pop() {
+    final DisiWrapper[] heap = this.heap;
+    final DisiWrapper result = heap[0];
     final int i = --size;
     heap[0] = heap[i];
     heap[i] = null;
@@ -117,18 +115,18 @@ implements Iterable<DisiWrapper<Iter>> {
     return result;
   }
 
-  public DisiWrapper<Iter> updateTop() {
+  public DisiWrapper updateTop() {
     downHeap(size);
     return heap[0];
   }
 
-  DisiWrapper<Iter> updateTop(DisiWrapper<Iter> topReplacement) {
+  DisiWrapper updateTop(DisiWrapper topReplacement) {
     heap[0] = topReplacement;
     return updateTop();
   }
 
   void upHeap(int i) {
-    final DisiWrapper<Iter> node = heap[i];
+    final DisiWrapper node = heap[i];
     final int nodeDoc = node.doc;
     int j = parentNode(i);
     while (j >= 0 && nodeDoc < heap[j].doc) {
@@ -141,7 +139,7 @@ implements Iterable<DisiWrapper<Iter>> {
 
   void downHeap(int size) {
     int i = 0;
-    final DisiWrapper<Iter> node = heap[0];
+    final DisiWrapper node = heap[0];
     int j = leftNode(i);
     if (j < size) {
       int k = rightNode(j);
@@ -164,7 +162,7 @@ implements Iterable<DisiWrapper<Iter>> {
   }
 
   @Override
-  public Iterator<DisiWrapper<Iter>> iterator() {
+  public Iterator<DisiWrapper> iterator() {
     return Arrays.asList(heap).subList(0, size).iterator();
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiWrapper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiWrapper.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiWrapper.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisiWrapper.java Thu Dec 10 17:45:29 2015
@@ -17,15 +17,18 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import org.apache.lucene.search.spans.Spans;
+
 /**
  * Wrapper used in {@link DisiPriorityQueue}.
  * @lucene.internal
  */
-public class DisiWrapper<Iter extends DocIdSetIterator> {
-  public final Iter iterator;
+public class DisiWrapper {
+  public final DocIdSetIterator iterator;
+  public final Scorer scorer;
   public final long cost;
   public int doc; // the current doc, used for comparison
-  public DisiWrapper<Iter> next; // reference to a next element, see #topList
+  public DisiWrapper next; // reference to a next element, see #topList
 
   // An approximation of the iterator, or the iterator itself if it does not
   // support two-phase iteration
@@ -33,15 +36,34 @@ public class DisiWrapper<Iter extends Do
   // A two-phase view of the iterator, or null if the iterator does not support
   // two-phase iteration
   public final TwoPhaseIterator twoPhaseView;
-  
+
+  // FOR SPANS
+  public final Spans spans;
   public int lastApproxMatchDoc; // last doc of approximation that did match
   public int lastApproxNonMatchDoc; // last doc of approximation that did not match
 
-  public DisiWrapper(Iter iterator) {
-    this.iterator = iterator;
+  public DisiWrapper(Scorer scorer) {
+    this.scorer = scorer;
+    this.spans = null;
+    this.iterator = scorer.iterator();
+    this.cost = iterator.cost();
+    this.doc = -1;
+    this.twoPhaseView = scorer.twoPhaseIterator();
+      
+    if (twoPhaseView != null) {
+      approximation = twoPhaseView.approximation();
+    } else {
+      approximation = iterator;
+    }
+  }
+
+  public DisiWrapper(Spans spans) {
+    this.scorer = null;
+    this.spans = spans;
+    this.iterator = spans;
     this.cost = iterator.cost();
     this.doc = -1;
-    this.twoPhaseView = TwoPhaseIterator.asTwoPhaseIterator(iterator);
+    this.twoPhaseView = spans.asTwoPhaseIterator();
       
     if (twoPhaseView != null) {
       approximation = twoPhaseView.approximation();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionDISIApproximation.java Thu Dec 10 17:45:29 2015
@@ -23,16 +23,15 @@ import java.io.IOException;
  * the provided iterators.
  * @lucene.internal
  */
-public class DisjunctionDISIApproximation<Iter extends DocIdSetIterator>
-extends DocIdSetIterator {
+public class DisjunctionDISIApproximation extends DocIdSetIterator {
 
-  final DisiPriorityQueue<Iter> subIterators;
+  final DisiPriorityQueue subIterators;
   final long cost;
 
-  public DisjunctionDISIApproximation(DisiPriorityQueue<Iter> subIterators) {
+  public DisjunctionDISIApproximation(DisiPriorityQueue subIterators) {
     this.subIterators = subIterators;
     long cost = 0;
-    for (DisiWrapper<Iter> w : subIterators) {
+    for (DisiWrapper w : subIterators) {
       cost += w.cost;
     }
     this.cost = cost;
@@ -50,7 +49,7 @@ extends DocIdSetIterator {
 
   @Override
   public int nextDoc() throws IOException {
-    DisiWrapper<Iter> top = subIterators.top();
+    DisiWrapper top = subIterators.top();
     final int doc = top.doc;
     do {
       top.doc = top.approximation.nextDoc();
@@ -62,7 +61,7 @@ extends DocIdSetIterator {
 
   @Override
   public int advance(int target) throws IOException {
-    DisiWrapper<Iter> top = subIterators.top();
+    DisiWrapper top = subIterators.top();
     do {
       top.doc = top.approximation.advance(target);
       top = subIterators.updateTop();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java Thu Dec 10 17:45:29 2015
@@ -46,11 +46,11 @@ final class DisjunctionMaxScorer extends
   }
 
   @Override
-  protected float score(DisiWrapper<Scorer> topList) throws IOException {
+  protected float score(DisiWrapper topList) throws IOException {
     float scoreSum = 0;
     float scoreMax = 0;
-    for (DisiWrapper<Scorer> w = topList; w != null; w = w.next) {
-      final float subScore = w.iterator.score();
+    for (DisiWrapper w = topList; w != null; w = w.next) {
+      final float subScore = w.scorer.score();
       scoreSum += subScore;
       if (subScore > scoreMax) {
         scoreMax = subScore;

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionScorer.java Thu Dec 10 17:45:29 2015
@@ -28,21 +28,21 @@ import java.util.List;
 abstract class DisjunctionScorer extends Scorer {
 
   private final boolean needsScores;
-  private final DisiPriorityQueue<Scorer> subScorers;
+  private final DisiPriorityQueue subScorers;
   private final long cost;
 
   /** Linked list of scorers which are on the current doc */
-  private DisiWrapper<Scorer> topScorers;
+  private DisiWrapper topScorers;
 
   protected DisjunctionScorer(Weight weight, List<Scorer> subScorers, boolean needsScores) {
     super(weight);
     if (subScorers.size() <= 1) {
       throw new IllegalArgumentException("There must be at least 2 subScorers");
     }
-    this.subScorers = new DisiPriorityQueue<Scorer>(subScorers.size());
+    this.subScorers = new DisiPriorityQueue(subScorers.size());
     long cost = 0;
     for (Scorer scorer : subScorers) {
-      final DisiWrapper<Scorer> w = new DisiWrapper<>(scorer);
+      final DisiWrapper w = new DisiWrapper(scorer);
       cost += w.cost;
       this.subScorers.add(w);
     }
@@ -51,13 +51,55 @@ abstract class DisjunctionScorer extends
   }
 
   @Override
-  public TwoPhaseIterator asTwoPhaseIterator() {
+  public DocIdSetIterator iterator() {
+    return new DocIdSetIterator() {
+
+      @Override
+      public int docID() {
+        return subScorers.top().doc;
+      }
+
+      @Override
+      public final int nextDoc() throws IOException {
+        topScorers = null;
+        DisiWrapper top = subScorers.top();
+        final int doc = top.doc;
+        do {
+          top.doc = top.iterator.nextDoc();
+          top = subScorers.updateTop();
+        } while (top.doc == doc);
+
+        return top.doc;
+      }
+
+      @Override
+      public final int advance(int target) throws IOException {
+        topScorers = null;
+        DisiWrapper top = subScorers.top();
+        do {
+          top.doc = top.iterator.advance(target);
+          top = subScorers.updateTop();
+        } while (top.doc < target);
+
+        return top.doc;
+      }
+
+      @Override
+      public final long cost() {
+        return cost;
+      }
+
+    };
+  }
+
+  @Override
+  public TwoPhaseIterator twoPhaseIterator() {
     float sumMatchCost = 0;
     long sumApproxCost = 0;
 
     // Compute matchCost as the avarage over the matchCost of the subScorers.
     // This is weighted by the cost, which is an expected number of matching documents.
-    for (DisiWrapper<Scorer> w : subScorers) {
+    for (DisiWrapper w : subScorers) {
       if (w.twoPhaseView != null) {
         long costWeight = (w.cost <= 1) ? 1 : w.cost;
         sumMatchCost += w.twoPhaseView.matchCost() * costWeight;
@@ -74,11 +116,11 @@ abstract class DisjunctionScorer extends
     // note it is important to share the same pq as this scorer so that
     // rebalancing the pq through the approximation will also rebalance
     // the pq in this scorer.
-    return new TwoPhaseIterator(new DisjunctionDISIApproximation<Scorer>(subScorers)) {
+    return new TwoPhaseIterator(new DisjunctionDISIApproximation(subScorers)) {
 
       @Override
       public boolean matches() throws IOException {
-        DisiWrapper<Scorer> topScorers = subScorers.topList();
+        DisiWrapper topScorers = subScorers.topList();
         // remove the head of the list as long as it does not match
         while (topScorers.twoPhaseView != null && ! topScorers.twoPhaseView.matches()) {
           topScorers = topScorers.next;
@@ -90,8 +132,8 @@ abstract class DisjunctionScorer extends
         if (needsScores) {
           // if scores or freqs are needed, we also need to remove scorers
           // from the top list that do not actually match
-          DisiWrapper<Scorer> previous = topScorers;
-          for (DisiWrapper<Scorer> w = topScorers.next; w != null; w = w.next) {
+          DisiWrapper previous = topScorers;
+          for (DisiWrapper w = topScorers.next; w != null; w = w.next) {
             if (w.twoPhaseView != null && ! w.twoPhaseView.matches()) {
               // w does not match, remove it
               previous.next = w.next;
@@ -120,47 +162,17 @@ abstract class DisjunctionScorer extends
   }
 
   @Override
-  public final long cost() {
-    return cost;
-  }
-
-  @Override
   public final int docID() {
    return subScorers.top().doc;
   }
 
   @Override
-  public final int nextDoc() throws IOException {
-    topScorers = null;
-    DisiWrapper<Scorer> top = subScorers.top();
-    final int doc = top.doc;
-    do {
-      top.doc = top.iterator.nextDoc();
-      top = subScorers.updateTop();
-    } while (top.doc == doc);
-
-    return top.doc;
-  }
-
-  @Override
-  public final int advance(int target) throws IOException {
-    topScorers = null;
-    DisiWrapper<Scorer> top = subScorers.top();
-    do {
-      top.doc = top.iterator.advance(target);
-      top = subScorers.updateTop();
-    } while (top.doc < target);
-
-    return top.doc;
-  }
-
-  @Override
   public final int freq() throws IOException {
     if (topScorers == null) {
       topScorers = subScorers.topList();
     }
     int freq = 1;
-    for (DisiWrapper<Scorer> w = topScorers.next; w != null; w = w.next) {
+    for (DisiWrapper w = topScorers.next; w != null; w = w.next) {
       freq += 1;
     }
     return freq;
@@ -175,13 +187,13 @@ abstract class DisjunctionScorer extends
   }
 
   /** Compute the score for the given linked list of scorers. */
-  protected abstract float score(DisiWrapper<Scorer> topList) throws IOException;
+  protected abstract float score(DisiWrapper topList) throws IOException;
 
   @Override
   public final Collection<ChildScorer> getChildren() {
     ArrayList<ChildScorer> children = new ArrayList<>();
-    for (DisiWrapper<Scorer> scorer : subScorers) {
-      children.add(new ChildScorer(scorer.iterator, "SHOULD"));
+    for (DisiWrapper scorer : subScorers) {
+      children.add(new ChildScorer(scorer.scorer, "SHOULD"));
     }
     return children;
   }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/DisjunctionSumScorer.java Thu Dec 10 17:45:29 2015
@@ -21,7 +21,6 @@ import java.io.IOException;
 import java.util.List;
 
 /** A Scorer for OR like queries, counterpart of <code>ConjunctionScorer</code>.
- * This Scorer implements {@link Scorer#advance(int)} and uses advance() on the given Scorers. 
  */
 final class DisjunctionSumScorer extends DisjunctionScorer { 
   private final float[] coord;
@@ -37,11 +36,11 @@ final class DisjunctionSumScorer extends
   }
 
   @Override
-  protected float score(DisiWrapper<Scorer> topList) throws IOException {
+  protected float score(DisiWrapper topList) throws IOException {
     double score = 0;
     int freq = 0;
-    for (DisiWrapper<Scorer> w = topList; w != null; w = w.next) {
-      score += w.iterator.score();
+    for (DisiWrapper w = topList; w != null; w = w.next) {
+      score += w.scorer.score();
       freq += 1;
     }
     return (float)score * coord[freq];

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ExactPhraseScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ExactPhraseScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ExactPhraseScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ExactPhraseScorer.java Thu Dec 10 17:45:29 2015
@@ -59,13 +59,13 @@ final class ExactPhraseScorer extends Sc
       iterators.add(posting.postings);
       postingsAndPositions.add(new PostingsAndPosition(posting.postings, posting.position));
     }
-    conjunction = ConjunctionDISI.intersect(iterators);
+    conjunction = ConjunctionDISI.intersectIterators(iterators);
     this.postings = postingsAndPositions.toArray(new PostingsAndPosition[postingsAndPositions.size()]);
     this.matchCost = matchCost;
   }
 
   @Override
-  public TwoPhaseIterator asTwoPhaseIterator() {
+  public TwoPhaseIterator twoPhaseIterator() {
     return new TwoPhaseIterator(conjunction) {
       @Override
       public boolean matches() throws IOException {
@@ -79,22 +79,9 @@ final class ExactPhraseScorer extends Sc
     };
   }
 
-  private int doNext(int doc) throws IOException {
-    for (;; doc = conjunction.nextDoc()) {
-      if (doc == NO_MORE_DOCS || phraseFreq() > 0) {
-        return doc;
-      }
-    }
-  }
-
   @Override
-  public int nextDoc() throws IOException {
-    return doNext(conjunction.nextDoc());
-  }
-
-  @Override
-  public int advance(int target) throws IOException {
-    return doNext(conjunction.advance(target));
+  public DocIdSetIterator iterator() {
+    return TwoPhaseIterator.asDocIdSetIterator(twoPhaseIterator());
   }
 
   @Override
@@ -180,8 +167,4 @@ final class ExactPhraseScorer extends Sc
     return this.freq = freq;
   }
 
-  @Override
-  public long cost() {
-    return conjunction.cost();
-  }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FakeScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FakeScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FakeScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FakeScorer.java Thu Dec 10 17:45:29 2015
@@ -29,11 +29,6 @@ final class FakeScorer extends Scorer {
   public FakeScorer() {
     super(null);
   }
-    
-  @Override
-  public int advance(int target) {
-    throw new UnsupportedOperationException("FakeScorer doesn't support advance(int)");
-  }
 
   @Override
   public int docID() {
@@ -44,11 +39,6 @@ final class FakeScorer extends Scorer {
   public int freq() {
     return freq;
   }
-
-  @Override
-  public int nextDoc() {
-    throw new UnsupportedOperationException("FakeScorer doesn't support nextDoc()");
-  }
     
   @Override
   public float score() {
@@ -56,8 +46,8 @@ final class FakeScorer extends Scorer {
   }
 
   @Override
-  public long cost() {
-    return 1;
+  public DocIdSetIterator iterator() {
+    throw new UnsupportedOperationException();
   }
 
   @Override

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilterScorer.java Thu Dec 10 17:45:29 2015
@@ -70,22 +70,12 @@ public abstract class FilterScorer exten
   }
 
   @Override
-  public final int nextDoc() throws IOException {
-    return in.nextDoc();
-  }
-
-  @Override
-  public final int advance(int target) throws IOException {
-    return in.advance(target);
-  }
-
-  @Override
-  public long cost() {
-    return in.cost();
+  public final DocIdSetIterator iterator() {
+    return in.iterator();
   }
   
   @Override
-  public final TwoPhaseIterator asTwoPhaseIterator() {
-    return in.asTwoPhaseIterator();
+  public final TwoPhaseIterator twoPhaseIterator() {
+    return in.twoPhaseIterator();
   }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/FilteredQuery.java Thu Dec 10 17:45:29 2015
@@ -285,9 +285,9 @@ public class FilteredQuery extends Query
           if (s == null) {
             match = false;
           } else {
-            final TwoPhaseIterator twoPhase = s.asTwoPhaseIterator();
+            final TwoPhaseIterator twoPhase = s.twoPhaseIterator();
             if (twoPhase == null) {
-              match = s.advance(doc) == doc;
+              match = s.iterator().advance(doc) == doc;
             } else {
               match = twoPhase.approximation().advance(doc) == doc && twoPhase.matches();
             }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MinShouldMatchSumScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MinShouldMatchSumScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MinShouldMatchSumScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MinShouldMatchSumScorer.java Thu Dec 10 17:45:29 2015
@@ -64,7 +64,7 @@ final class MinShouldMatchSumScorer exte
     final PriorityQueue<Scorer> pq = new PriorityQueue<Scorer>(scorers.size() - minShouldMatch + 1) {
       @Override
       protected boolean lessThan(Scorer a, Scorer b) {
-        return a.cost() > b.cost();
+        return a.iterator().cost() > b.iterator().cost();
       }
     };
     for (Scorer scorer : scorers) {
@@ -72,7 +72,7 @@ final class MinShouldMatchSumScorer exte
     }
     long cost = 0;
     for (Scorer scorer = pq.pop(); scorer != null; scorer = pq.pop()) {
-      cost += scorer.cost();
+      cost += scorer.iterator().cost();
     }
     return cost;
   }
@@ -82,23 +82,22 @@ final class MinShouldMatchSumScorer exte
 
   // list of scorers which 'lead' the iteration and are currently
   // positioned on 'doc'
-  DisiWrapper<Scorer> lead;
+  DisiWrapper lead;
   int doc;  // current doc ID of the leads
   int freq; // number of scorers on the desired doc ID
 
   // priority queue of scorers that are too advanced compared to the current
   // doc. Ordered by doc ID.
-  final DisiPriorityQueue<Scorer> head;
+  final DisiPriorityQueue head;
 
   // priority queue of scorers which are behind the current doc.
   // Ordered by cost.
-  final DisiWrapper<Scorer>[] tail;
+  final DisiWrapper[] tail;
   int tailSize;
 
   final Collection<ChildScorer> childScorers;
   final long cost;
 
-  @SuppressWarnings({"unchecked","rawtypes"})
   MinShouldMatchSumScorer(Weight weight, Collection<Scorer> scorers, int minShouldMatch, float[] coord) {
     super(weight);
 
@@ -113,13 +112,13 @@ final class MinShouldMatchSumScorer exte
     this.coord = coord;
     this.doc = -1;
 
-    head = new DisiPriorityQueue<Scorer>(scorers.size() - minShouldMatch + 1);
+    head = new DisiPriorityQueue(scorers.size() - minShouldMatch + 1);
     // there can be at most minShouldMatch - 1 scorers beyond the current position
     // otherwise we might be skipping over matching documents
     tail = new DisiWrapper[minShouldMatch - 1];
 
     for (Scorer scorer : scorers) {
-      addLead(new DisiWrapper<Scorer>(scorer));
+      addLead(new DisiWrapper(scorer));
     }
 
     List<ChildScorer> children = new ArrayList<>();
@@ -131,76 +130,88 @@ final class MinShouldMatchSumScorer exte
   }
 
   @Override
-  public long cost() {
-    return cost;
-  }
-
-  @Override
   public final Collection<ChildScorer> getChildren() {
     return childScorers;
   }
 
   @Override
-  public int nextDoc() throws IOException {
-    // We are moving to the next doc ID, so scorers in 'lead' need to go in
-    // 'tail'. If there is not enough space in 'tail', then we take the least
-    // costly scorers and advance them.
-    for (DisiWrapper<Scorer> s = lead; s != null; s = s.next) {
-      final DisiWrapper<Scorer> evicted = insertTailWithOverFlow(s);
-      if (evicted != null) {
-        if (evicted.doc == doc) {
-          evicted.doc = evicted.iterator.nextDoc();
-        } else {
-          evicted.doc = evicted.iterator.advance(doc + 1);
-        }
-        head.add(evicted);
+  public DocIdSetIterator iterator() {
+    return new DocIdSetIterator() {
+
+      @Override
+      public int docID() {
+        assert doc == lead.doc;
+        return doc;
       }
-    }
 
-    setDocAndFreq();
-    return doNext();
-  }
+      @Override
+      public int nextDoc() throws IOException {
+        // We are moving to the next doc ID, so scorers in 'lead' need to go in
+        // 'tail'. If there is not enough space in 'tail', then we take the least
+        // costly scorers and advance them.
+        for (DisiWrapper s = lead; s != null; s = s.next) {
+          final DisiWrapper evicted = insertTailWithOverFlow(s);
+          if (evicted != null) {
+            if (evicted.doc == doc) {
+              evicted.doc = evicted.iterator.nextDoc();
+            } else {
+              evicted.doc = evicted.iterator.advance(doc + 1);
+            }
+            head.add(evicted);
+          }
+        }
 
-  @Override
-  public int advance(int target) throws IOException {
-    // Same logic as in nextDoc
-    for (DisiWrapper<Scorer> s = lead; s != null; s = s.next) {
-      final DisiWrapper<Scorer> evicted = insertTailWithOverFlow(s);
-      if (evicted != null) {
-        evicted.doc = evicted.iterator.advance(target);
-        head.add(evicted);
+        setDocAndFreq();
+        return doNext();
       }
-    }
 
-    // But this time there might also be scorers in 'head' behind the desired
-    // target so we need to do the same thing that we did on 'lead' on 'head'
-    DisiWrapper<Scorer> headTop = head.top();
-    while (headTop.doc < target) {
-      final DisiWrapper<Scorer> evicted = insertTailWithOverFlow(headTop);
-      // We know that the tail is full since it contains at most
-      // minShouldMatch - 1 entries and we just moved at least minShouldMatch
-      // entries to it, so evicted is not null
-      evicted.doc = evicted.iterator.advance(target);
-      headTop = head.updateTop(evicted);
-    }
+      @Override
+      public int advance(int target) throws IOException {
+        // Same logic as in nextDoc
+        for (DisiWrapper s = lead; s != null; s = s.next) {
+          final DisiWrapper evicted = insertTailWithOverFlow(s);
+          if (evicted != null) {
+            evicted.doc = evicted.iterator.advance(target);
+            head.add(evicted);
+          }
+        }
+
+        // But this time there might also be scorers in 'head' behind the desired
+        // target so we need to do the same thing that we did on 'lead' on 'head'
+        DisiWrapper headTop = head.top();
+        while (headTop.doc < target) {
+          final DisiWrapper evicted = insertTailWithOverFlow(headTop);
+          // We know that the tail is full since it contains at most
+          // minShouldMatch - 1 entries and we just moved at least minShouldMatch
+          // entries to it, so evicted is not null
+          evicted.doc = evicted.iterator.advance(target);
+          headTop = head.updateTop(evicted);
+        }
 
-    setDocAndFreq();
-    return doNext();
+        setDocAndFreq();
+        return doNext();
+      }
+
+      @Override
+      public long cost() {
+        return cost;
+      }
+    };
   }
 
-  private void addLead(DisiWrapper<Scorer> lead) {
+  private void addLead(DisiWrapper lead) {
     lead.next = this.lead;
     this.lead = lead;
     freq += 1;
   }
 
   private void pushBackLeads() throws IOException {
-    for (DisiWrapper<Scorer> s = lead; s != null; s = s.next) {
+    for (DisiWrapper s = lead; s != null; s = s.next) {
       addTail(s);
     }
   }
 
-  private void advanceTail(DisiWrapper<Scorer> top) throws IOException {
+  private void advanceTail(DisiWrapper top) throws IOException {
     top.doc = top.iterator.advance(doc);
     if (top.doc == doc) {
       addLead(top);
@@ -210,7 +221,7 @@ final class MinShouldMatchSumScorer exte
   }
 
   private void advanceTail() throws IOException {
-    final DisiWrapper<Scorer> top = popTail();
+    final DisiWrapper top = popTail();
     advanceTail(top);
   }
 
@@ -276,8 +287,8 @@ final class MinShouldMatchSumScorer exte
     // we need to know about all matches
     updateFreq();
     double score = 0;
-    for (DisiWrapper<Scorer> s = lead; s != null; s = s.next) {
-      score += s.iterator.score();
+    for (DisiWrapper s = lead; s != null; s = s.next) {
+      score += s.scorer.score();
     }
     return coord[freq] * (float) score;
   }
@@ -289,12 +300,12 @@ final class MinShouldMatchSumScorer exte
   }
 
   /** Insert an entry in 'tail' and evict the least-costly scorer if full. */
-  private DisiWrapper<Scorer> insertTailWithOverFlow(DisiWrapper<Scorer> s) {
+  private DisiWrapper insertTailWithOverFlow(DisiWrapper s) {
     if (tailSize < tail.length) {
       addTail(s);
       return null;
     } else if (tail.length >= 1) {
-      final DisiWrapper<Scorer> top = tail[0];
+      final DisiWrapper top = tail[0];
       if (top.cost < s.cost) {
         tail[0] = s;
         downHeapCost(tail, tailSize);
@@ -305,16 +316,16 @@ final class MinShouldMatchSumScorer exte
   }
 
   /** Add an entry to 'tail'. Fails if over capacity. */
-  private void addTail(DisiWrapper<Scorer> s) {
+  private void addTail(DisiWrapper s) {
     tail[tailSize] = s;
     upHeapCost(tail, tailSize);
     tailSize += 1;
   }
 
   /** Pop the least-costly scorer from 'tail'. */
-  private DisiWrapper<Scorer> popTail() {
+  private DisiWrapper popTail() {
     assert tailSize > 0;
-    final DisiWrapper<Scorer> result = tail[0];
+    final DisiWrapper result = tail[0];
     tail[0] = tail[--tailSize];
     downHeapCost(tail, tailSize);
     return result;
@@ -322,8 +333,8 @@ final class MinShouldMatchSumScorer exte
 
   /** Heap helpers */
 
-  private static void upHeapCost(DisiWrapper<Scorer>[] heap, int i) {
-    final DisiWrapper<Scorer> node = heap[i];
+  private static void upHeapCost(DisiWrapper[] heap, int i) {
+    final DisiWrapper node = heap[i];
     final long nodeCost = node.cost;
     int j = parentNode(i);
     while (j >= 0 && nodeCost < heap[j].cost) {
@@ -334,9 +345,9 @@ final class MinShouldMatchSumScorer exte
     heap[i] = node;
   }
 
-  private static void downHeapCost(DisiWrapper<Scorer>[] heap, int size) {
+  private static void downHeapCost(DisiWrapper[] heap, int size) {
     int i = 0;
-    final DisiWrapper<Scorer> node = heap[0];
+    final DisiWrapper node = heap[0];
     int j = leftNode(i);
     if (j < size) {
       int k = rightNode(j);

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/MultiPhraseQuery.java Thu Dec 10 17:45:29 2015
@@ -242,7 +242,7 @@ public class MultiPhraseQuery extends Qu
     public Explanation explain(LeafReaderContext context, int doc) throws IOException {
       Scorer scorer = scorer(context);
       if (scorer != null) {
-        int newDoc = scorer.advance(doc);
+        int newDoc = scorer.iterator().advance(doc);
         if (newDoc == doc) {
           float freq = slop == 0 ? scorer.freq() : ((SloppyPhraseScorer)scorer).sloppyFreq();
           SimScorer docScorer = similarity.simScorer(stats, context);

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/PhraseQuery.java Thu Dec 10 17:45:29 2015
@@ -472,7 +472,7 @@ public class PhraseQuery extends Query {
     public Explanation explain(LeafReaderContext context, int doc) throws IOException {
       Scorer scorer = scorer(context);
       if (scorer != null) {
-        int newDoc = scorer.advance(doc);
+        int newDoc = scorer.iterator().advance(doc);
         if (newDoc == doc) {
           float freq = slop == 0 ? scorer.freq() : ((SloppyPhraseScorer)scorer).sloppyFreq();
           SimScorer docScorer = similarity.simScorer(stats, context);

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryRescorer.java Thu Dec 10 17:45:29 2015
@@ -89,7 +89,7 @@ public abstract class QueryRescorer exte
         int targetDoc = docID - docBase;
         int actualDoc = scorer.docID();
         if (actualDoc < targetDoc) {
-          actualDoc = scorer.advance(targetDoc);
+          actualDoc = scorer.iterator().advance(targetDoc);
         }
 
         if (actualDoc == targetDoc) {

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/QueryWrapperFilter.java Thu Dec 10 17:45:29 2015
@@ -66,7 +66,8 @@ public class QueryWrapperFilter extends
     DocIdSet set = new DocIdSet() {
       @Override
       public DocIdSetIterator iterator() throws IOException {
-        return weight.scorer(privateContext);
+        Scorer s = weight.scorer(privateContext);
+        return s == null ? null : s.iterator();
       }
 
       @Override

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqExclScorer.java Thu Dec 10 17:45:29 2015
@@ -23,9 +23,6 @@ import java.util.Collections;
 
 /** A Scorer for queries with a required subscorer
  * and an excluding (prohibited) sub {@link Scorer}.
- * <br>
- * This <code>Scorer</code> implements {@link Scorer#advance(int)},
- * and it uses the advance() on the given scorers.
  */
 class ReqExclScorer extends Scorer {
 
@@ -44,25 +41,20 @@ class ReqExclScorer extends Scorer {
   public ReqExclScorer(Scorer reqScorer, Scorer exclScorer) {
     super(reqScorer.weight);
     this.reqScorer = reqScorer;
-    reqTwoPhaseIterator = reqScorer.asTwoPhaseIterator();
+    reqTwoPhaseIterator = reqScorer.twoPhaseIterator();
     if (reqTwoPhaseIterator == null) {
-      reqApproximation = reqScorer;
+      reqApproximation = reqScorer.iterator();
     } else {
       reqApproximation = reqTwoPhaseIterator.approximation();
     }
-    exclTwoPhaseIterator = exclScorer.asTwoPhaseIterator();
+    exclTwoPhaseIterator = exclScorer.twoPhaseIterator();
     if (exclTwoPhaseIterator == null) {
-      exclApproximation = exclScorer;
+      exclApproximation = exclScorer.iterator();
     } else {
       exclApproximation = exclTwoPhaseIterator.approximation();
     }
   }
 
-  @Override
-  public int nextDoc() throws IOException {
-    return toNonExcluded(reqApproximation.nextDoc());
-  }
-
   /** Confirms whether or not the given {@link TwoPhaseIterator}
    *  matches on the current document. */
   private static boolean matches(TwoPhaseIterator it) throws IOException {
@@ -85,25 +77,52 @@ class ReqExclScorer extends Scorer {
     return matches(reqTwoPhaseIterator);
   }
 
-  /** Advance to the next non-excluded doc. */
-  private int toNonExcluded(int doc) throws IOException {
-    int exclDoc = exclApproximation.docID();
-    for (;; doc = reqApproximation.nextDoc()) {
-      if (doc == NO_MORE_DOCS) {
-        return NO_MORE_DOCS;
+  @Override
+  public DocIdSetIterator iterator() {
+    return new DocIdSetIterator() {
+
+      /** Advance to the next non-excluded doc. */
+      private int toNonExcluded(int doc) throws IOException {
+        int exclDoc = exclApproximation.docID();
+        for (;; doc = reqApproximation.nextDoc()) {
+          if (doc == NO_MORE_DOCS) {
+            return NO_MORE_DOCS;
+          }
+          if (exclDoc < doc) {
+            exclDoc = exclApproximation.advance(doc);
+          }
+          if (matches(doc, exclDoc, reqTwoPhaseIterator, exclTwoPhaseIterator)) {
+            return doc;
+          }
+        }
       }
-      if (exclDoc < doc) {
-        exclDoc = exclApproximation.advance(doc);
+
+      @Override
+      public int nextDoc() throws IOException {
+        return toNonExcluded(reqApproximation.nextDoc());
       }
-      if (matches(doc, exclDoc, reqTwoPhaseIterator, exclTwoPhaseIterator)) {
-        return doc;
+
+      @Override
+      public int advance(int target) throws IOException {
+        return toNonExcluded(reqApproximation.advance(target));
       }
-    }
+
+      @Override
+      public int docID() {
+        return reqApproximation.docID();
+      }
+
+      @Override
+      public long cost() {
+        return reqApproximation.cost();
+      }
+
+    };
   }
 
   @Override
   public int docID() {
-    return reqScorer.docID();
+    return reqApproximation.docID();
   }
 
   @Override
@@ -112,11 +131,6 @@ class ReqExclScorer extends Scorer {
   }
 
   @Override
-  public long cost() {
-    return reqScorer.cost();
-  }
-
-  @Override
   public float score() throws IOException {
     return reqScorer.score(); // reqScorer may be null when next() or skipTo() already return false
   }
@@ -127,12 +141,7 @@ class ReqExclScorer extends Scorer {
   }
 
   @Override
-  public int advance(int target) throws IOException {
-    return toNonExcluded(reqApproximation.advance(target));
-  }
-
-  @Override
-  public TwoPhaseIterator asTwoPhaseIterator() {
+  public TwoPhaseIterator twoPhaseIterator() {
     if (reqTwoPhaseIterator == null) {
       return null;
     }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/ReqOptSumScorer.java Thu Dec 10 17:45:29 2015
@@ -22,15 +22,14 @@ import java.util.Collection;
 
 /** A Scorer for queries with a required part and an optional part.
  * Delays skipTo() on the optional part until a score() is needed.
- * <br>
- * This <code>Scorer</code> implements {@link Scorer#advance(int)}.
  */
 class ReqOptSumScorer extends Scorer {
   /** The scorers passed from the constructor.
    * These are set to null as soon as their next() or skipTo() returns false.
    */
   protected final Scorer reqScorer;
-  protected Scorer optScorer;
+  protected final Scorer optScorer;
+  protected final DocIdSetIterator optIterator;
 
   /** Construct a <code>ReqOptScorer</code>.
    * @param reqScorer The required scorer. This must match.
@@ -45,30 +44,26 @@ class ReqOptSumScorer extends Scorer {
     assert optScorer != null;
     this.reqScorer = reqScorer;
     this.optScorer = optScorer;
+    this.optIterator = optScorer.iterator();
   }
 
   @Override
-  public TwoPhaseIterator asTwoPhaseIterator() {
-    return reqScorer.asTwoPhaseIterator();
+  public TwoPhaseIterator twoPhaseIterator() {
+    return reqScorer.twoPhaseIterator();
   }
 
   @Override
-  public int nextDoc() throws IOException {
-    return reqScorer.nextDoc();
+  public DocIdSetIterator iterator() {
+    return reqScorer.iterator();
   }
-  
-  @Override
-  public int advance(int target) throws IOException {
-    return reqScorer.advance(target);
-  }
-  
+
   @Override
   public int docID() {
     return reqScorer.docID();
   }
-  
+
   /** Returns the score of the current document matching the query.
-   * Initially invalid, until {@link #nextDoc()} is called the first time.
+   * Initially invalid, until the {@link #iterator()} is advanced the first time.
    * @return The score of the required scorer, eventually increased by the score
    * of the optional scorer when it also matches the current document.
    */
@@ -76,25 +71,25 @@ class ReqOptSumScorer extends Scorer {
   public float score() throws IOException {
     // TODO: sum into a double and cast to float if we ever send required clauses to BS1
     int curDoc = reqScorer.docID();
-    float reqScore = reqScorer.score();
-    if (optScorer == null) {
-      return reqScore;
+    float score = reqScorer.score();
+
+    int optScorerDoc = optIterator.docID();
+    if (optScorerDoc < curDoc) {
+      optScorerDoc = optIterator.advance(curDoc);
     }
     
-    int optScorerDoc = optScorer.docID();
-    if (optScorerDoc < curDoc && (optScorerDoc = optScorer.advance(curDoc)) == NO_MORE_DOCS) {
-      optScorer = null;
-      return reqScore;
+    if (optScorerDoc == curDoc) {
+      score += optScorer.score();
     }
     
-    return optScorerDoc == curDoc ? reqScore + optScorer.score() : reqScore;
+    return score;
   }
 
   @Override
   public int freq() throws IOException {
     // we might have deferred advance()
     score();
-    return (optScorer != null && optScorer.docID() == reqScorer.docID()) ? 2 : 1;
+    return optIterator.docID() == reqScorer.docID() ? 2 : 1;
   }
 
   @Override
@@ -105,9 +100,5 @@ class ReqOptSumScorer extends Scorer {
     return children;
   }
 
-  @Override
-  public long cost() {
-    return reqScorer.cost();
-  }
 }
 

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Scorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Scorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Scorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/Scorer.java Thu Dec 10 17:45:29 2015
@@ -25,8 +25,8 @@ import java.util.Collections;
  * Expert: Common scoring functionality for different types of queries.
  *
  * <p>
- * A <code>Scorer</code> iterates over documents matching a
- * query in increasing order of doc Id.
+ * A <code>Scorer</code> exposes an {@link #iterator()} over documents
+ * matching a query in increasing order of doc Id.
  * </p>
  * <p>
  * Document scores are computed using a given <code>Similarity</code>
@@ -39,7 +39,7 @@ import java.util.Collections;
  * TopScoreDocCollector}) will not properly collect hits
  * with these scores.
  */
-public abstract class Scorer extends DocIdSetIterator {
+public abstract class Scorer {
   /** the Scorer's parent Weight. in some cases this may be null */
   // TODO can we clean this up?
   protected final Weight weight;
@@ -52,10 +52,18 @@ public abstract class Scorer extends Doc
     this.weight = weight;
   }
 
+  /**
+   * Returns the doc ID that is currently being scored.
+   * This will return {@code -1} if the {@link #iterator()} is not positioned
+   * or {@link DocIdSetIterator#NO_MORE_DOCS} if it has been entirely consumed.
+   * @see DocIdSetIterator#docID()
+   */
+  public abstract int docID();
+
   /** Returns the score of the current document matching the query.
-   * Initially invalid, until {@link #nextDoc()} or {@link #advance(int)}
-   * is called the first time, or when called from within
-   * {@link LeafCollector#collect}.
+   * Initially invalid, until {@link DocIdSetIterator#nextDoc()} or
+   * {@link DocIdSetIterator#advance(int)} is called on the {@link #iterator()}
+   * the first time, or when called from within {@link LeafCollector#collect}.
    */
   public abstract float score() throws IOException;
 
@@ -102,21 +110,34 @@ public abstract class Scorer extends Doc
   }
 
   /**
+   * Return a {@link DocIdSetIterator} over matching documents.
+   *
+   * The returned iterator will either be positioned on {@code -1} if no
+   * documents have been scored yet, {@link DocIdSetIterator#NO_MORE_DOCS}
+   * if all documents have been scored already, or the last document id that
+   * has been scored otherwise.
+   *
+   * The returned iterator is a view: calling this method several times will
+   * return iterators that have the same state.
+   */
+  public abstract DocIdSetIterator iterator();
+
+  /**
    * 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.
    *
    * Note that the returned {@link TwoPhaseIterator}'s
    * {@link TwoPhaseIterator#approximation() approximation} must
-   * advance synchronously with this iterator: advancing the approximation must
-   * advance this iterator and vice-versa.
+   * advance synchronously with the {@link #iterator()}: advancing the
+   * approximation must advance the iterator and vice-versa.
    *
    * Implementing this method is typically useful on {@link Scorer}s
    * that have a high per-document overhead in order to confirm matches.
    *
    * The default implementation returns {@code null}.
    */
-  public TwoPhaseIterator asTwoPhaseIterator() {
+  public TwoPhaseIterator twoPhaseIterator() {
     return null;
   }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/SloppyPhraseScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/SloppyPhraseScorer.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/SloppyPhraseScorer.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/SloppyPhraseScorer.java Thu Dec 10 17:45:29 2015
@@ -69,7 +69,7 @@ final class SloppyPhraseScorer extends S
       iterators[i] = postings[i].postings;
       phrasePositions[i] = new PhrasePositions(postings[i].postings, postings[i].position, i, postings[i].terms);
     }
-    conjunction = ConjunctionDISI.intersect(Arrays.asList(iterators));
+    conjunction = ConjunctionDISI.intersectIterators(Arrays.asList(iterators));
     this.matchCost = matchCost;
   }
 
@@ -550,19 +550,6 @@ final class SloppyPhraseScorer extends S
   public int docID() {
     return conjunction.docID(); 
   }
-
-  @Override
-  public int nextDoc() throws IOException {
-    int doc;
-    for (doc = conjunction.nextDoc(); doc != NO_MORE_DOCS; doc = conjunction.nextDoc()) {
-      sloppyFreq = phraseFreq(); // check for phrase
-      if (sloppyFreq != 0f) {
-        break;
-      }
-    }
-
-    return doc;
-  }
   
   @Override
   public float score() {
@@ -570,29 +557,10 @@ final class SloppyPhraseScorer extends S
   }
 
   @Override
-  public int advance(int target) throws IOException {
-    assert target > docID();
-    int doc;
-    for (doc = conjunction.advance(target); doc != NO_MORE_DOCS; doc = conjunction.nextDoc()) {
-      sloppyFreq = phraseFreq(); // check for phrase
-      if (sloppyFreq != 0f) {
-        break;
-      }
-    }
-
-    return doc;
-  }
-
-  @Override
-  public long cost() {
-    return conjunction.cost();
-  }
-
-  @Override
   public String toString() { return "scorer(" + weight + ")"; }
 
   @Override
-  public TwoPhaseIterator asTwoPhaseIterator() {
+  public TwoPhaseIterator twoPhaseIterator() {
     return new TwoPhaseIterator(conjunction) {
       @Override
       public boolean matches() throws IOException {
@@ -611,4 +579,9 @@ final class SloppyPhraseScorer extends S
       }
     };
   }
+
+  @Override
+  public DocIdSetIterator iterator() {
+    return TwoPhaseIterator.asDocIdSetIterator(twoPhaseIterator());
+  }
 }

Modified: lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java?rev=1719124&r1=1719123&r2=1719124&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/java/org/apache/lucene/search/TermQuery.java Thu Dec 10 17:45:29 2015
@@ -137,7 +137,7 @@ public class TermQuery extends Query {
     public Explanation explain(LeafReaderContext context, int doc) throws IOException {
       Scorer scorer = scorer(context);
       if (scorer != null) {
-        int newDoc = scorer.advance(doc);
+        int newDoc = scorer.iterator().advance(doc);
         if (newDoc == doc) {
           float freq = scorer.freq();
           SimScorer docScorer = similarity.simScorer(stats, context);