You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by yo...@apache.org on 2009/06/08 16:47:23 UTC

svn commit: r782657 - in /lucene/solr/trunk/src/java/org/apache/solr/search/function: BoostedQuery.java FunctionQuery.java

Author: yonik
Date: Mon Jun  8 14:47:23 2009
New Revision: 782657

URL: http://svn.apache.org/viewvc?rev=782657&view=rev
Log:
optimize NaN and -Inf check

Modified:
    lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java
    lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java?rev=782657&r1=782656&r2=782657&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/BoostedQuery.java Mon Jun  8 14:47:23 2009
@@ -122,9 +122,10 @@
     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 {

Modified: lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java?rev=782657&r1=782656&r2=782657&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/FunctionQuery.java Mon Jun  8 14:47:23 2009
@@ -133,9 +133,10 @@
     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 {