Apache Solr open-source search software
LUCENE-6888: Explain output of map() function now also prints default value
Jan Høydahl0124adb5c109
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex f47326e8597..299cbb21a58 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -273,6 +273,8 @@ Bug Fixes"leak" if you tokenize large strings with many threads across manyindices (Alex Chow via Mike McCandless)+* LUCENE-6888: Explain output of map() function now also prints default value (janhoy)+Other* LUCENE-6478: Test execution can hang with java.security.debug. (Dawid Weiss)diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.javaindex 6319655a35e..210339fdb23 100644--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/RangeMapFloatFunction.java@@ -55,7 +55,7 @@ public class RangeMapFloatFunction extends ValueSource {@Overridepublic String description() {- return "map(" + source.description() + "," + min + "," + max + "," + target.description() + ")";+ return "map(" + source.description() + "," + min + "," + max + "," + target.description() + "," + (defaultVal == null ? "null" : defaultVal.description()) + ")";}@Override@@ -71,7 +71,7 @@ public class RangeMapFloatFunction extends ValueSource {}@Overridepublic String toString(int doc) {- return "map(" + vals.toString(doc) + ",min=" + min + ",max=" + max + ",target=" + targets.toString(doc) + ")";+ return "map(" + vals.toString(doc) + ",min=" + min + ",max=" + max + ",target=" + targets.toString(doc) + ",defaultVal=" + (defaults == null ? "null" : (defaults.toString(doc))) + ")";}};}diff --git a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQueryExplanations.java b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQueryExplanations.javaindex 34dcc59349c..7dbe30faf14 100644--- a/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQueryExplanations.java+++ b/lucene/queries/src/test/org/apache/lucene/queries/function/TestFunctionQueryExplanations.java@@ -18,6 +18,7 @@ package org.apache.lucene.queries.function;*/import org.apache.lucene.queries.function.valuesource.ConstValueSource;+import org.apache.lucene.queries.function.valuesource.RangeMapFloatFunction;import org.apache.lucene.search.BaseExplanationTestCase;import org.apache.lucene.search.BoostQuery;import org.apache.lucene.search.Query;@@ -33,4 +34,17 @@ public class TestFunctionQueryExplanations extends BaseExplanationTestCase {Query q = new BoostQuery(new FunctionQuery(new ConstValueSource(5)), 2);qtest(q, new int[] { 0,1,2,3 });}++ public void testMapFunction() throws Exception {+ ValueSource rff = new RangeMapFloatFunction(new ConstValueSource(3), 0, 1, 2, new Float(4));+ Query q = new FunctionQuery(rff);+ qtest(q, new int[] { 0,1,2,3 });+ assertEquals("map(const(3.0),0.0,1.0,const(2.0),const(4.0))", rff.description());+ assertEquals("map(const(3.0),min=0.0,max=1.0,target=const(2.0),defaultVal=const(4.0))", rff.getValues(null, null).toString(123));++ // DefaultValue is null -> defaults to source value+ rff = new RangeMapFloatFunction(new ConstValueSource(3), 0, 1, 2, null);+ assertEquals("map(const(3.0),0.0,1.0,const(2.0),null)", rff.description());+ assertEquals("map(const(3.0),min=0.0,max=1.0,target=const(2.0),defaultVal=null)", rff.getValues(null, null).toString(123));+ }}