FileDocCategorySizeDatePackage
ReqOptSumScorer.javaAPI DocApache Lucene 1.93099Mon Feb 20 09:20:04 GMT 2006org.apache.lucene.search

ReqOptSumScorer

public class ReqOptSumScorer extends Scorer
A Scorer for queries with a required part and an optional part. Delays skipTo() on the optional part until a score() is needed.
This Scorer implements {@link Scorer#skipTo(int)}.

Fields Summary
private Scorer
reqScorer
The scorers passed from the constructor. These are set to null as soon as their next() or skipTo() returns false.
private Scorer
optScorer
private boolean
firstTimeOptScorer
Constructors Summary
public ReqOptSumScorer(Scorer reqScorer, Scorer optScorer)
Construct a ReqOptScorer.

param
reqScorer The required scorer. This must match.
param
optScorer The optional scorer. This is used for scoring only.

    super(null); // No similarity used.
    this.reqScorer = reqScorer;
    this.optScorer = optScorer;
  
Methods Summary
public intdoc()

    return reqScorer.doc();
  
public org.apache.lucene.search.Explanationexplain(int doc)
Explain the score of a document.

todo
Also show the total score. See BooleanScorer.explain() on how to do this.

    Explanation res = new Explanation();
    res.setDescription("required, optional");
    res.addDetail(reqScorer.explain(doc));
    res.addDetail(optScorer.explain(doc));
    return res;
  
public booleannext()


       
    return reqScorer.next();
  
public floatscore()
Returns the score of the current document matching the query. Initially invalid, until {@link #next()} is called the first time.

return
The score of the required scorer, eventually increased by the score of the optional scorer when it also matches the current document.

    int curDoc = reqScorer.doc();
    float reqScore = reqScorer.score();
    if (firstTimeOptScorer) {
      firstTimeOptScorer = false;
      if (! optScorer.skipTo(curDoc)) {
        optScorer = null;
        return reqScore;
      }
    } else if (optScorer == null) {
      return reqScore;
    } else if ((optScorer.doc() < curDoc) && (! optScorer.skipTo(curDoc))) {
      optScorer = null;
      return reqScore;
    }
    // assert (optScorer != null) && (optScorer.doc() >= curDoc);
    return (optScorer.doc() == curDoc)
       ? reqScore + optScorer.score()
       : reqScore;
  
public booleanskipTo(int target)

    return reqScorer.skipTo(target);