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

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@835090 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-11-11 21:58:05 +00:00
parent 5b83cc59b2
commit b50794e1ec
4 changed files with 25 additions and 27 deletions

View File

@ -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.

View File

@ -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. */

View File

@ -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();
}
}

View File

@ -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);
}
}
}