You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2010/10/11 15:25:21 UTC
svn commit: r1021340 -
/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
Author: mikemccand
Date: Mon Oct 11 13:25:20 2010
New Revision: 1021340
URL: http://svn.apache.org/viewvc?rev=1021340&view=rev
Log:
LUCENE-2695: don't create 2 arrays per .score() call
Modified:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java?rev=1021340&r1=1021339&r2=1021340&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/DisjunctionMaxScorer.java Mon Oct 11 13:25:20 2010
@@ -33,6 +33,10 @@ class DisjunctionMaxScorer extends Score
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 Score
@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);
}
}