mirror of https://github.com/apache/lucene.git
LUCENE-2695: don't create 2 arrays per .score() call
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1021340 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
15134055f9
commit
76c371d5d7
|
@ -33,6 +33,10 @@ class DisjunctionMaxScorer extends Scorer {
|
|||
private final float tieBreakerMultiplier;
|
||||
private int doc = -1;
|
||||
|
||||
/* Used when scoring currently matching doc. */
|
||||
private float scoreSum;
|
||||
private float scoreMax;
|
||||
|
||||
/**
|
||||
* Creates a new instance of DisjunctionMaxScorer
|
||||
*
|
||||
|
@ -90,21 +94,21 @@ class DisjunctionMaxScorer extends Scorer {
|
|||
@Override
|
||||
public float score() throws IOException {
|
||||
int doc = subScorers[0].docID();
|
||||
float[] sum = { subScorers[0].score() }, max = { sum[0] };
|
||||
scoreSum = scoreMax = subScorers[0].score();
|
||||
int size = numScorers;
|
||||
scoreAll(1, size, doc, sum, max);
|
||||
scoreAll(2, size, doc, sum, max);
|
||||
return max[0] + (sum[0] - max[0]) * tieBreakerMultiplier;
|
||||
scoreAll(1, size, doc);
|
||||
scoreAll(2, size, doc);
|
||||
return scoreMax + (scoreSum - scoreMax) * tieBreakerMultiplier;
|
||||
}
|
||||
|
||||
// Recursively iterate all subScorers that generated last doc computing sum and max
|
||||
private void scoreAll(int root, int size, int doc, float[] sum, float[] max) throws IOException {
|
||||
private void scoreAll(int root, int size, int doc) throws IOException {
|
||||
if (root < size && subScorers[root].docID() == doc) {
|
||||
float sub = subScorers[root].score();
|
||||
sum[0] += sub;
|
||||
max[0] = Math.max(max[0], sub);
|
||||
scoreAll((root<<1)+1, size, doc, sum, max);
|
||||
scoreAll((root<<1)+2, size, doc, sum, max);
|
||||
scoreSum += sub;
|
||||
scoreMax = Math.max(scoreMax, sub);
|
||||
scoreAll((root<<1)+1, size, doc);
|
||||
scoreAll((root<<1)+2, size, doc);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue