FileDocCategorySizeDatePackage
Scorer.javaAPI DocApache Lucene 2.1.04268Wed Feb 14 10:46:40 GMT 2007org.apache.lucene.search

Scorer

public abstract class Scorer extends Object
Expert: Common scoring functionality for different types of queries.
A Scorer either iterates over documents matching a query, or provides an explanation of the score for a query for a given document.
Document scores are computed using a given Similarity implementation.

Fields Summary
private Similarity
similarity
Constructors Summary
protected Scorer(Similarity similarity)
Constructs a Scorer.

param
similarity The Similarity implementation used by this scorer.

    this.similarity = similarity;
  
Methods Summary
public abstract intdoc()
Returns the current document number matching the query. Initially invalid, until {@link #next()} is called the first time.

public abstract org.apache.lucene.search.Explanationexplain(int doc)
Returns an explanation of the score for a document.
When this method is used, the {@link #next()}, {@link #skipTo(int)} and {@link #score(HitCollector)} methods should not be used.

param
doc The document number for the explanation.

public org.apache.lucene.search.SimilaritygetSimilarity()
Returns the Similarity implementation used by this scorer.

    return this.similarity;
  
public abstract booleannext()
Advances to the next document matching the query.

return
true iff there is another document matching the query.
When this method is used the {@link #explain(int)} method should not be used.

public voidscore(org.apache.lucene.search.HitCollector hc)
Scores and collects all matching documents.

param
hc The collector to which all matching documents are passed through {@link HitCollector#collect(int, float)}.
When this method is used the {@link #explain(int)} method should not be used.

    while (next()) {
      hc.collect(doc(), score());
    }
  
protected booleanscore(org.apache.lucene.search.HitCollector hc, int max)
Expert: Collects matching documents in a range. Hook for optimization. Note that {@link #next()} must be called once before this method is called for the first time.

param
hc The collector to which all matching documents are passed through {@link HitCollector#collect(int, float)}.
param
max Do not score documents past this.
return
true if more matching documents may remain.

    while (doc() < max) {
      hc.collect(doc(), score());
      if (!next())
        return false;
    }
    return true;
  
public abstract floatscore()
Returns the score of the current document matching the query. Initially invalid, until {@link #next()} or {@link #skipTo(int)} is called the first time.

public abstract booleanskipTo(int target)
Skips to the first match beyond the current whose document number is greater than or equal to a given target.
When this method is used the {@link #explain(int)} method should not be used.

param
target The target document number.
return
true iff there is such a match.

Behaves as if written:

boolean skipTo(int target) {
do {
if (!next())
return false;
} while (target > doc());
return true;
}
Most implementations are considerably more efficient than that.