Apache Lucene open-source search software
optimize NaN and -Inf check
Yonik Seeley2e5960f5e69d
diff --git a/src/java/org/apache/solr/search/function/BoostedQuery.java b/src/java/org/apache/solr/search/function/BoostedQuery.javaindex 93551142187..37f518d0348 100755--- a/src/java/org/apache/solr/search/function/BoostedQuery.java+++ b/src/java/org/apache/solr/search/function/BoostedQuery.java@@ -122,9 +122,10 @@ public class BoostedQuery extends Query {public float score() throws IOException {float score = qWeight * scorer.score() * vals.floatVal(scorer.doc());- // current Lucene sorting priority queues can't handle NaN (score!=score is true for NaN) and -Infinity- if (score != score || score==Float.NEGATIVE_INFINITY) return -Float.MAX_VALUE;- return score;+ // Current Lucene priority queues can't handle NaN and -Infinity, so+ // map to -Float.MAX_VALUE. This conditional handles both -infinity+ // and NaN since comparisons with NaN are always false.+ return score>Float.NEGATIVE_INFINITY ? score : -Float.MAX_VALUE;}public boolean skipTo(int target) throws IOException {diff --git a/src/java/org/apache/solr/search/function/FunctionQuery.java b/src/java/org/apache/solr/search/function/FunctionQuery.javaindex 07a718f2c41..b643ad9fce3 100644--- a/src/java/org/apache/solr/search/function/FunctionQuery.java+++ b/src/java/org/apache/solr/search/function/FunctionQuery.java@@ -133,9 +133,10 @@ public class FunctionQuery extends Query {public float score() throws IOException {float score = qWeight * vals.floatVal(doc);- // current Lucene sorting priority queues can't handle NaN (score!=score is true for NaN) and -Infinity- if (score != score || score==Float.NEGATIVE_INFINITY) return -Float.MAX_VALUE;- return score;+ // Current Lucene priority queues can't handle NaN and -Infinity, so+ // map to -Float.MAX_VALUE. This conditional handles both -infinity+ // and NaN since comparisons with NaN are always false.+ return score>Float.NEGATIVE_INFINITY ? score : -Float.MAX_VALUE;}public boolean skipTo(int target) throws IOException {