Apache Lucene open-source search software
Oops. Fixed a bug I introduced in my last change. Thanks to Cristoph for catching this! I overgeneralized. Sorted results are not always the highest scoring.
Doug Cutting1b8843fa0423
diff --git a/src/java/org/apache/lucene/search/IndexSearcher.java b/src/java/org/apache/lucene/search/IndexSearcher.javaindex 2b020a6eca0..adc0cce3c06 100644--- a/src/java/org/apache/lucene/search/IndexSearcher.java+++ b/src/java/org/apache/lucene/search/IndexSearcher.java@@ -123,15 +123,11 @@ public class IndexSearcher extends Searcher {new FieldSortedHitQueue(reader, sort.fields, nDocs);final int[] totalHits = new int[1];scorer.score(new HitCollector() {- private float minScore = 0.0f;public final void collect(int doc, float score) {- if (score > 0.0f && // ignore zeroed buckets- (bits==null || bits.get(doc))) { // skip docs not in bits+ if (score > 0.0f && // ignore zeroed buckets+ (bits==null || bits.get(doc))) { // skip docs not in bitstotalHits[0]++;- if (hq.size() < nDocs || score >= minScore) {- hq.insert(new FieldDoc(doc, score));- minScore = ((FieldDoc)hq.top()).score; // maintain minScore- }+ hq.insert(new FieldDoc(doc, score));}}});