diff --git a/src/main/java/org/elasticsearch/common/lucene/search/function/FunctionScoreQuery.java b/src/main/java/org/elasticsearch/common/lucene/search/function/FunctionScoreQuery.java index 19135535c14..b2ef9ca9c0a 100644 --- a/src/main/java/org/elasticsearch/common/lucene/search/function/FunctionScoreQuery.java +++ b/src/main/java/org/elasticsearch/common/lucene/search/function/FunctionScoreQuery.java @@ -200,8 +200,13 @@ public class FunctionScoreQuery extends Query { } public static float toFloat(double input) { - assert Double.compare(((float) input), input) == 0 || (Math.abs(((float) input) - input) <= 0.001) : "input " + input + " out of float scope for function score"; + assert deviation(input) <= 0.001 : "input " + input + " out of float scope for function score deviation: " + deviation(input); return (float) input; } + + private static double deviation(double input) { // only with assert! + float floatVersion = (float)input; + return Double.compare(floatVersion, input) == 0 || input == 0.0d ? 0 : 1.d-(floatVersion) / input; + } } diff --git a/src/test/java/org/elasticsearch/test/integration/search/functionscore/FunctionScorePluginTests.java b/src/test/java/org/elasticsearch/test/integration/search/functionscore/FunctionScorePluginTests.java index fa655917f5e..51f9bb4018e 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/functionscore/FunctionScorePluginTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/functionscore/FunctionScorePluginTests.java @@ -21,7 +21,6 @@ package org.elasticsearch.test.integration.search.functionscore; import org.apache.lucene.search.ComplexExplanation; import org.apache.lucene.search.Explanation; -import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.action.ActionFuture; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; @@ -62,7 +61,6 @@ public class FunctionScorePluginTests extends AbstractNodesTests { } @Test - @LuceneTestCase.AwaitsFix(bugUrl = "britta to look into it, it creates a double value that fails the toFloat assertion") public void testPlugin() throws Exception { ImmutableSettings.Builder settings = settingsBuilder().put("plugin.types", CustomDistanceScorePlugin.class.getName()); startNode("server1", settings);