Skip to content

Apache Lucene open-source search software

LUCENE-1575: clarify that certain float values are invalid scores

Michael McCandlessd47c46f1a9f2
diff --git a/CHANGES.txt b/CHANGES.txt
index 8d7d34302db..8ab78ea12e2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -27,7 +27,11 @@ Changes in backwards compatibility policy
implement Searchable or extend Searcher, you should change you
code to implement this method. If you already extend
IndexSearcher, no further changes are needed to use Collector.
- (Shai Erera via Mike McCandless)
+
+ Finally, the values Float.Nan, Float.NEGATIVE_INFINITY and
+ Float.POSITIVE_INFINITY are not valid scores. Lucene uses these
+ values internally in certain places, so if you have hits with such
+ scores it will cause problems. (Shai Erera via Mike McCandless)
Changes in runtime behavior
diff --git a/src/java/org/apache/lucene/search/Scorer.java b/src/java/org/apache/lucene/search/Scorer.java
index aaa61c3b4e2..0d5c0c8c9e3 100644
--- a/src/java/org/apache/lucene/search/Scorer.java
+++ b/src/java/org/apache/lucene/search/Scorer.java
@@ -31,6 +31,13 @@ import java.io.IOException;
* Document scores are computed using a given <code>Similarity</code>
* implementation.
* </p>
+ *
+ * <p><b>NOTE</b>: The values Float.Nan,
+ * Float.NEGATIVE_INFINITY and Float.POSITIVE_INFINITY are
+ * not valid scores. Certain collectors (eg {@link
+ * TopScoreDocCollector}) will not properly collect hits
+ * with these scores.
+ *
* @see BooleanQuery#setAllowDocsOutOfOrder
*/
public abstract class Scorer extends DocIdSetIterator {
diff --git a/src/java/org/apache/lucene/search/TopScoreDocCollector.java b/src/java/org/apache/lucene/search/TopScoreDocCollector.java
index 9fdc1dc897b..ec9a1f657f3 100644
--- a/src/java/org/apache/lucene/search/TopScoreDocCollector.java
+++ b/src/java/org/apache/lucene/search/TopScoreDocCollector.java
@@ -28,6 +28,11 @@ import org.apache.lucene.index.IndexReader;
* and then (when the scores are tied) docID ascending. When you create an
* instance of this collector you should know in advance whether documents are
* going to be collected in doc Id order or not.
+ *
+ * <p><b>NOTE</b>: The values Float.Nan,
+ * Float.NEGATIVE_INFINITY and Float.POSITIVE_INFINITY are
+ * not valid scores. This collector will not properly
+ * collect hits with such scores.
*/
public abstract class TopScoreDocCollector extends TopDocsCollector {