LUCENE-2271: Fix javadocs of TopScoreDocCollector

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@912407 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2010-02-21 21:25:21 +00:00
parent 75c4305fb3
commit 7b9c0f7969
2 changed files with 18 additions and 9 deletions

View File

@ -612,10 +612,10 @@ Changes in backwards compatibility policy
code to implement this method. If you already extend
IndexSearcher, no further changes are needed to use Collector.
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)
Finally, the values Float.NaN and Float.NEGATIVE_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)
* LUCENE-1687: All methods and parsers from the interface ExtendedFieldCache
have been moved into FieldCache. ExtendedFieldCache is now deprecated and
@ -693,7 +693,7 @@ Changes in runtime behavior
* LUCENE-1575: As of 2.9, the core collectors as well as
IndexSearcher's search methods that return top N results, no
longer filter out zero scoring documents. If you rely on this
longer filter documents with scores <= 0.0. If you rely on this
functionality you can use PositiveScoresOnlyCollector like this:
<code>

View File

@ -29,10 +29,10 @@ import org.apache.lucene.index.IndexReader;
* 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.
* <p><b>NOTE</b>: The values {@link Float#NaN} and
* {Float#NEGATIVE_INFINITY} are not valid scores. This
* collector will not properly collect hits with such
* scores.
*/
public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
@ -45,6 +45,11 @@ public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
@Override
public void collect(int doc) throws IOException {
float score = scorer.score();
// This collector cannot handle these scores:
assert score != Float.NEGATIVE_INFINITY;
assert !Float.isNaN(score);
totalHits++;
if (score <= pqTop.score) {
// Since docs are returned in-order (i.e., increasing doc Id), a document
@ -72,6 +77,10 @@ public abstract class TopScoreDocCollector extends TopDocsCollector<ScoreDoc> {
@Override
public void collect(int doc) throws IOException {
float score = scorer.score();
// This collector cannot handle NaN
assert !Float.isNaN(score);
totalHits++;
doc += docBase;
if (score < pqTop.score || (score == pqTop.score && doc > pqTop.doc)) {