lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject svn commit: r1649824 [3/4] - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/core/ lucene/core/src/java/org/apache/lucene/search/ lucene/core/src/test/org/apache/lucene/search/ lucene/expressions/ lucene/expressions/src/java/org/apache/lucene/expr...
Date Tue, 06 Jan 2015 15:15:43 GMT
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=1649824&r1=1649823&r2=1649824&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 Tue Jan  6 15:15:42 2015
@@ -171,14 +171,14 @@ public class TestTopFieldCollector exten
         new boolean[] { true, true, true },
     };
     String[] actualTFCClasses = new String[] {
-        "OutOfOrderOneComparatorNonScoringCollector", 
-        "OutOfOrderOneComparatorScoringMaxScoreCollector", 
-        "OutOfOrderOneComparatorScoringNoMaxScoreCollector", 
-        "OutOfOrderOneComparatorScoringMaxScoreCollector", 
-        "OutOfOrderOneComparatorNonScoringCollector", 
-        "OutOfOrderOneComparatorScoringMaxScoreCollector", 
-        "OutOfOrderOneComparatorScoringNoMaxScoreCollector", 
-        "OutOfOrderOneComparatorScoringMaxScoreCollector" 
+        "OutOfOrderNonScoringCollector", 
+        "OutOfOrderScoringMaxScoreCollector", 
+        "OutOfOrderScoringNoMaxScoreCollector", 
+        "OutOfOrderScoringMaxScoreCollector", 
+        "OutOfOrderNonScoringCollector", 
+        "OutOfOrderScoringMaxScoreCollector", 
+        "OutOfOrderScoringNoMaxScoreCollector", 
+        "OutOfOrderScoringMaxScoreCollector" 
     };
     
     BooleanQuery bq = new BooleanQuery();
@@ -220,14 +220,14 @@ public class TestTopFieldCollector exten
         new boolean[] { true, true, true },
     };
     String[] actualTFCClasses = new String[] {
-        "OutOfOrderMultiComparatorNonScoringCollector", 
-        "OutOfOrderMultiComparatorScoringMaxScoreCollector", 
-        "OutOfOrderMultiComparatorScoringNoMaxScoreCollector", 
-        "OutOfOrderMultiComparatorScoringMaxScoreCollector", 
-        "OutOfOrderMultiComparatorNonScoringCollector", 
-        "OutOfOrderMultiComparatorScoringMaxScoreCollector", 
-        "OutOfOrderMultiComparatorScoringNoMaxScoreCollector", 
-        "OutOfOrderMultiComparatorScoringMaxScoreCollector" 
+        "OutOfOrderNonScoringCollector", 
+        "OutOfOrderScoringMaxScoreCollector", 
+        "OutOfOrderScoringNoMaxScoreCollector", 
+        "OutOfOrderScoringMaxScoreCollector", 
+        "OutOfOrderNonScoringCollector", 
+        "OutOfOrderScoringMaxScoreCollector", 
+        "OutOfOrderScoringNoMaxScoreCollector", 
+        "OutOfOrderScoringMaxScoreCollector" 
     };
     
     BooleanQuery bq = new BooleanQuery();

Modified: lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/core/src/test/org/apache/lucene/search/TestTopScoreDocCollector.java Tue Jan  6 15:15:42 2015
@@ -34,10 +34,6 @@ public class TestTopScoreDocCollector ex
     }
     
     boolean[] inOrder = new boolean[] { false, true };
-    String[] actualTSDCClass = new String[] {
-        "OutOfOrderTopScoreDocCollector", 
-        "InOrderTopScoreDocCollector" 
-    };
     
     BooleanQuery bq = new BooleanQuery();
     // Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2
@@ -50,7 +46,8 @@ public class TestTopScoreDocCollector ex
     IndexSearcher searcher = newSearcher(reader);
     for (int i = 0; i < inOrder.length; i++) {
       TopDocsCollector<ScoreDoc> tdc = TopScoreDocCollector.create(3, inOrder[i]);
-      assertEquals("org.apache.lucene.search.TopScoreDocCollector$" + actualTSDCClass[i], tdc.getClass().getName());
+      LeafCollector leafCollector = tdc.getLeafCollector(reader.leaves().get(0));
+      assertEquals(!inOrder[i], leafCollector.acceptsDocsOutOfOrder());
       
       searcher.search(new MatchAllDocsQuery(), tdc);
       

Modified: lucene/dev/branches/branch_5x/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionComparator.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionComparator.java (original)
+++ lucene/dev/branches/branch_5x/lucene/expressions/src/java/org/apache/lucene/expressions/ExpressionComparator.java Tue Jan  6 15:15:42 2015
@@ -24,10 +24,11 @@ import org.apache.lucene.index.LeafReade
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.LeafFieldComparator;
 import org.apache.lucene.search.Scorer;
 
 /** A custom comparator for sorting documents by an expression */
-class ExpressionComparator extends FieldComparator<Double> {
+class ExpressionComparator extends FieldComparator<Double> implements LeafFieldComparator {
   private final double[] values;
   private double bottom;
   private double topValue;
@@ -44,7 +45,6 @@ class ExpressionComparator extends Field
   // TODO: change FieldComparator.setScorer to throw IOException and remove this try-catch
   @Override
   public void setScorer(Scorer scorer) {
-    super.setScorer(scorer);
     // TODO: might be cleaner to lazy-init 'source' and set scorer after?
     assert readerContext != null;
     try {
@@ -83,7 +83,7 @@ class ExpressionComparator extends Field
   }
   
   @Override
-  public FieldComparator<Double> setNextReader(LeafReaderContext context) throws IOException {
+  public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
     this.readerContext = context;
     return this;
   }

Modified: lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractFirstPassGroupingCollector.java Tue Jan  6 15:15:42 2015
@@ -37,6 +37,7 @@ abstract public class AbstractFirstPassG
 
   private final Sort groupSort;
   private final FieldComparator<?>[] comparators;
+  private final LeafFieldComparator[] leafComparators;
   private final int[] reversed;
   private final int topNGroups;
   private final HashMap<GROUP_VALUE_TYPE, CollectedSearchGroup<GROUP_VALUE_TYPE>> groupMap;
@@ -60,7 +61,6 @@ abstract public class AbstractFirstPassG
    *  @param topNGroups How many top groups to keep.
    *  @throws IOException If I/O related errors occur
    */
-  @SuppressWarnings({"unchecked","rawtypes"})
   public AbstractFirstPassGroupingCollector(Sort groupSort, int topNGroups) throws IOException {
     if (topNGroups < 1) {
       throw new IllegalArgumentException("topNGroups must be >= 1 (got " + topNGroups + ")");
@@ -74,6 +74,7 @@ abstract public class AbstractFirstPassG
 
     final SortField[] sortFields = groupSort.getSort();
     comparators = new FieldComparator[sortFields.length];
+    leafComparators = new LeafFieldComparator[sortFields.length];
     compIDXEnd = comparators.length - 1;
     reversed = new int[sortFields.length];
     for (int i = 0; i < sortFields.length; i++) {
@@ -137,7 +138,7 @@ abstract public class AbstractFirstPassG
 
   @Override
   public void setScorer(Scorer scorer) throws IOException {
-    for (FieldComparator<?> comparator : comparators) {
+    for (LeafFieldComparator comparator : leafComparators) {
       comparator.setScorer(scorer);
     }
   }
@@ -157,7 +158,7 @@ abstract public class AbstractFirstPassG
     // wasted effort as we will most likely be updating an existing group.
     if (orderedGroups != null) {
       for (int compIDX = 0;; compIDX++) {
-        final int c = reversed[compIDX] * comparators[compIDX].compareBottom(doc);
+        final int c = reversed[compIDX] * leafComparators[compIDX].compareBottom(doc);
         if (c < 0) {
           // Definitely not competitive. So don't even bother to continue
           return;
@@ -197,7 +198,7 @@ abstract public class AbstractFirstPassG
         sg.groupValue = copyDocGroupValue(groupValue, null);
         sg.comparatorSlot = groupMap.size();
         sg.topDoc = docBase + doc;
-        for (FieldComparator<?> fc : comparators) {
+        for (LeafFieldComparator fc : leafComparators) {
           fc.copy(sg.comparatorSlot, doc);
         }
         groupMap.put(sg.groupValue, sg);
@@ -223,7 +224,7 @@ abstract public class AbstractFirstPassG
       bottomGroup.groupValue = copyDocGroupValue(groupValue, bottomGroup.groupValue);
       bottomGroup.topDoc = docBase + doc;
 
-      for (FieldComparator<?> fc : comparators) {
+      for (LeafFieldComparator fc : leafComparators) {
         fc.copy(bottomGroup.comparatorSlot, doc);
       }
 
@@ -232,7 +233,7 @@ abstract public class AbstractFirstPassG
       assert orderedGroups.size() == topNGroups;
 
       final int lastComparatorSlot = orderedGroups.last().comparatorSlot;
-      for (FieldComparator<?> fc : comparators) {
+      for (LeafFieldComparator fc : leafComparators) {
         fc.setBottom(lastComparatorSlot);
       }
 
@@ -241,17 +242,16 @@ abstract public class AbstractFirstPassG
 
     // Update existing group:
     for (int compIDX = 0;; compIDX++) {
-      final FieldComparator<?> fc = comparators[compIDX];
-      fc.copy(spareSlot, doc);
+      leafComparators[compIDX].copy(spareSlot, doc);
 
-      final int c = reversed[compIDX] * fc.compare(group.comparatorSlot, spareSlot);
+      final int c = reversed[compIDX] * comparators[compIDX].compare(group.comparatorSlot, spareSlot);
       if (c < 0) {
         // Definitely not competitive.
         return;
       } else if (c > 0) {
         // Definitely competitive; set remaining comparators:
         for (int compIDX2=compIDX+1; compIDX2<comparators.length; compIDX2++) {
-          comparators[compIDX2].copy(spareSlot, doc);
+          leafComparators[compIDX2].copy(spareSlot, doc);
         }
         break;
       } else if (compIDX == compIDXEnd) {
@@ -288,7 +288,7 @@ abstract public class AbstractFirstPassG
       final CollectedSearchGroup<?> newLast = orderedGroups.last();
       // If we changed the value of the last group, or changed which group was last, then update bottom:
       if (group == newLast || prevLast != newLast) {
-        for (FieldComparator<?> fc : comparators) {
+        for (LeafFieldComparator fc : leafComparators) {
           fc.setBottom(newLast.comparatorSlot);
         }
       }
@@ -315,7 +315,7 @@ abstract public class AbstractFirstPassG
     orderedGroups.addAll(groupMap.values());
     assert orderedGroups.size() > 0;
 
-    for (FieldComparator<?> fc : comparators) {
+    for (LeafFieldComparator fc : leafComparators) {
       fc.setBottom(orderedGroups.last().comparatorSlot);
     }
   }
@@ -329,7 +329,7 @@ abstract public class AbstractFirstPassG
   protected void doSetNextReader(LeafReaderContext readerContext) throws IOException {
     docBase = readerContext.docBase;
     for (int i=0; i<comparators.length; i++) {
-      comparators[i] = comparators[i].setNextReader(readerContext);
+      leafComparators[i] = comparators[i].getLeafComparator(readerContext);
     }
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractSecondPassGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractSecondPassGroupingCollector.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractSecondPassGroupingCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/AbstractSecondPassGroupingCollector.java Tue Jan  6 15:15:42 2015
@@ -83,7 +83,7 @@ public abstract class AbstractSecondPass
   @Override
   public void setScorer(Scorer scorer) throws IOException {
     for (SearchGroupDocs<GROUP_VALUE_TYPE> group : groupMap.values()) {
-      group.collector.setScorer(scorer);
+      group.leafCollector.setScorer(scorer);
     }
   }
 
@@ -93,7 +93,7 @@ public abstract class AbstractSecondPass
     SearchGroupDocs<GROUP_VALUE_TYPE> group = retrieveGroup(doc);
     if (group != null) {
       totalGroupedHitCount++;
-      group.collector.collect(doc);
+      group.leafCollector.collect(doc);
     }
   }
 
@@ -110,7 +110,7 @@ public abstract class AbstractSecondPass
   protected void doSetNextReader(LeafReaderContext readerContext) throws IOException {
     //System.out.println("SP.setNextReader");
     for (SearchGroupDocs<GROUP_VALUE_TYPE> group : groupMap.values()) {
-      group.collector.getLeafCollector(readerContext);
+      group.leafCollector = group.collector.getLeafCollector(readerContext);
     }
   }
 
@@ -151,6 +151,7 @@ public abstract class AbstractSecondPass
 
     public final GROUP_VALUE_TYPE groupValue;
     public final TopDocsCollector<?> collector;
+    public LeafCollector leafCollector;
 
     public SearchGroupDocs(GROUP_VALUE_TYPE groupValue, TopDocsCollector<?> collector) {
       this.groupValue = groupValue;

Modified: lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java Tue Jan  6 15:15:42 2015
@@ -69,6 +69,7 @@ public class BlockGroupingCollector exte
   private final boolean needsScores;
 
   private final FieldComparator<?>[] comparators;
+  private final LeafFieldComparator[] leafComparators;
   private final int[] reversed;
   private final int compIDXEnd;
   private int bottomSlot;
@@ -202,7 +203,7 @@ public class BlockGroupingCollector exte
           bottomSlot = bottomGroup.comparatorSlot;
           //System.out.println("    set bottom=" + bottomSlot);
           for (int i = 0; i < comparators.length; i++) {
-            comparators[i].setBottom(bottomSlot);
+            leafComparators[i].setBottom(bottomSlot);
           }
           //System.out.println("     QUEUE FULL");
         } else {
@@ -231,7 +232,7 @@ public class BlockGroupingCollector exte
 
         //System.out.println("    set bottom=" + bottomSlot);
         for (int i = 0; i < comparators.length; i++) {
-          comparators[i].setBottom(bottomSlot);
+          leafComparators[i].setBottom(bottomSlot);
         }
       }
     }
@@ -278,6 +279,7 @@ public class BlockGroupingCollector exte
 
     final SortField[] sortFields = groupSort.getSort();
     comparators = new FieldComparator<?>[sortFields.length];
+    leafComparators = new LeafFieldComparator[sortFields.length];
     compIDXEnd = comparators.length - 1;
     reversed = new int[sortFields.length];
     for (int i = 0; i < sortFields.length; i++) {
@@ -349,15 +351,15 @@ public class BlockGroupingCollector exte
         collector = TopFieldCollector.create(withinGroupSort, maxDocsPerGroup, fillSortFields, needsScores, needsScores, true);
       }
 
-      collector.setScorer(fakeScorer);
-      collector.getLeafCollector(og.readerContext);
+      LeafCollector leafCollector = collector.getLeafCollector(og.readerContext);
+      leafCollector.setScorer(fakeScorer);
       for(int docIDX=0;docIDX<og.count;docIDX++) {
         final int doc = og.docs[docIDX];
         fakeScorer.doc = doc;
         if (needsScores) {
           fakeScorer.score = og.scores[docIDX];
         }
-        collector.collect(doc);
+        leafCollector.collect(doc);
       }
       totalGroupedHitCount += og.count;
 
@@ -402,7 +404,7 @@ public class BlockGroupingCollector exte
   @Override
   public void setScorer(Scorer scorer) throws IOException {
     this.scorer = scorer;
-    for (FieldComparator<?> comparator : comparators) {
+    for (LeafFieldComparator comparator : leafComparators) {
       comparator.setScorer(scorer);
     }
   }
@@ -443,7 +445,7 @@ public class BlockGroupingCollector exte
         assert !queueFull;
 
         //System.out.println("    init copy to bottomSlot=" + bottomSlot);
-        for (FieldComparator<?> fc : comparators) {
+        for (LeafFieldComparator fc : leafComparators) {
           fc.copy(bottomSlot, doc);
           fc.setBottom(bottomSlot);
         }        
@@ -451,7 +453,7 @@ public class BlockGroupingCollector exte
       } else {
         // Compare to bottomSlot
         for (int compIDX = 0;; compIDX++) {
-          final int c = reversed[compIDX] * comparators[compIDX].compareBottom(doc);
+          final int c = reversed[compIDX] * leafComparators[compIDX].compareBottom(doc);
           if (c < 0) {
             // Definitely not competitive -- done
             return;
@@ -468,7 +470,7 @@ public class BlockGroupingCollector exte
 
         //System.out.println("       best w/in group!");
         
-        for (FieldComparator<?> fc : comparators) {
+        for (LeafFieldComparator fc : leafComparators) {
           fc.copy(bottomSlot, doc);
           // Necessary because some comparators cache
           // details of bottom slot; this forces them to
@@ -481,7 +483,7 @@ public class BlockGroupingCollector exte
       // We're not sure this group will make it into the
       // queue yet
       for (int compIDX = 0;; compIDX++) {
-        final int c = reversed[compIDX] * comparators[compIDX].compareBottom(doc);
+        final int c = reversed[compIDX] * leafComparators[compIDX].compareBottom(doc);
         if (c < 0) {
           // Definitely not competitive -- done
           //System.out.println("    doc doesn't compete w/ top groups");
@@ -498,7 +500,7 @@ public class BlockGroupingCollector exte
         }
       }
       groupCompetes = true;
-      for (FieldComparator<?> fc : comparators) {
+      for (LeafFieldComparator fc : leafComparators) {
         fc.copy(bottomSlot, doc);
         // Necessary because some comparators cache
         // details of bottom slot; this forces them to
@@ -528,7 +530,7 @@ public class BlockGroupingCollector exte
 
     currentReaderContext = readerContext;
     for (int i=0; i<comparators.length; i++) {
-      comparators[i] = comparators[i].setNextReader(readerContext);
+      leafComparators[i] = comparators[i].getLeafComparator(readerContext);
     }
   }
 }

Modified: lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java (original)
+++ lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java Tue Jan  6 15:15:42 2015
@@ -18,6 +18,7 @@ package org.apache.lucene.search.groupin
  */
 
 import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.LeafFieldComparator;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
 
@@ -158,7 +159,7 @@ public class SearchGroup<GROUP_VALUE_TYP
 
     public GroupComparator(Sort groupSort) throws IOException {
       final SortField[] sortFields = groupSort.getSort();
-      comparators = new FieldComparator<?>[sortFields.length];
+      comparators = new FieldComparator[sortFields.length];
       reversed = new int[sortFields.length];
       for (int compIDX = 0; compIDX < sortFields.length; compIDX++) {
         final SortField sortField = sortFields[compIDX];

Modified: lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/function/FunctionAllGroupHeadsCollector.java Tue Jan  6 15:15:42 2015
@@ -21,6 +21,7 @@ import org.apache.lucene.index.LeafReade
 import org.apache.lucene.queries.function.FunctionValues;
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.LeafFieldComparator;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
@@ -94,7 +95,7 @@ public class FunctionAllGroupHeadsCollec
   public void setScorer(Scorer scorer) throws IOException {
     this.scorer = scorer;
     for (GroupHead groupHead : groups.values()) {
-      for (FieldComparator<?> comparator : groupHead.comparators) {
+      for (LeafFieldComparator comparator : groupHead.leafComparators) {
         comparator.setScorer(scorer);
       }
     }
@@ -109,7 +110,7 @@ public class FunctionAllGroupHeadsCollec
 
     for (GroupHead groupHead : groups.values()) {
       for (int i = 0; i < groupHead.comparators.length; i++) {
-        groupHead.comparators[i] = groupHead.comparators[i].setNextReader(context);
+        groupHead.leafComparators[i] = groupHead.comparators[i].getLeafComparator(context);
       }
     }
   }
@@ -120,28 +121,31 @@ public class FunctionAllGroupHeadsCollec
   public class GroupHead extends AbstractAllGroupHeadsCollector.GroupHead<MutableValue> {
 
     final FieldComparator<?>[] comparators;
+    final LeafFieldComparator[] leafComparators;
 
     @SuppressWarnings({"unchecked","rawtypes"})
     private GroupHead(MutableValue groupValue, Sort sort, int doc) throws IOException {
       super(groupValue, doc + readerContext.docBase);
       final SortField[] sortFields = sort.getSort();
       comparators = new FieldComparator[sortFields.length];
+      leafComparators = new LeafFieldComparator[sortFields.length];
       for (int i = 0; i < sortFields.length; i++) {
-        comparators[i] = sortFields[i].getComparator(1, i).setNextReader(readerContext);
-        comparators[i].setScorer(scorer);
-        comparators[i].copy(0, doc);
-        comparators[i].setBottom(0);
+        comparators[i] = sortFields[i].getComparator(1, i);
+        leafComparators[i] = comparators[i].getLeafComparator(readerContext);
+        leafComparators[i].setScorer(scorer);
+        leafComparators[i].copy(0, doc);
+        leafComparators[i].setBottom(0);
       }
     }
 
     @Override
     public int compare(int compIDX, int doc) throws IOException {
-      return comparators[compIDX].compareBottom(doc);
+      return leafComparators[compIDX].compareBottom(doc);
     }
 
     @Override
     public void updateDocHead(int doc) throws IOException {
-      for (FieldComparator<?> comparator : comparators) {
+      for (LeafFieldComparator comparator : leafComparators) {
         comparator.copy(0, doc);
         comparator.setBottom(0);
       }

Modified: lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermAllGroupHeadsCollector.java Tue Jan  6 15:15:42 2015
@@ -21,6 +21,7 @@ import org.apache.lucene.index.LeafReade
 import org.apache.lucene.index.DocValues;
 import org.apache.lucene.index.SortedDocValues;
 import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.LeafFieldComparator;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
@@ -164,7 +165,7 @@ public abstract class TermAllGroupHeadsC
 
       for (GroupHead groupHead : groups.values()) {
         for (int i = 0; i < groupHead.comparators.length; i++) {
-          groupHead.comparators[i] = groupHead.comparators[i].setNextReader(context);
+          groupHead.leafComparators[i] = groupHead.comparators[i].getLeafComparator(context);
         }
       }
     }
@@ -173,7 +174,7 @@ public abstract class TermAllGroupHeadsC
     public void setScorer(Scorer scorer) throws IOException {
       this.scorer = scorer;
       for (GroupHead groupHead : groups.values()) {
-        for (FieldComparator<?> comparator : groupHead.comparators) {
+        for (LeafFieldComparator comparator : groupHead.leafComparators) {
           comparator.setScorer(scorer);
         }
       }
@@ -181,28 +182,31 @@ public abstract class TermAllGroupHeadsC
 
     class GroupHead extends AbstractAllGroupHeadsCollector.GroupHead<BytesRef> {
 
-      final FieldComparator<?>[] comparators;
+      final FieldComparator[] comparators;
+      final LeafFieldComparator[] leafComparators;
 
       private GroupHead(BytesRef groupValue, Sort sort, int doc) throws IOException {
         super(groupValue, doc + readerContext.docBase);
         final SortField[] sortFields = sort.getSort();
         comparators = new FieldComparator[sortFields.length];
+        leafComparators = new LeafFieldComparator[sortFields.length];
         for (int i = 0; i < sortFields.length; i++) {
-          comparators[i] = sortFields[i].getComparator(1, i).setNextReader(readerContext);
-          comparators[i].setScorer(scorer);
-          comparators[i].copy(0, doc);
-          comparators[i].setBottom(0);
+          comparators[i] = sortFields[i].getComparator(1, i);
+          leafComparators[i] = comparators[i].getLeafComparator(readerContext);
+          leafComparators[i].setScorer(scorer);
+          leafComparators[i].copy(0, doc);
+          leafComparators[i].setBottom(0);
         }
       }
 
       @Override
       public int compare(int compIDX, int doc) throws IOException {
-        return comparators[compIDX].compareBottom(doc);
+        return leafComparators[compIDX].compareBottom(doc);
       }
 
       @Override
       public void updateDocHead(int doc) throws IOException {
-        for (FieldComparator<?> comparator : comparators) {
+        for (LeafFieldComparator comparator : leafComparators) {
           comparator.copy(0, doc);
           comparator.setBottom(0);
         }

Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinCollector.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinCollector.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinCollector.java Tue Jan  6 15:15:42 2015
@@ -74,7 +74,7 @@ import java.util.*;
  *
  * @lucene.experimental
  */
-public class ToParentBlockJoinCollector extends SimpleCollector {
+public class ToParentBlockJoinCollector implements Collector {
 
   private final Sort sort;
 
@@ -83,16 +83,11 @@ public class ToParentBlockJoinCollector
   private final Map<Query,Integer> joinQueryID = new HashMap<>();
   private final int numParentHits;
   private final FieldValueHitQueue<OneGroup> queue;
-  private final FieldComparator[] comparators;
-  private final int[] reverseMul;
-  private final int compEnd;
+  private final FieldComparator<?>[] comparators;
   private final boolean trackMaxScore;
   private final boolean trackScores;
 
-  private int docBase;
   private ToParentBlockJoinQuery.BlockJoinScorer[] joinScorers = new ToParentBlockJoinQuery.BlockJoinScorer[0];
-  private LeafReaderContext currentReaderContext;
-  private Scorer scorer;
   private boolean queueFull;
 
   private OneGroup bottom;
@@ -116,8 +111,6 @@ public class ToParentBlockJoinCollector
     this.numParentHits = numParentHits;
     queue = FieldValueHitQueue.create(sort.getSort(), numParentHits);
     comparators = queue.getComparators();
-    reverseMul = queue.getReverseMul();
-    compEnd = comparators.length - 1;
   }
   
   private static final class OneGroup extends FieldValueHitQueue.Entry {
@@ -143,143 +136,172 @@ public class ToParentBlockJoinCollector
   }
 
   @Override
-  public void collect(int parentDoc) throws IOException {
-    //System.out.println("\nC parentDoc=" + parentDoc);
-    totalHitCount++;
-
-    float score = Float.NaN;
+  public LeafCollector getLeafCollector(final LeafReaderContext context)
+      throws IOException {
+    final LeafFieldComparator[] comparators = queue.getComparators(context);
+    final int[] reverseMul = queue.getReverseMul();
+    final int docBase = context.docBase;
+    return new LeafCollector() {
+
+      private Scorer scorer;
+
+      @Override
+      public void setScorer(Scorer scorer) throws IOException {
+        //System.out.println("C.setScorer scorer=" + scorer);
+        // Since we invoke .score(), and the comparators likely
+        // do as well, cache it so it's only "really" computed
+        // once:
+        if (scorer instanceof ScoreCachingWrappingScorer == false) {
+          scorer = new ScoreCachingWrappingScorer(scorer);
+        }
+        this.scorer = scorer;
+        for (LeafFieldComparator comparator : comparators) {
+          comparator.setScorer(scorer);
+        }
+        Arrays.fill(joinScorers, null);
 
-    if (trackMaxScore) {
-      score = scorer.score();
-      maxScore = Math.max(maxScore, score);
-    }
+        Queue<Scorer> queue = new LinkedList<>();
+        //System.out.println("\nqueue: add top scorer=" + scorer);
+        queue.add(scorer);
+        while ((scorer = queue.poll()) != null) {
+          //System.out.println("  poll: " + scorer + "; " + scorer.getWeight().getQuery());
+          if (scorer instanceof ToParentBlockJoinQuery.BlockJoinScorer) {
+            enroll((ToParentBlockJoinQuery) scorer.getWeight().getQuery(), (ToParentBlockJoinQuery.BlockJoinScorer) scorer);
+          }
 
-    // TODO: we could sweep all joinScorers here and
-    // aggregate total child hit count, so we can fill this
-    // in getTopGroups (we wire it to 0 now)
-
-    if (queueFull) {
-      //System.out.println("  queueFull");
-      // Fastmatch: return if this hit is not competitive
-      for (int i = 0;; i++) {
-        final int c = reverseMul[i] * comparators[i].compareBottom(parentDoc);
-        if (c < 0) {
-          // Definitely not competitive.
-          //System.out.println("    skip");
-          return;
-        } else if (c > 0) {
-          // Definitely competitive.
-          break;
-        } else if (i == compEnd) {
-          // Here c=0. If we're at the last comparator, this doc is not
-          // competitive, since docs are visited in doc Id order, which means
-          // this doc cannot compete with any other document in the queue.
-          //System.out.println("    skip");
-          return;
+          for (ChildScorer sub : scorer.getChildren()) {
+            //System.out.println("  add sub: " + sub.child + "; " + sub.child.getWeight().getQuery());
+            queue.add(sub.child);
+          }
         }
       }
+      
+      @Override
+      public void collect(int parentDoc) throws IOException {
+      //System.out.println("\nC parentDoc=" + parentDoc);
+        totalHitCount++;
+
+        float score = Float.NaN;
+
+        if (trackMaxScore) {
+          score = scorer.score();
+          maxScore = Math.max(maxScore, score);
+        }
 
-      //System.out.println("    competes!  doc=" + (docBase + parentDoc));
+        // TODO: we could sweep all joinScorers here and
+        // aggregate total child hit count, so we can fill this
+        // in getTopGroups (we wire it to 0 now)
+
+        if (queueFull) {
+          //System.out.println("  queueFull");
+          // Fastmatch: return if this hit is not competitive
+          int c = 0;
+          for (int i = 0; i < comparators.length; ++i) {
+            c = reverseMul[i] * comparators[i].compareBottom(parentDoc);
+            if (c != 0) {
+              break;
+            }
+          }
+          if (c <= 0) { // in case of equality, this hit is not competitive as docs are visited in order
+            // Definitely not competitive.
+            //System.out.println("    skip");
+            return;
+          }
 
-      // This hit is competitive - replace bottom element in queue & adjustTop
-      for (int i = 0; i < comparators.length; i++) {
-        comparators[i].copy(bottom.slot, parentDoc);
-      }
-      if (!trackMaxScore && trackScores) {
-        score = scorer.score();
-      }
-      bottom.doc = docBase + parentDoc;
-      bottom.readerContext = currentReaderContext;
-      bottom.score = score;
-      copyGroups(bottom);
-      bottom = queue.updateTop();
+          //System.out.println("    competes!  doc=" + (docBase + parentDoc));
 
-      for (int i = 0; i < comparators.length; i++) {
-        comparators[i].setBottom(bottom.slot);
-      }
-    } else {
-      // Startup transient: queue is not yet full:
-      final int comparatorSlot = totalHitCount - 1;
+          // This hit is competitive - replace bottom element in queue & adjustTop
+          for (LeafFieldComparator comparator : comparators) {
+            comparator.copy(bottom.slot, parentDoc);
+          }
+          if (!trackMaxScore && trackScores) {
+            score = scorer.score();
+          }
+          bottom.doc = docBase + parentDoc;
+          bottom.readerContext = context;
+          bottom.score = score;
+          copyGroups(bottom);
+          bottom = queue.updateTop();
 
-      // Copy hit into queue
-      for (int i = 0; i < comparators.length; i++) {
-        comparators[i].copy(comparatorSlot, parentDoc);
-      }
-      //System.out.println("  startup: new OG doc=" + (docBase+parentDoc));
-      if (!trackMaxScore && trackScores) {
-        score = scorer.score();
-      }
-      final OneGroup og = new OneGroup(comparatorSlot, docBase+parentDoc, score, joinScorers.length, trackScores);
-      og.readerContext = currentReaderContext;
-      copyGroups(og);
-      bottom = queue.add(og);
-      queueFull = totalHitCount == numParentHits;
-      if (queueFull) {
-        // End of startup transient: queue just filled up:
-        for (int i = 0; i < comparators.length; i++) {
-          comparators[i].setBottom(bottom.slot);
+          for (LeafFieldComparator comparator : comparators) {
+            comparator.setBottom(bottom.slot);
+          }
+        } else {
+          // Startup transient: queue is not yet full:
+          final int comparatorSlot = totalHitCount - 1;
+
+          // Copy hit into queue
+          for (LeafFieldComparator comparator : comparators) {
+            comparator.copy(comparatorSlot, parentDoc);
+          }
+          //System.out.println("  startup: new OG doc=" + (docBase+parentDoc));
+          if (!trackMaxScore && trackScores) {
+            score = scorer.score();
+          }
+          final OneGroup og = new OneGroup(comparatorSlot, docBase+parentDoc, score, joinScorers.length, trackScores);
+          og.readerContext = context;
+          copyGroups(og);
+          bottom = queue.add(og);
+          queueFull = totalHitCount == numParentHits;
+          if (queueFull) {
+            // End of startup transient: queue just filled up:
+            for (LeafFieldComparator comparator : comparators) {
+              comparator.setBottom(bottom.slot);
+            }
+          }
         }
       }
-    }
-  }
-
-  // Pulls out child doc and scores for all join queries:
-  private void copyGroups(OneGroup og) {
-    // While rare, it's possible top arrays could be too
-    // short if join query had null scorer on first
-    // segment(s) but then became non-null on later segments
-    final int numSubScorers = joinScorers.length;
-    if (og.docs.length < numSubScorers) {
-      // While rare, this could happen if join query had
-      // null scorer on first segment(s) but then became
-      // non-null on later segments
-      og.docs = ArrayUtil.grow(og.docs);
-    }
-    if (og.counts.length < numSubScorers) {
-      og.counts = ArrayUtil.grow(og.counts);
-    }
-    if (trackScores && og.scores.length < numSubScorers) {
-      og.scores = ArrayUtil.grow(og.scores);
-    }
+      
+      // Pulls out child doc and scores for all join queries:
+      private void copyGroups(OneGroup og) {
+        // While rare, it's possible top arrays could be too
+        // short if join query had null scorer on first
+        // segment(s) but then became non-null on later segments
+        final int numSubScorers = joinScorers.length;
+        if (og.docs.length < numSubScorers) {
+          // While rare, this could happen if join query had
+          // null scorer on first segment(s) but then became
+          // non-null on later segments
+          og.docs = ArrayUtil.grow(og.docs);
+        }
+        if (og.counts.length < numSubScorers) {
+          og.counts = ArrayUtil.grow(og.counts);
+        }
+        if (trackScores && og.scores.length < numSubScorers) {
+          og.scores = ArrayUtil.grow(og.scores);
+        }
 
-    //System.out.println("\ncopyGroups parentDoc=" + og.doc);
-    for(int scorerIDX = 0;scorerIDX < numSubScorers;scorerIDX++) {
-      final ToParentBlockJoinQuery.BlockJoinScorer joinScorer = joinScorers[scorerIDX];
-      //System.out.println("  scorer=" + joinScorer);
-      if (joinScorer != null && docBase + joinScorer.getParentDoc() == og.doc) {
-        og.counts[scorerIDX] = joinScorer.getChildCount();
-        //System.out.println("    count=" + og.counts[scorerIDX]);
-        og.docs[scorerIDX] = joinScorer.swapChildDocs(og.docs[scorerIDX]);
-        assert og.docs[scorerIDX].length >= og.counts[scorerIDX]: "length=" + og.docs[scorerIDX].length + " vs count=" + og.counts[scorerIDX];
-        //System.out.println("    len=" + og.docs[scorerIDX].length);
-        /*
-          for(int idx=0;idx<og.counts[scorerIDX];idx++) {
-          System.out.println("    docs[" + idx + "]=" + og.docs[scorerIDX][idx]);
+        //System.out.println("\ncopyGroups parentDoc=" + og.doc);
+        for(int scorerIDX = 0;scorerIDX < numSubScorers;scorerIDX++) {
+          final ToParentBlockJoinQuery.BlockJoinScorer joinScorer = joinScorers[scorerIDX];
+          //System.out.println("  scorer=" + joinScorer);
+          if (joinScorer != null && docBase + joinScorer.getParentDoc() == og.doc) {
+            og.counts[scorerIDX] = joinScorer.getChildCount();
+            //System.out.println("    count=" + og.counts[scorerIDX]);
+            og.docs[scorerIDX] = joinScorer.swapChildDocs(og.docs[scorerIDX]);
+            assert og.docs[scorerIDX].length >= og.counts[scorerIDX]: "length=" + og.docs[scorerIDX].length + " vs count=" + og.counts[scorerIDX];
+            //System.out.println("    len=" + og.docs[scorerIDX].length);
+            /*
+              for(int idx=0;idx<og.counts[scorerIDX];idx++) {
+              System.out.println("    docs[" + idx + "]=" + og.docs[scorerIDX][idx]);
+              }
+            */
+            if (trackScores) {
+              //System.out.println("    copy scores");
+              og.scores[scorerIDX] = joinScorer.swapChildScores(og.scores[scorerIDX]);
+              assert og.scores[scorerIDX].length >= og.counts[scorerIDX]: "length=" + og.scores[scorerIDX].length + " vs count=" + og.counts[scorerIDX];
+            }
+          } else {
+            og.counts[scorerIDX] = 0;
           }
-        */
-        if (trackScores) {
-          //System.out.println("    copy scores");
-          og.scores[scorerIDX] = joinScorer.swapChildScores(og.scores[scorerIDX]);
-          assert og.scores[scorerIDX].length >= og.counts[scorerIDX]: "length=" + og.scores[scorerIDX].length + " vs count=" + og.counts[scorerIDX];
         }
-      } else {
-        og.counts[scorerIDX] = 0;
       }
-    }
-  }
-
-  @Override
-  protected void doSetNextReader(LeafReaderContext context) throws IOException {
-    currentReaderContext = context;
-    docBase = context.docBase;
-    for (int compIDX = 0; compIDX < comparators.length; compIDX++) {
-      queue.setComparator(compIDX, comparators[compIDX].setNextReader(context));
-    }
-  }
-
-  @Override
-  public boolean acceptsDocsOutOfOrder() {
-    return false;
+      
+      @Override
+      public boolean acceptsDocsOutOfOrder() {
+        return false;
+      }
+    };
   }
 
   private void enroll(ToParentBlockJoinQuery query, ToParentBlockJoinQuery.BlockJoinScorer scorer) {
@@ -296,34 +318,6 @@ public class ToParentBlockJoinCollector
       joinScorers[slot] = scorer;
     }
   }
-  
-  @Override
-  public void setScorer(Scorer scorer) {
-    //System.out.println("C.setScorer scorer=" + scorer);
-    // Since we invoke .score(), and the comparators likely
-    // do as well, cache it so it's only "really" computed
-    // once:
-    this.scorer = new ScoreCachingWrappingScorer(scorer);
-    for (int compIDX = 0; compIDX < comparators.length; compIDX++) {
-      comparators[compIDX].setScorer(this.scorer);
-    }
-    Arrays.fill(joinScorers, null);
-
-    Queue<Scorer> queue = new LinkedList<>();
-    //System.out.println("\nqueue: add top scorer=" + scorer);
-    queue.add(scorer);
-    while ((scorer = queue.poll()) != null) {
-      //System.out.println("  poll: " + scorer + "; " + scorer.getWeight().getQuery());
-      if (scorer instanceof ToParentBlockJoinQuery.BlockJoinScorer) {
-        enroll((ToParentBlockJoinQuery) scorer.getWeight().getQuery(), (ToParentBlockJoinQuery.BlockJoinScorer) scorer);
-      }
-
-      for (ChildScorer sub : scorer.getChildren()) {
-        //System.out.println("  add sub: " + sub.child + "; " + sub.child.getWeight().getQuery());
-        queue.add(sub.child);
-      }
-    }
-  }
 
   private OneGroup[] sortedGroups;
 
@@ -420,8 +414,8 @@ public class ToParentBlockJoinCollector
         collector = TopFieldCollector.create(withinGroupSort, numDocsInGroup, fillSortFields, trackScores, trackMaxScore, true);
       }
 
-      collector.setScorer(fakeScorer);
-      collector.getLeafCollector(og.readerContext);
+      LeafCollector leafCollector = collector.getLeafCollector(og.readerContext);
+      leafCollector.setScorer(fakeScorer);
       for(int docIDX=0;docIDX<numChildDocs;docIDX++) {
         //System.out.println("docIDX=" + docIDX + " vs " + og.docs[slot].length);
         final int doc = og.docs[slot][docIDX];
@@ -429,7 +423,7 @@ public class ToParentBlockJoinCollector
         if (trackScores) {
           fakeScorer.score = og.scores[slot][docIDX];
         }
-        collector.collect(doc);
+        leafCollector.collect(doc);
       }
       totalGroupedHitCount += numChildDocs;
 

Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinFieldComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinFieldComparator.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinFieldComparator.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinFieldComparator.java Tue Jan  6 15:15:42 2015
@@ -22,6 +22,8 @@ import java.io.IOException;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.LeafFieldComparator;
+import org.apache.lucene.search.SimpleFieldComparator;
 import org.apache.lucene.util.BitDocIdSet;
 import org.apache.lucene.util.BitSet;
 
@@ -31,13 +33,14 @@ import org.apache.lucene.util.BitSet;
  *
  * @lucene.experimental
  */
-public abstract class ToParentBlockJoinFieldComparator extends FieldComparator<Object> {
+public abstract class ToParentBlockJoinFieldComparator extends SimpleFieldComparator<Object> implements LeafFieldComparator { // repeat LeafFieldComparator for javadocs
 
   private final BitDocIdSetFilter parentFilter;
   private final BitDocIdSetFilter childFilter;
   final int spareSlot;
 
   FieldComparator<Object> wrappedComparator;
+  LeafFieldComparator wrappedLeafComparator;
   BitSet parentDocuments;
   BitSet childDocuments;
 
@@ -55,7 +58,7 @@ public abstract class ToParentBlockJoinF
 
   @Override
   public void setBottom(int slot) {
-    wrappedComparator.setBottom(slot);
+    wrappedLeafComparator.setBottom(slot);
   }
 
   @Override
@@ -64,7 +67,7 @@ public abstract class ToParentBlockJoinF
   }
 
   @Override
-  public FieldComparator<Object> setNextReader(LeafReaderContext context) throws IOException {
+  protected void doSetNextReader(LeafReaderContext context) throws IOException {
     BitDocIdSet children = childFilter.getDocIdSet(context);
     if (children == null) {
       childDocuments = null;
@@ -77,8 +80,7 @@ public abstract class ToParentBlockJoinF
     } else {
       parentDocuments = parents.bits();
     }
-    wrappedComparator = wrappedComparator.setNextReader(context);
-    return this;
+    wrappedLeafComparator = wrappedComparator.getLeafComparator(context);
   }
 
   @Override
@@ -90,12 +92,12 @@ public abstract class ToParentBlockJoinF
    * Concrete implementation of {@link ToParentBlockJoinSortField} to sorts the parent docs with the lowest values
    * in the child / nested docs first.
    */
-  public static final class Lowest extends ToParentBlockJoinFieldComparator {
+  public static final class Lowest extends ToParentBlockJoinFieldComparator implements LeafFieldComparator {
 
     /**
      * Create ToParentBlockJoinFieldComparator.Lowest
      *
-     * @param wrappedComparator The {@link FieldComparator} on the child / nested level.
+     * @param wrappedComparator The {@link LeafFieldComparator} on the child / nested level.
      * @param parentFilter Filter that identifies the parent documents.
      * @param childFilter Filter that defines which child / nested documents participates in sorting.
      * @param spareSlot The extra slot inside the wrapped comparator that is used to compare which nested document
@@ -119,7 +121,7 @@ public abstract class ToParentBlockJoinF
       }
 
       // We only need to emit a single cmp value for any matching child doc
-      int cmp = wrappedComparator.compareBottom(childDoc);
+      int cmp = wrappedLeafComparator.compareBottom(childDoc);
       if (cmp > 0) {
         return cmp;
       }
@@ -129,7 +131,7 @@ public abstract class ToParentBlockJoinF
         if (childDoc >= parentDoc || childDoc == DocIdSetIterator.NO_MORE_DOCS) {
           return cmp;
         }
-        int cmp1 = wrappedComparator.compareBottom(childDoc);
+        int cmp1 = wrappedLeafComparator.compareBottom(childDoc);
         if (cmp1 > 0) {
           return cmp1;
         } else {
@@ -152,23 +154,22 @@ public abstract class ToParentBlockJoinF
       if (childDoc >= parentDoc || childDoc == DocIdSetIterator.NO_MORE_DOCS) {
         return;
       }
-      wrappedComparator.copy(spareSlot, childDoc);
-      wrappedComparator.copy(slot, childDoc);
+      wrappedLeafComparator.copy(spareSlot, childDoc);
+      wrappedLeafComparator.copy(slot, childDoc);
 
       while (true) {
         childDoc = childDocuments.nextSetBit(childDoc + 1);
         if (childDoc >= parentDoc || childDoc == DocIdSetIterator.NO_MORE_DOCS) {
           return;
         }
-        wrappedComparator.copy(spareSlot, childDoc);
+        wrappedLeafComparator.copy(spareSlot, childDoc);
         if (wrappedComparator.compare(spareSlot, slot) < 0) {
-          wrappedComparator.copy(slot, childDoc);
+          wrappedLeafComparator.copy(slot, childDoc);
         }
       }
     }
 
     @Override
-    @SuppressWarnings("unchecked")
     public int compareTop(int parentDoc) throws IOException {
       if (parentDoc == 0 || parentDocuments == null || childDocuments == null) {
         return 0;
@@ -182,7 +183,7 @@ public abstract class ToParentBlockJoinF
       }
 
       // We only need to emit a single cmp value for any matching child doc
-      int cmp = wrappedComparator.compareBottom(childDoc);
+      int cmp = wrappedLeafComparator.compareBottom(childDoc);
       if (cmp > 0) {
         return cmp;
       }
@@ -192,7 +193,7 @@ public abstract class ToParentBlockJoinF
         if (childDoc >= parentDoc || childDoc == DocIdSetIterator.NO_MORE_DOCS) {
           return cmp;
         }
-        int cmp1 = wrappedComparator.compareTop(childDoc);
+        int cmp1 = wrappedLeafComparator.compareTop(childDoc);
         if (cmp1 > 0) {
           return cmp1;
         } else {
@@ -209,12 +210,12 @@ public abstract class ToParentBlockJoinF
    * Concrete implementation of {@link ToParentBlockJoinSortField} to sorts the parent docs with the highest values
    * in the child / nested docs first.
    */
-  public static final class Highest extends ToParentBlockJoinFieldComparator {
+  public static final class Highest extends ToParentBlockJoinFieldComparator implements LeafFieldComparator {
 
     /**
      * Create ToParentBlockJoinFieldComparator.Highest
      *
-     * @param wrappedComparator The {@link FieldComparator} on the child / nested level.
+     * @param wrappedComparator The {@link LeafFieldComparator} on the child / nested level.
      * @param parentFilter Filter that identifies the parent documents.
      * @param childFilter Filter that defines which child / nested documents participates in sorting.
      * @param spareSlot The extra slot inside the wrapped comparator that is used to compare which nested document
@@ -236,7 +237,7 @@ public abstract class ToParentBlockJoinF
         return 0;
       }
 
-      int cmp = wrappedComparator.compareBottom(childDoc);
+      int cmp = wrappedLeafComparator.compareBottom(childDoc);
       if (cmp < 0) {
         return cmp;
       }
@@ -246,7 +247,7 @@ public abstract class ToParentBlockJoinF
         if (childDoc >= parentDoc || childDoc == DocIdSetIterator.NO_MORE_DOCS) {
           return cmp;
         }
-        int cmp1 = wrappedComparator.compareBottom(childDoc);
+        int cmp1 = wrappedLeafComparator.compareBottom(childDoc);
         if (cmp1 < 0) {
           return cmp1;
         } else {
@@ -268,23 +269,22 @@ public abstract class ToParentBlockJoinF
       if (childDoc >= parentDoc || childDoc == DocIdSetIterator.NO_MORE_DOCS) {
         return;
       }
-      wrappedComparator.copy(spareSlot, childDoc);
-      wrappedComparator.copy(slot, childDoc);
+      wrappedLeafComparator.copy(spareSlot, childDoc);
+      wrappedLeafComparator.copy(slot, childDoc);
 
       while (true) {
         childDoc = childDocuments.nextSetBit(childDoc + 1);
         if (childDoc >= parentDoc || childDoc == DocIdSetIterator.NO_MORE_DOCS) {
           return;
         }
-        wrappedComparator.copy(spareSlot, childDoc);
+        wrappedLeafComparator.copy(spareSlot, childDoc);
         if (wrappedComparator.compare(spareSlot, slot) > 0) {
-          wrappedComparator.copy(slot, childDoc);
+          wrappedLeafComparator.copy(slot, childDoc);
         }
       }
     }
 
     @Override
-    @SuppressWarnings("unchecked")
     public int compareTop(int parentDoc) throws IOException {
       if (parentDoc == 0 || parentDocuments == null || childDocuments == null) {
         return 0;
@@ -296,7 +296,7 @@ public abstract class ToParentBlockJoinF
         return 0;
       }
 
-      int cmp = wrappedComparator.compareBottom(childDoc);
+      int cmp = wrappedLeafComparator.compareBottom(childDoc);
       if (cmp < 0) {
         return cmp;
       }
@@ -306,7 +306,7 @@ public abstract class ToParentBlockJoinF
         if (childDoc >= parentDoc || childDoc == DocIdSetIterator.NO_MORE_DOCS) {
           return cmp;
         }
-        int cmp1 = wrappedComparator.compareTop(childDoc);
+        int cmp1 = wrappedLeafComparator.compareTop(childDoc);
         if (cmp1 < 0) {
           return cmp1;
         } else {

Modified: lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java Tue Jan  6 15:15:42 2015
@@ -18,6 +18,7 @@ package org.apache.lucene.search.join;
  */
 
 import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.LeafFieldComparator;
 import org.apache.lucene.search.SortField;
 
 import java.io.IOException;

Modified: lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java (original)
+++ lucene/dev/branches/branch_5x/lucene/join/src/test/org/apache/lucene/search/join/TestJoinUtil.java Tue Jan  6 15:15:42 2015
@@ -52,9 +52,12 @@ import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
 import org.apache.lucene.search.BooleanClause;
 import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.Collector;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.Explanation;
+import org.apache.lucene.search.FilterLeafCollector;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.LeafCollector;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
@@ -482,30 +485,25 @@ public class TestJoinUtil extends Lucene
         // Need to know all documents that have matches. TopDocs doesn't give me that and then I'd be also testing TopDocsCollector...
         final BitSet actualResult = new FixedBitSet(indexSearcher.getIndexReader().maxDoc());
         final TopScoreDocCollector topScoreDocCollector = TopScoreDocCollector.create(10, false);
-        indexSearcher.search(joinQuery, new SimpleCollector() {
-
-          int docBase;
-
-          @Override
-          public void collect(int doc) throws IOException {
-            actualResult.set(doc + docBase);
-            topScoreDocCollector.collect(doc);
-          }
-
-          @Override
-          protected void doSetNextReader(LeafReaderContext context) throws IOException {
-            docBase = context.docBase;
-            topScoreDocCollector.getLeafCollector(context);
-          }
-
-          @Override
-          public void setScorer(Scorer scorer) throws IOException {
-            topScoreDocCollector.setScorer(scorer);
-          }
+        indexSearcher.search(joinQuery, new Collector() {
 
           @Override
-          public boolean acceptsDocsOutOfOrder() {
-            return scoreDocsInOrder;
+          public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
+            final int docBase = context.docBase;
+            final LeafCollector in = topScoreDocCollector.getLeafCollector(context);
+            return new FilterLeafCollector(in) {
+
+              @Override
+              public void collect(int doc) throws IOException {
+                super.collect(doc);
+                actualResult.set(doc + docBase);
+              }
+              
+              @Override
+              public boolean acceptsDocsOutOfOrder() {
+                return scoreDocsInOrder;
+              }
+            };
           }
         });
         // Asserting bit set...

Modified: lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/index/Sorter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/index/Sorter.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/index/Sorter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/index/Sorter.java Tue Jan  6 15:15:42 2015
@@ -20,9 +20,7 @@ package org.apache.lucene.index;
 import java.io.IOException;
 import java.util.Comparator;
 
-import org.apache.lucene.index.LeafReader;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.LeafFieldComparator;
 import org.apache.lucene.search.Scorer;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
@@ -214,12 +212,11 @@ final class Sorter {
   DocMap sort(LeafReader reader) throws IOException {
     SortField fields[] = sort.getSort();
     final int reverseMul[] = new int[fields.length];
-    final FieldComparator<?> comparators[] = new FieldComparator[fields.length];
+    final LeafFieldComparator comparators[] = new LeafFieldComparator[fields.length];
     
     for (int i = 0; i < fields.length; i++) {
       reverseMul[i] = fields[i].getReverse() ? -1 : 1;
-      comparators[i] = fields[i].getComparator(1, i);
-      comparators[i].setNextReader(reader.getContext());
+      comparators[i] = fields[i].getComparator(1, i).getLeafComparator(reader.getContext());
       comparators[i].setScorer(FAKESCORER);
     }
     final DocComparator comparator = new DocComparator() {

Modified: lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/search/BlockJoinComparatorSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/search/BlockJoinComparatorSource.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/search/BlockJoinComparatorSource.java (original)
+++ lucene/dev/branches/branch_5x/lucene/misc/src/java/org/apache/lucene/search/BlockJoinComparatorSource.java Tue Jan  6 15:15:42 2015
@@ -21,18 +21,8 @@ import java.io.IOException;
 
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.SortingMergePolicy;
-import org.apache.lucene.search.DocIdSet;
-import org.apache.lucene.search.FieldComparator;
-import org.apache.lucene.search.FieldComparatorSource;
-import org.apache.lucene.search.Filter;
-import org.apache.lucene.search.IndexSearcher; // javadocs
-import org.apache.lucene.search.Query; // javadocs
-import org.apache.lucene.search.ScoreDoc; // javadocs
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.Sort;
-import org.apache.lucene.search.SortField;
 import org.apache.lucene.util.BitDocIdSet;
-import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.BitSet;
 
 /**
  * Helper class to sort readers that contain blocks of documents.
@@ -51,22 +41,22 @@ public class BlockJoinComparatorSource e
   final Filter parentsFilter;
   final Sort parentSort;
   final Sort childSort;
-  
-  /** 
+
+  /**
    * Create a new BlockJoinComparatorSource, sorting only blocks of documents
    * with {@code parentSort} and not reordering children with a block.
-   * 
+   *
    * @param parentsFilter Filter identifying parent documents
    * @param parentSort Sort for parent documents
    */
   public BlockJoinComparatorSource(Filter parentsFilter, Sort parentSort) {
     this(parentsFilter, parentSort, new Sort(SortField.FIELD_DOC));
   }
-  
-  /** 
+
+  /**
    * Create a new BlockJoinComparatorSource, specifying the sort order for both
    * blocks of documents and children within a block.
-   * 
+   *
    * @param parentsFilter Filter identifying parent documents
    * @param parentSort Sort for parent documents
    * @param childSort Sort for child documents in the same block
@@ -82,7 +72,7 @@ public class BlockJoinComparatorSource e
     // we keep parallel slots: the parent ids and the child ids
     final int parentSlots[] = new int[numHits];
     final int childSlots[] = new int[numHits];
-    
+
     SortField parentFields[] = parentSort.getSort();
     final int parentReverseMul[] = new int[parentFields.length];
     final FieldComparator<?> parentComparators[] = new FieldComparator[parentFields.length];
@@ -90,7 +80,7 @@ public class BlockJoinComparatorSource e
       parentReverseMul[i] = parentFields[i].getReverse() ? -1 : 1;
       parentComparators[i] = parentFields[i].getComparator(1, i);
     }
-    
+
     SortField childFields[] = childSort.getSort();
     final int childReverseMul[] = new int[childFields.length];
     final FieldComparator<?> childComparators[] = new FieldComparator[childFields.length];
@@ -98,14 +88,16 @@ public class BlockJoinComparatorSource e
       childReverseMul[i] = childFields[i].getReverse() ? -1 : 1;
       childComparators[i] = childFields[i].getComparator(1, i);
     }
-        
+
     // NOTE: we could return parent ID as value but really our sort "value" is more complex...
     // So we throw UOE for now. At the moment you really should only use this at indexing time.
     return new FieldComparator<Integer>() {
       int bottomParent;
       int bottomChild;
-      FixedBitSet parentBits;
-      
+      BitSet parentBits;
+      LeafFieldComparator[] parentLeafComparators;
+      LeafFieldComparator[] childLeafComparators;
+
       @Override
       public int compare(int slot1, int slot2) {
         try {
@@ -116,51 +108,69 @@ public class BlockJoinComparatorSource e
       }
 
       @Override
-      public void setBottom(int slot) {
-        bottomParent = parentSlots[slot];
-        bottomChild = childSlots[slot];
-      }
-
-      @Override
       public void setTopValue(Integer value) {
         // we dont have enough information (the docid is needed)
         throw new UnsupportedOperationException("this comparator cannot be used with deep paging");
       }
 
       @Override
-      public int compareBottom(int doc) throws IOException {
-        return compare(bottomChild, bottomParent, doc, parent(doc));
-      }
-
-      @Override
-      public int compareTop(int doc) throws IOException {
-        // we dont have enough information (the docid is needed)
-        throw new UnsupportedOperationException("this comparator cannot be used with deep paging");
-      }
-
-      @Override
-      public void copy(int slot, int doc) throws IOException {
-        childSlots[slot] = doc;
-        parentSlots[slot] = parent(doc);
-      }
-
-      @Override
-      public FieldComparator<Integer> setNextReader(LeafReaderContext context) throws IOException {
+      public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
+        if (parentBits != null) {
+          throw new IllegalStateException("This comparator can only be used on a single segment");
+        }
         final DocIdSet parents = parentsFilter.getDocIdSet(context, null);
         if (parents == null) {
           throw new IllegalStateException("LeafReader " + context.reader() + " contains no parents!");
         }
-        if (!(parents instanceof BitDocIdSet)) {
-          throw new IllegalStateException("parentFilter must return FixedBitSet; got " + parents);
+        if (parents instanceof BitDocIdSet == false) {
+          throw new IllegalStateException("parentFilter must return BitSet; got " + parents);
         }
-        parentBits = (FixedBitSet) parents.bits();
+        parentBits = (BitSet) parents.bits();
+        parentLeafComparators = new LeafFieldComparator[parentComparators.length];
         for (int i = 0; i < parentComparators.length; i++) {
-          parentComparators[i] = parentComparators[i].setNextReader(context);
+          parentLeafComparators[i] = parentComparators[i].getLeafComparator(context);
         }
+        childLeafComparators = new LeafFieldComparator[childComparators.length];
         for (int i = 0; i < childComparators.length; i++) {
-          childComparators[i] = childComparators[i].setNextReader(context);
+          childLeafComparators[i] = childComparators[i].getLeafComparator(context);
         }
-        return this;
+
+        return new LeafFieldComparator() {
+
+          @Override
+          public int compareBottom(int doc) throws IOException {
+            return compare(bottomChild, bottomParent, doc, parent(doc));
+          }
+
+          @Override
+          public int compareTop(int doc) throws IOException {
+            // we dont have enough information (the docid is needed)
+            throw new UnsupportedOperationException("this comparator cannot be used with deep paging");
+          }
+
+          @Override
+          public void copy(int slot, int doc) throws IOException {
+            childSlots[slot] = doc;
+            parentSlots[slot] = parent(doc);
+          }
+
+          @Override
+          public void setBottom(int slot) {
+            bottomParent = parentSlots[slot];
+            bottomChild = childSlots[slot];
+          }
+
+          @Override
+          public void setScorer(Scorer scorer) {
+            for (LeafFieldComparator comp : parentLeafComparators) {
+              comp.setScorer(scorer);
+            }
+            for (LeafFieldComparator comp : childLeafComparators) {
+              comp.setScorer(scorer);
+            }
+          }
+
+        };
       }
 
       @Override
@@ -168,32 +178,21 @@ public class BlockJoinComparatorSource e
         // really our sort "value" is more complex...
         throw new UnsupportedOperationException("filling sort field values is not yet supported");
       }
-      
-      @Override
-      public void setScorer(Scorer scorer) {
-        super.setScorer(scorer);
-        for (FieldComparator<?> comp : parentComparators) {
-          comp.setScorer(scorer);
-        }
-        for (FieldComparator<?> comp : childComparators) {
-          comp.setScorer(scorer);
-        }
-      }
 
       int parent(int doc) {
         return parentBits.nextSetBit(doc);
       }
-      
+
       int compare(int docID1, int parent1, int docID2, int parent2) throws IOException {
         if (parent1 == parent2) { // both are in the same block
           if (docID1 == parent1 || docID2 == parent2) {
             // keep parents at the end of blocks
             return docID1 - docID2;
           } else {
-            return compare(docID1, docID2, childComparators, childReverseMul);
+            return compare(docID1, docID2, childLeafComparators, childReverseMul);
           }
         } else {
-          int cmp = compare(parent1, parent2, parentComparators, parentReverseMul);
+          int cmp = compare(parent1, parent2, parentLeafComparators, parentReverseMul);
           if (cmp == 0) {
             return parent1 - parent2;
           } else {
@@ -201,8 +200,8 @@ public class BlockJoinComparatorSource e
           }
         }
       }
-      
-      int compare(int docID1, int docID2, FieldComparator<?> comparators[], int reverseMul[]) throws IOException {
+
+      int compare(int docID1, int docID2, LeafFieldComparator comparators[], int reverseMul[]) throws IOException {
         for (int i = 0; i < comparators.length; i++) {
           // TODO: would be better if copy() didnt cause a term lookup in TermOrdVal & co,
           // the segments are always the same here...
@@ -217,7 +216,7 @@ public class BlockJoinComparatorSource e
       }
     };
   }
-  
+
   @Override
   public String toString() {
     return "blockJoin(parentSort=" + parentSort + ",childSort=" + childSort + ")";

Modified: lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java (original)
+++ lucene/dev/branches/branch_5x/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java Tue Jan  6 15:15:42 2015
@@ -17,16 +17,17 @@ package org.apache.lucene.queries.functi
  * limitations under the License.
  */
 
+import java.io.IOException;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.search.FieldComparator;
 import org.apache.lucene.search.FieldComparatorSource;
 import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.SimpleFieldComparator;
 import org.apache.lucene.search.SortField;
 
-import java.io.IOException;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
 /**
  * Instantiates {@link FunctionValues} for a particular reader.
  * <br>
@@ -126,7 +127,7 @@ public abstract class ValueSource {
    * off of the {@link FunctionValues} for a ValueSource
    * instead of the normal Lucene FieldComparator that works off of a FieldCache.
    */
-  class ValueSourceComparator extends FieldComparator<Double> {
+  class ValueSourceComparator extends SimpleFieldComparator<Double> {
     private final double[] values;
     private FunctionValues docVals;
     private double bottom;
@@ -154,9 +155,8 @@ public abstract class ValueSource {
     }
 
     @Override
-    public FieldComparator setNextReader(LeafReaderContext context) throws IOException {
+    public void doSetNextReader(LeafReaderContext context) throws IOException {
       docVals = getValues(fcontext, context);
-      return this;
     }
 
     @Override

Modified: lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/SlowCollatedStringComparator.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/SlowCollatedStringComparator.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/SlowCollatedStringComparator.java (original)
+++ lucene/dev/branches/branch_5x/lucene/sandbox/src/java/org/apache/lucene/sandbox/queries/SlowCollatedStringComparator.java Tue Jan  6 15:15:42 2015
@@ -23,7 +23,7 @@ import java.text.Collator;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.BinaryDocValues;
 import org.apache.lucene.index.DocValues;
-import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.SimpleFieldComparator;
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 
@@ -36,7 +36,7 @@ import org.apache.lucene.util.BytesRef;
  * This class will be removed in Lucene 5.0
  */
 @Deprecated
-public final class SlowCollatedStringComparator extends FieldComparator<String> {
+public final class SlowCollatedStringComparator extends SimpleFieldComparator<String> {
 
   private final String[] values;
   private BinaryDocValues currentDocTerms;
@@ -93,10 +93,9 @@ public final class SlowCollatedStringCom
   }
 
   @Override
-  public FieldComparator<String> setNextReader(LeafReaderContext context) throws IOException {
+  protected void doSetNextReader(LeafReaderContext context) throws IOException {
     currentDocTerms = DocValues.getBinary(context.reader(), field);
     docsWithField = DocValues.getDocsWithField(context.reader(), field);
-    return this;
   }
   
   @Override

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java Tue Jan  6 15:15:42 2015
@@ -23,6 +23,7 @@ import org.apache.lucene.index.ReaderUti
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.BooleanQuery;
 import org.apache.lucene.search.FieldComparator;
+import org.apache.lucene.search.LeafFieldComparator;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
 import org.apache.lucene.search.Scorer;
@@ -598,7 +599,8 @@ public class QueryComponent extends Sear
         // :TODO: would be simpler to always serialize every position of SortField[]
         if (type==SortField.Type.SCORE || type==SortField.Type.DOC) continue;
 
-        FieldComparator comparator = null;
+        FieldComparator<?> comparator = null;
+        LeafFieldComparator leafComparator = null;
         Object[] vals = new Object[nDocs];
 
         int lastIdx = -1;
@@ -621,12 +623,12 @@ public class QueryComponent extends Sear
 
           if (comparator == null) {
             comparator = sortField.getComparator(1,0);
-            comparator = comparator.setNextReader(currentLeaf);
+            leafComparator = comparator.getLeafComparator(currentLeaf);
           }
 
           doc -= currentLeaf.docBase;  // adjust for what segment this is in
-          comparator.setScorer(new FakeScorer(doc, score));
-          comparator.copy(0, doc);
+          leafComparator.setScorer(new FakeScorer(doc, score));
+          leafComparator.copy(0, doc);
           Object val = comparator.value(0);
           if (null != ft) val = ft.marshalSortValue(val);
           vals[position] = val;

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java Tue Jan  6 15:15:42 2015
@@ -36,6 +36,7 @@ import org.apache.lucene.search.DocIdSet
 import org.apache.lucene.search.FieldComparator;
 import org.apache.lucene.search.FieldComparatorSource;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.SimpleFieldComparator;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.SortField;
 import org.apache.lucene.search.TermQuery;
@@ -631,7 +632,7 @@ public class QueryElevationComponent ext
 
   @Override
   public FieldComparator<Integer> newComparator(String fieldname, final int numHits, int sortPos, boolean reversed) throws IOException {
-    return new FieldComparator<Integer>() {
+    return new SimpleFieldComparator<Integer>() {
       private final int[] values = new int[numHits];
       private int bottomVal;
       private int topVal;
@@ -677,13 +678,13 @@ public class QueryElevationComponent ext
       }
 
       @Override
-      public FieldComparator setNextReader(LeafReaderContext context) throws IOException {
+      protected void doSetNextReader(LeafReaderContext context) throws IOException {
         //convert the ids to Lucene doc ids, the ordSet and termValues needs to be the same size as the number of elevation docs we have
         ordSet.clear();
         Fields fields = context.reader().fields();
-        if (fields == null) return this;
+        if (fields == null) return;
         Terms terms = fields.terms(idField);
-        if (terms == null) return this;
+        if (terms == null) return;
         termsEnum = terms.iterator(termsEnum);
         BytesRefBuilder term = new BytesRefBuilder();
         Bits liveDocs = context.reader().getLiveDocs();
@@ -701,7 +702,6 @@ public class QueryElevationComponent ext
             }
           }
         }
-        return this;
       }
 
       @Override

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/RandomSortField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/RandomSortField.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/RandomSortField.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/schema/RandomSortField.java Tue Jan  6 15:15:42 2015
@@ -109,7 +109,7 @@ public class RandomSortField extends Fie
   private static FieldComparatorSource randomComparatorSource = new FieldComparatorSource() {
     @Override
     public FieldComparator<Integer> newComparator(final String fieldname, final int numHits, int sortPos, boolean reversed) {
-      return new FieldComparator<Integer>() {
+      return new SimpleFieldComparator<Integer>() {
         int seed;
         private final int[] values = new int[numHits];
         int bottomVal;
@@ -141,9 +141,8 @@ public class RandomSortField extends Fie
         }
 
         @Override
-        public FieldComparator setNextReader(LeafReaderContext context) {
+        protected void doSetNextReader(LeafReaderContext context) {
           seed = getSeed(fieldname, context);
-          return this;
         }
 
         @Override

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ExportQParserPlugin.java Tue Jan  6 15:15:42 2015
@@ -26,7 +26,6 @@ import org.apache.solr.common.util.Named
 import org.apache.solr.request.SolrQueryRequest;
 import org.apache.solr.common.params.SolrParams;
 
-
 import java.io.IOException;
 import java.util.Map;
 import java.util.Set;
@@ -129,22 +128,32 @@ public class ExportQParserPlugin extends
   private class ExportCollector extends TopDocsCollector  {
 
     private FixedBitSet[] sets;
-    private FixedBitSet set;
 
     public ExportCollector(FixedBitSet[] sets) {
       super(null);
       this.sets = sets;
     }
-    
-    public void doSetNextReader(LeafReaderContext context) throws IOException {
-      this.set = new FixedBitSet(context.reader().maxDoc());
-      this.sets[context.ord] = set;
 
-    }
-    
-    public void collect(int docId) throws IOException{
-      ++totalHits;
-      set.set(docId);
+    @Override
+    public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
+      final FixedBitSet set = new FixedBitSet(context.reader().maxDoc());
+      this.sets[context.ord] = set;
+      return new LeafCollector() {
+        
+        @Override
+        public void setScorer(Scorer scorer) throws IOException {}
+        
+        @Override
+        public void collect(int docId) throws IOException{
+          ++totalHits;
+          set.set(docId);
+        }
+        
+        @Override
+        public boolean acceptsDocsOutOfOrder() {
+          return false;
+        }
+      };
     }
 
     private ScoreDoc[] getScoreDocs(int howMany) {
@@ -170,12 +179,5 @@ public class ExportQParserPlugin extends
       return new TopDocs(totalHits, scoreDocs, 0.0f);
     }
 
-    public void setScorer(Scorer scorer) throws IOException {
-
-    }
-    
-    public boolean acceptsDocsOutOfOrder() {
-      return false;
-    }
   }
 }
\ No newline at end of file

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/ReRankQParserPlugin.java Tue Jan  6 15:15:42 2015
@@ -18,6 +18,7 @@
 package org.apache.solr.search;
 
 import com.carrotsearch.hppc.IntIntOpenHashMap;
+
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.search.Explanation;
 import org.apache.lucene.search.MatchAllDocsQuery;
@@ -33,7 +34,7 @@ import org.apache.solr.common.util.Named
 import org.apache.solr.handler.component.MergeStrategy;
 import org.apache.solr.handler.component.QueryElevationComponent;
 import org.apache.solr.request.SolrQueryRequest;
-
+import org.apache.lucene.search.LeafCollector;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.Weight;
 import org.apache.lucene.search.IndexSearcher;
@@ -43,6 +44,7 @@ import org.apache.lucene.search.Sort;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.ScoreDoc;
+
 import com.carrotsearch.hppc.IntFloatOpenHashMap;
 
 import org.apache.lucene.util.Bits;
@@ -255,26 +257,15 @@ public class ReRankQParserPlugin extends
       this.reRankWeight = reRankWeight;
     }
 
-    public boolean acceptsDocsOutOfOrder() {
-      return false;
-    }
-
-    public void collect(int doc) throws IOException {
-      mainCollector.collect(doc);
-    }
-
-    public void setScorer(Scorer scorer) throws IOException{
-      mainCollector.setScorer(scorer);
-    }
-
-    public void doSetNextReader(LeafReaderContext context) throws IOException{
-      mainCollector.getLeafCollector(context);
-    }
-
     public int getTotalHits() {
       return mainCollector.getTotalHits();
     }
 
+    @Override
+    public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
+      return mainCollector.getLeafCollector(context);
+    }
+
     public TopDocs topDocs(int start, int howMany) {
 
       try {
@@ -387,6 +378,7 @@ public class ReRankQParserPlugin extends
         throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
       }
     }
+
   }
 
   public class BoostedComp implements Comparator {

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java?rev=1649824&r1=1649823&r2=1649824&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java Tue Jan  6 15:15:42 2015
@@ -2054,16 +2054,17 @@ public class SolrIndexSearcher extends I
     int end=0;
     int readerIndex = 0;
 
+    LeafCollector leafCollector = null;
     while (iter.hasNext()) {
       int doc = iter.nextDoc();
       while (doc>=end) {
         LeafReaderContext leaf = leafContexts.get(readerIndex++);
         base = leaf.docBase;
         end = base + leaf.reader().maxDoc();
-        topCollector.getLeafCollector(leaf);
+        leafCollector = topCollector.getLeafCollector(leaf);
         // we should never need to set the scorer given the settings for the collector
       }
-      topCollector.collect(doc-base);
+      leafCollector.collect(doc-base);
     }
     
     TopDocs topDocs = topCollector.topDocs(0, nDocs);



Mime
View raw message