Index: src/test/org/apache/lucene/search/TestSort.java =================================================================== --- src/test/org/apache/lucene/search/TestSort.java (revision 800717) +++ src/test/org/apache/lucene/search/TestSort.java (working copy) @@ -412,7 +412,7 @@ bottomValue = slotValues[bottom]; } - public void setNextReader(IndexReader reader, int docBase, int numSlotsFull) throws IOException { + public void setNextReader(IndexReader reader, int docBase) throws IOException { docValues = FieldCache.DEFAULT.getInts(reader, "parser", new FieldCache.IntParser() { public final int parseInt(final String val) { return (val.charAt(0)-'A') * 123456; @@ -420,10 +420,6 @@ }); } - public int sortType() { - return 0; - } - public Comparable value(int slot) { return new Integer(slotValues[slot]); } Index: src/test/org/apache/lucene/search/JustCompileSearch.java =================================================================== --- src/test/org/apache/lucene/search/JustCompileSearch.java (revision 800717) +++ src/test/org/apache/lucene/search/JustCompileSearch.java (working copy) @@ -221,15 +221,11 @@ throw new UnsupportedOperationException(UNSUPPORTED_MSG); } - public void setNextReader(IndexReader reader, int docBase, int numSlotsFull) + public void setNextReader(IndexReader reader, int docBase) throws IOException { throw new UnsupportedOperationException(UNSUPPORTED_MSG); } - public int sortType() { - throw new UnsupportedOperationException(UNSUPPORTED_MSG); - } - public Comparable value(int slot) { throw new UnsupportedOperationException(UNSUPPORTED_MSG); } Index: src/test/org/apache/lucene/search/TestElevationComparator.java =================================================================== --- src/test/org/apache/lucene/search/TestElevationComparator.java (revision 800717) +++ src/test/org/apache/lucene/search/TestElevationComparator.java (working copy) @@ -21,7 +21,6 @@ import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.*; -import org.apache.lucene.search.*; import org.apache.lucene.store.*; import org.apache.lucene.util.LuceneTestCase; @@ -165,14 +164,10 @@ values[slot] = docVal(doc); } - public void setNextReader(IndexReader reader, int docBase, int numSlotsFull) throws IOException { + public void setNextReader(IndexReader reader, int docBase) throws IOException { idIndex = FieldCache.DEFAULT.getStringIndex(reader, fieldname); } - public int sortType() { - return SortField.CUSTOM; - } - public Comparable value(int slot) { return new Integer(values[slot]); } Index: src/java/org/apache/lucene/search/FieldValueHitQueue.java =================================================================== --- src/java/org/apache/lucene/search/FieldValueHitQueue.java (revision 800717) +++ src/java/org/apache/lucene/search/FieldValueHitQueue.java (working copy) @@ -76,7 +76,7 @@ SortField field = fields[0]; // AUTO is resolved before we are called assert field.getType() != SortField.AUTO; - comparator = field.getComparator(size, 0, field.reverse); + comparator = field.getComparator(size, 0); oneReverseMul = field.reverse ? -1 : 1; comparators[0] = comparator; @@ -127,7 +127,7 @@ assert field.getType() != SortField.AUTO; reverseMul[i] = field.reverse ? -1 : 1; - comparators[i] = field.getComparator(size, i, field.reverse); + comparators[i] = field.getComparator(size, i); } initialize(size); Index: src/java/org/apache/lucene/search/FieldComparator.java =================================================================== --- src/java/org/apache/lucene/search/FieldComparator.java (revision 800717) +++ src/java/org/apache/lucene/search/FieldComparator.java (working copy) @@ -31,13 +31,54 @@ import org.apache.lucene.search.FieldCache.StringIndex; /** - * A FieldComparator compares hits across multiple IndexReaders. - * - * A comparator can compare a hit at hit 'slot a' with hit 'slot b', - * compare a hit on 'doc i' with hit 'slot a', or copy a hit at 'doc i' - * to 'slot a'. Each slot refers to a hit while each doc refers to the - * current IndexReader. + * Expert: a FieldComparator compares hits so as to determine their + * sort order when collecting the top results with {@link + * TopFieldCollector}. The concrete public FieldComparator + * classes here correspond to the SortField types. * + *
This API is designed to achieve high performance + * sorting, by exposing a tight interaction with {@link + * FieldValueHitQueue} as it visits hits. Whenever a hit is + * competitive, it's enrolled into a virtual slot, which is + * an int ranging from 0 to numHits-1. The {@link + * FieldComparator} is made aware of segment transitions + * during searching in case any internal state it's tracking + * needs to be recomputed during these transitions.
+ * + *A comparator must define these functions:
+ * + *For a search that hits many results, this method + * will be the hotspot (invoked by far the most + * frequently).
* * @param doc that was hit * @return any N < 0 if the doc's value is sorted after @@ -819,7 +831,10 @@ public abstract int compareBottom(int doc) throws IOException; /** - * Copy hit (doc,score) to hit slot. + * This method is called when a new hit is competitive. + * You should copy any state associated with this document + * that will be required for future comparisons, into the + * specified slot. * * @param slot which slot to copy the hit to * @param doc docID relative to current reader @@ -834,22 +849,21 @@ * @throws IOException * @throws IOException */ - public abstract void setNextReader(IndexReader reader, int docBase, int numSlotsFull) throws IOException; + public abstract void setNextReader(IndexReader reader, int docBase) throws IOException; - /** Sets the Scorer to use in case a document's score is needed. */ + /** Sets the Scorer to use in case a document's score is + * needed. + * + * @param scorer Scorer instance that you should use to + * obtain the current hit's score, if necessary. */ public void setScorer(Scorer scorer) { // Empty implementation since most comparators don't need the score. This // can be overridden by those that need it. } /** - * @return SortField.TYPE - */ - public abstract int sortType(); - - /** - * Return the actual value at slot. - * + * Return the actual value in the slot. + * * @param slot the value * @return value in this slot upgraded to Comparable */ Index: src/java/org/apache/lucene/search/SortField.java =================================================================== --- src/java/org/apache/lucene/search/SortField.java (revision 800717) +++ src/java/org/apache/lucene/search/SortField.java (working copy) @@ -443,16 +443,20 @@ } - /** Returns the {@link FieldComparator} to use for sorting. + /** Returns the {@link FieldComparator} to use for + * sorting. + * + * NOTE: This API is experimental and might change in + * incompatible ways in the next release. + * * @param numHits number of top hits the queue will store * @param sortPos position of this SortField within {@link * Sort}. The comparator is primary if sortPos==0, * secondary if sortPos==1, etc. Some comparators can * optimize themselves when they are the primary sort. - * @param reversed True if the SortField is reversed * @return {@link FieldComparator} to use when sorting */ - public FieldComparator getComparator(final int numHits, final int sortPos, final boolean reversed) throws IOException { + public FieldComparator getComparator(final int numHits, final int sortPos) throws IOException { if (locale != null) { // TODO: it'd be nice to allow FieldCache.getStringIndex @@ -488,10 +492,10 @@ case SortField.CUSTOM: assert factory == null && comparatorSource != null; - return comparatorSource.newComparator(field, numHits, sortPos, reversed); + return comparatorSource.newComparator(field, numHits, sortPos, reverse); case SortField.STRING: - return new FieldComparator.StringOrdValComparator(numHits, field, sortPos, reversed); + return new FieldComparator.StringOrdValComparator(numHits, field, sortPos, reverse); case SortField.STRING_VAL: return new FieldComparator.StringValComparator(numHits, field); Index: src/java/org/apache/lucene/search/TopFieldCollector.java =================================================================== --- src/java/org/apache/lucene/search/TopFieldCollector.java (revision 800717) +++ src/java/org/apache/lucene/search/TopFieldCollector.java (working copy) @@ -87,9 +87,8 @@ } public void setNextReader(IndexReader reader, int docBase) throws IOException { - final int numSlotsFull = queueFull ? numHits : totalHits; this.docBase = docBase; - comparator.setNextReader(reader, docBase, numSlotsFull); + comparator.setNextReader(reader, docBase); } public void setScorer(Scorer scorer) throws IOException { @@ -428,10 +427,9 @@ } public void setNextReader(IndexReader reader, int docBase) throws IOException { - final int numSlotsFull = queueFull ? numHits : totalHits; this.docBase = docBase; for (int i = 0; i < comparators.length; i++) { - comparators[i].setNextReader(reader, docBase, numSlotsFull); + comparators[i].setNextReader(reader, docBase); } } Index: contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java =================================================================== --- contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java (revision 800717) +++ contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java (working copy) @@ -210,7 +210,7 @@ bottomValue = slotValues[bottom]; } - public void setNextReader(IndexReader reader, int docBase, int numSlotsFull) throws IOException { + public void setNextReader(IndexReader reader, int docBase) throws IOException { docValues = FieldCache.DEFAULT.getInts(reader, "parser", new FieldCache.IntParser() { public final int parseInt(final String val) { return (val.charAt(0)-'A') * 123456; Index: contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java =================================================================== --- contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java (revision 800717) +++ contrib/spatial/src/java/org/apache/lucene/spatial/tier/DistanceFieldComparatorSource.java (working copy) @@ -108,8 +108,8 @@ } @Override - public void setNextReader(IndexReader reader, int docBase, - int numSlotsFull) throws IOException { + public void setNextReader(IndexReader reader, int docBase) + throws IOException { // each reader in a segmented base // has an offset based on the maxDocs of previous readers @@ -120,12 +120,6 @@ public Comparable