Skip to content

Apache Lucene open-source search software

LUCENE-2057: TopDocsCollector should have bounded generic <T extends ScoreDoc>

Uwe Schindlerb50794e1ec64
diff --git a/CHANGES.txt b/CHANGES.txt
index 54f28364af4..5aec5abc272 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -42,8 +42,9 @@ Changes in runtime behavior
API Changes
-* LUCENE-1257, LUCENE-1984, LUCENE-1985, ...: Port to Java 1.5 [not yet finished].
- (Uwe Schindler, Robert Muir, Karl Wettin, Paul Elschot, Kay Kay)
+* LUCENE-1257, LUCENE-1984, LUCENE-1985, LUCENE-2057,...: Port to Java 1.5
+ [not yet finished]. (Uwe Schindler, Robert Muir, Karl Wettin, Paul Elschot,
+ Kay Kay, Shai Erera)
* LUCENE-1944: Remove (all) deprecated methods/constructors taking
String/File directory pathes in IndexReader / IndexWriter and others.
diff --git a/src/java/org/apache/lucene/search/FieldValueHitQueue.java b/src/java/org/apache/lucene/search/FieldValueHitQueue.java
index 50c8241681e..75d4bba7481 100644
--- a/src/java/org/apache/lucene/search/FieldValueHitQueue.java
+++ b/src/java/org/apache/lucene/search/FieldValueHitQueue.java
@@ -36,20 +36,17 @@ import org.apache.lucene.util.PriorityQueue;
*/
public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueue.Entry> {
- final static class Entry {
+ final static class Entry extends ScoreDoc {
int slot;
- int docID;
- float score;
- Entry(int slot, int docID, float score) {
+ Entry(int slot, int doc, float score) {
+ super(doc, score);
this.slot = slot;
- this.docID = docID;
- this.score = score;
}
@Override
public String toString() {
- return "slot:" + slot + " docID:" + docID + " score=" + score;
+ return "slot:" + slot + " " + super.toString();
}
}
@@ -97,7 +94,7 @@ public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueu
}
// avoid random sort order that could lead to duplicates (bug #31241):
- return hitA.docID > hitB.docID;
+ return hitA.doc > hitB.doc;
}
}
@@ -139,7 +136,7 @@ public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueu
}
// avoid random sort order that could lead to duplicates (bug #31241):
- return hitA.docID > hitB.docID;
+ return hitA.doc > hitB.doc;
}
}
@@ -214,7 +211,7 @@ public abstract class FieldValueHitQueue extends PriorityQueue<FieldValueHitQueu
fields[i] = comparators[i].value(entry.slot);
}
//if (maxscore > 1.0f) doc.score /= maxscore; // normalize scores
- return new FieldDoc(entry.docID, entry.score, fields);
+ return new FieldDoc(entry.doc, entry.score, fields);
}
/** Returns the SortFields being used by this hit queue. */
diff --git a/src/java/org/apache/lucene/search/TopDocsCollector.java b/src/java/org/apache/lucene/search/TopDocsCollector.java
index 63f792e450d..5d007a7143e 100644
--- a/src/java/org/apache/lucene/search/TopDocsCollector.java
+++ b/src/java/org/apache/lucene/search/TopDocsCollector.java
@@ -28,7 +28,7 @@ import org.apache.lucene.util.PriorityQueue;
* Extending classes can override {@link #topDocs(int, int)} and
* {@link #getTotalHits()} in order to provide their own implementation.
*/
-public abstract class TopDocsCollector<T> extends Collector {
+public abstract class TopDocsCollector<T extends ScoreDoc> extends Collector {
// This is used in case topDocs() is called with illegal parameters, or there
// simply aren't (enough) results.
@@ -55,7 +55,7 @@ public abstract class TopDocsCollector<T> extends Collector {
*/
protected void populateResults(ScoreDoc[] results, int howMany) {
for (int i = howMany - 1; i >= 0; i--) {
- results[i] = (ScoreDoc) pq.pop();
+ results[i] = pq.pop();
}
}
diff --git a/src/java/org/apache/lucene/search/TopFieldCollector.java b/src/java/org/apache/lucene/search/TopFieldCollector.java
index 0b41534d0fe..a39567e1ca2 100644
--- a/src/java/org/apache/lucene/search/TopFieldCollector.java
+++ b/src/java/org/apache/lucene/search/TopFieldCollector.java
@@ -59,7 +59,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
final void updateBottom(int doc) {
// bottom.score is already set to Float.NaN in add().
- bottom.docID = docBase + doc;
+ bottom.doc = docBase + doc;
bottom = pq.updateTop();
}
@@ -122,7 +122,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
if (queueFull) {
// Fastmatch: return if this hit is not competitive
final int cmp = reverseMul * comparator.compareBottom(doc);
- if (cmp < 0 || (cmp == 0 && doc + docBase > bottom.docID)) {
+ if (cmp < 0 || (cmp == 0 && doc + docBase > bottom.doc)) {
return;
}
@@ -164,7 +164,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
}
final void updateBottom(int doc, float score) {
- bottom.docID = docBase + doc;
+ bottom.doc = docBase + doc;
bottom.score = score;
bottom = pq.updateTop();
}
@@ -230,7 +230,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
if (queueFull) {
// Fastmatch: return if this hit is not competitive
final int cmp = reverseMul * comparator.compareBottom(doc);
- if (cmp < 0 || (cmp == 0 && doc + docBase > bottom.docID)) {
+ if (cmp < 0 || (cmp == 0 && doc + docBase > bottom.doc)) {
return;
}
@@ -280,7 +280,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
}
final void updateBottom(int doc, float score) {
- bottom.docID = docBase + doc;
+ bottom.doc = docBase + doc;
bottom.score = score;
bottom = pq.updateTop();
}
@@ -347,7 +347,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
if (queueFull) {
// Fastmatch: return if this hit is not competitive
final int cmp = reverseMul * comparator.compareBottom(doc);
- if (cmp < 0 || (cmp == 0 && doc + docBase > bottom.docID)) {
+ if (cmp < 0 || (cmp == 0 && doc + docBase > bottom.doc)) {
return;
}
@@ -392,7 +392,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
final void updateBottom(int doc) {
// bottom.score is already set to Float.NaN in add().
- bottom.docID = docBase + doc;
+ bottom.doc = docBase + doc;
bottom = pq.updateTop();
}
@@ -488,7 +488,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
break;
} else if (i == comparators.length - 1) {
// This is the equals case.
- if (doc + docBase > bottom.docID) {
+ if (doc + docBase > bottom.doc) {
// Definitely not competitive
return;
}
@@ -545,7 +545,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
}
final void updateBottom(int doc, float score) {
- bottom.docID = docBase + doc;
+ bottom.doc = docBase + doc;
bottom.score = score;
bottom = pq.updateTop();
}
@@ -640,7 +640,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
break;
} else if (i == comparators.length - 1) {
// This is the equals case.
- if (doc + docBase > bottom.docID) {
+ if (doc + docBase > bottom.doc) {
// Definitely not competitive
return;
}
@@ -695,7 +695,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
}
final void updateBottom(int doc, float score) {
- bottom.docID = docBase + doc;
+ bottom.doc = docBase + doc;
bottom.score = score;
bottom = pq.updateTop();
}
@@ -788,7 +788,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
break;
} else if (i == comparators.length - 1) {
// This is the equals case.
- if (doc + docBase > bottom.docID) {
+ if (doc + docBase > bottom.doc) {
// Definitely not competitive
return;
}
@@ -972,7 +972,7 @@ public abstract class TopFieldCollector extends TopDocsCollector<Entry> {
} else {
for (int i = howMany - 1; i >= 0; i--) {
Entry entry = pq.pop();
- results[i] = new FieldDoc(entry.docID, entry.score);
+ results[i] = new FieldDoc(entry.doc, entry.score);
}
}
}