From 60ab72e32246cd301b194faaebff91f7c25ef6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Carvalho?= Date: Mon, 24 Aug 2015 09:19:45 -0300 Subject: [PATCH] using emptySortedNumericDoubles instead of null in score function --- .../search/function/FieldValueFactorFunction.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/lucene/search/function/FieldValueFactorFunction.java b/core/src/main/java/org/elasticsearch/common/lucene/search/function/FieldValueFactorFunction.java index e6d1362f9e7..38c2cc98a2e 100644 --- a/core/src/main/java/org/elasticsearch/common/lucene/search/function/FieldValueFactorFunction.java +++ b/core/src/main/java/org/elasticsearch/common/lucene/search/function/FieldValueFactorFunction.java @@ -22,6 +22,7 @@ package org.elasticsearch.common.lucene.search.function; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.search.Explanation; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.index.fielddata.FieldData; import org.elasticsearch.index.fielddata.IndexNumericFieldData; import org.elasticsearch.index.fielddata.SortedNumericDoubleValues; @@ -56,7 +57,7 @@ public class FieldValueFactorFunction extends ScoreFunction { public LeafScoreFunction getLeafScoreFunction(LeafReaderContext ctx) { final SortedNumericDoubleValues values; if(indexFieldData == null) { - values = null; + values = FieldData.emptySortedNumericDoubles(0); } else { values = this.indexFieldData.load(ctx).getDoubleValues(); } @@ -65,13 +66,8 @@ public class FieldValueFactorFunction extends ScoreFunction { @Override public double score(int docId, float subQueryScore) { - final int numValues; - if(values == null){ - numValues = 0; - } else { - values.setDocument(docId); - numValues = values.count(); - } + values.setDocument(docId); + final int numValues = values.count(); double value; if (numValues > 0) { value = values.valueAt(0);