mirror of https://github.com/apache/lucene.git
Do not construct a ScoreDoc for every non-zero hit, but only for those
in the current top scoring set. This makes a substantial performance improvement for queries that match lots of documents. git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150528 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0a5fab187b
commit
b85006589c
|
@ -90,11 +90,15 @@ public class IndexSearcher extends Searcher {
|
||||||
final HitQueue hq = new HitQueue(nDocs);
|
final HitQueue hq = new HitQueue(nDocs);
|
||||||
final int[] totalHits = new int[1];
|
final int[] totalHits = new int[1];
|
||||||
scorer.score(new HitCollector() {
|
scorer.score(new HitCollector() {
|
||||||
|
private float minScore = 0.0f;
|
||||||
public final void collect(int doc, float score) {
|
public final void collect(int doc, float score) {
|
||||||
if (score > 0.0f && // ignore zeroed buckets
|
if (score > 0.0f && // ignore zeroed buckets
|
||||||
(bits==null || bits.get(doc))) { // skip docs not in bits
|
(bits==null || bits.get(doc))) { // skip docs not in bits
|
||||||
totalHits[0]++;
|
totalHits[0]++;
|
||||||
|
if (hq.size() < nDocs || score >= minScore) {
|
||||||
hq.insert(new ScoreDoc(doc, score));
|
hq.insert(new ScoreDoc(doc, score));
|
||||||
|
minScore = ((ScoreDoc)hq.top()).score; // maintain minScore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -119,11 +123,15 @@ public class IndexSearcher extends Searcher {
|
||||||
new FieldSortedHitQueue(reader, sort.fields, nDocs);
|
new FieldSortedHitQueue(reader, sort.fields, nDocs);
|
||||||
final int[] totalHits = new int[1];
|
final int[] totalHits = new int[1];
|
||||||
scorer.score(new HitCollector() {
|
scorer.score(new HitCollector() {
|
||||||
|
private float minScore = 0.0f;
|
||||||
public final void collect(int doc, float score) {
|
public final void collect(int doc, float score) {
|
||||||
if (score > 0.0f && // ignore zeroed buckets
|
if (score > 0.0f && // ignore zeroed buckets
|
||||||
(bits==null || bits.get(doc))) { // skip docs not in bits
|
(bits==null || bits.get(doc))) { // skip docs not in bits
|
||||||
totalHits[0]++;
|
totalHits[0]++;
|
||||||
|
if (hq.size() < nDocs || score >= minScore) {
|
||||||
hq.insert(new FieldDoc(doc, score));
|
hq.insert(new FieldDoc(doc, score));
|
||||||
|
minScore = ((FieldDoc)hq.top()).score; // maintain minScore
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue