using emptySortedNumericDoubles instead of null in score function

This commit is contained in:
André Carvalho 2015-08-24 09:19:45 -03:00
parent 345b2b98cf
commit 60ab72e322
1 changed files with 4 additions and 8 deletions

View File

@ -22,6 +22,7 @@ package org.elasticsearch.common.lucene.search.function;
import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.Explanation; import org.apache.lucene.search.Explanation;
import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.index.fielddata.FieldData;
import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues;
@ -56,7 +57,7 @@ public class FieldValueFactorFunction extends ScoreFunction {
public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) { public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) {
final SortedNumericDoubleValues values; final SortedNumericDoubleValues values;
if(indexFieldData == null) { if(indexFieldData == null) {
values = null; values = FieldData.emptySortedNumericDoubles(0);
} else { } else {
values = this.indexFieldData.load(ctx).getDoubleValues(); values = this.indexFieldData.load(ctx).getDoubleValues();
} }
@ -65,13 +66,8 @@ public class FieldValueFactorFunction extends ScoreFunction {
@Override @Override
public double score(int docId, float subQueryScore) { public double score(int docId, float subQueryScore) {
final int numValues;
if(values == null){
numValues = 0;
} else {
values.setDocument(docId); values.setDocument(docId);
numValues = values.count(); final int numValues = values.count();
}
double value; double value;
if (numValues > 0) { if (numValues > 0) {
value = values.valueAt(0); value = values.valueAt(0);