Index: lucene/contrib/queries/src/java/org/apache/lucene/search/SlowCollatedStringComparator.java
--- lucene/contrib/queries/src/java/org/apache/lucene/search/SlowCollatedStringComparator.java Fri Jun 10 16:56:32 2011 -0400
+++ lucene/contrib/queries/src/java/org/apache/lucene/search/SlowCollatedStringComparator.java Fri Jun 10 19:38:21 2011 -0400
@@ -33,7 +33,7 @@
* This class will be removed in Lucene 5.0
*/
@Deprecated
-public final class SlowCollatedStringComparator extends FieldComparator {
+public final class SlowCollatedStringComparator extends FieldComparatorvalue method corresponding
+ * FieldComparator used to sort this field.
* @see Sort
* @see IndexSearcher#search(Query,Filter,int,Sort)
*/
- public Comparable[] fields;
+ public Object[] fields;
/** Expert: Creates one of these objects with empty sort information. */
public FieldDoc (int doc, float score) {
@@ -53,7 +54,7 @@
}
/** Expert: Creates one of these objects with the given sort information. */
- public FieldDoc (int doc, float score, Comparable[] fields) {
+ public FieldDoc (int doc, float score, Object[] fields) {
super (doc, score);
this.fields = fields;
}
Index: lucene/src/java/org/apache/lucene/search/FieldValueHitQueue.java
--- lucene/src/java/org/apache/lucene/search/FieldValueHitQueue.java Fri Jun 10 16:56:32 2011 -0400
+++ lucene/src/java/org/apache/lucene/search/FieldValueHitQueue.java Fri Jun 10 19:38:21 2011 -0400
@@ -200,7 +200,7 @@
*/
FieldDoc fillFields(final Entry entry) {
final int n = comparators.length;
- final Comparable>[] fields = new Comparable[n];
+ final Object[] fields = new Object[n];
for (int i = 0; i < n; ++i) {
fields[i] = comparators[i].value(entry.slot);
}
Index: lucene/src/java/org/apache/lucene/search/IndexSearcher.java
--- lucene/src/java/org/apache/lucene/search/IndexSearcher.java Fri Jun 10 16:56:32 2011 -0400
+++ lucene/src/java/org/apache/lucene/search/IndexSearcher.java Fri Jun 10 19:38:21 2011 -0400
@@ -443,7 +443,7 @@
* Collector)}.
type is SCORE or DOC.
* @param type Type of values in the terms.
*/
- public SortField (String field, int type) {
+ public SortField(String field, int type) {
initFieldType(field, type);
}
@@ -122,7 +122,7 @@
* @param type Type of values in the terms.
* @param reverse True if natural order should be reversed.
*/
- public SortField (String field, int type, boolean reverse) {
+ public SortField(String field, int type, boolean reverse) {
initFieldType(field, type);
this.reverse = reverse;
}
@@ -140,7 +140,7 @@
* @deprecated (4.0) use EntryCreator version
*/
@Deprecated
- public SortField (String field, FieldCache.Parser parser) {
+ public SortField(String field, FieldCache.Parser parser) {
this(field, parser, false);
}
@@ -158,7 +158,7 @@
* @deprecated (4.0) use EntryCreator version
*/
@Deprecated
- public SortField (String field, FieldCache.Parser parser, boolean reverse) {
+ public SortField(String field, FieldCache.Parser parser, boolean reverse) {
if (field == null) {
throw new IllegalArgumentException("field can only be null when type is SCORE or DOC");
}
@@ -225,7 +225,7 @@
* @param field Name of field to sort by; cannot be null.
* @param comparator Returns a comparator for sorting hits.
*/
- public SortField (String field, FieldComparatorSource comparator) {
+ public SortField(String field, FieldComparatorSource comparator) {
initFieldType(field, CUSTOM);
this.comparatorSource = comparator;
}
@@ -235,7 +235,7 @@
* @param comparator Returns a comparator for sorting hits.
* @param reverse True if natural order should be reversed.
*/
- public SortField (String field, FieldComparatorSource comparator, boolean reverse) {
+ public SortField(String field, FieldComparatorSource comparator, boolean reverse) {
initFieldType(field, CUSTOM);
this.reverse = reverse;
this.comparatorSource = comparator;
Index: lucene/src/java/org/apache/lucene/search/TopDocs.java
--- lucene/src/java/org/apache/lucene/search/TopDocs.java Fri Jun 10 16:56:32 2011 -0400
+++ lucene/src/java/org/apache/lucene/search/TopDocs.java Fri Jun 10 19:38:21 2011 -0400
@@ -17,6 +17,10 @@
* limitations under the License.
*/
+import java.io.IOException;
+
+import org.apache.lucene.util.PriorityQueue;
+
/** Represents hits returned by {@link
* IndexSearcher#search(Query,Filter,int)} and {@link
* IndexSearcher#search(Query,int)}. */
@@ -52,4 +56,212 @@
this.scoreDocs = scoreDocs;
this.maxScore = maxScore;
}
+
+ // Refers to one hit:
+ private static class ShardRef {
+ // Which shard (index into shardHits[]):
+ final int shardIndex;
+
+ // Which hit within the shard:
+ int hitIndex;
+
+ public ShardRef(int shardIndex) {
+ this.shardIndex = shardIndex;
+ }
+
+ @Override
+ public String toString() {
+ return "ShardRef(shardIndex=" + shardIndex + " hitIndex=" + hitIndex + ")";
+ }
+ };
+
+ // Specialized MergeSortQueue that just merges by
+ // relevance score, descending:
+ private static class ScoreMergeSortQueue extends PriorityQueuehits.scoreDocs */
+ public final int[] shardIndex;
+
+ public TopDocsAndShards(TopDocs hits, int[] shardIndex) {
+ this.hits = hits;
+ this.shardIndex = shardIndex;
+ }
+ }
+
+ /** Returns a new TopDocs, containing topN results across
+ * the provided TopDocs, sorting by the specified {@link
+ * Sort}. Each of the TopDocs must have been sorted by
+ * the same Sort, and sort field values must have been
+ * filled (ie, fillFields=true must be
+ * passed to {@link
+ * TopFieldCollector#create}.
+ *
+ * Pass sort=null to merge sort by score descending.
+ *
+ * @lucene.experimental */
+ public static TopDocsAndShards merge(Sort sort, int topN, TopDocs[] shardHits) throws IOException {
+
+ final PriorityQueue