Class ScoreCachingWrappingScorer

java.lang.Object
org.apache.lucene.search.Scorable
org.apache.lucene.search.ScoreCachingWrappingScorer

public final class ScoreCachingWrappingScorer extends Scorable
A Scorer which wraps another scorer and caches the score of the current document. Successive calls to score() will return the same result and will not invoke the wrapped Scorer's score() method, unless the current document has changed.
This class might be useful due to the changes done to the Collector interface, in which the score is not computed for a document by default, only if the collector requests it. Some collectors may need to use the score in several places, however all they have in hand is a Scorer object, and might end up computing the score of a document more than once.
  • Method Details

    • wrap

      public static LeafCollector wrap(LeafCollector collector)
      Wrap the provided LeafCollector so that scores are computed lazily and cached if accessed multiple times.
    • score

      public float score() throws IOException
      Description copied from class: Scorable
      Returns the score of the current document matching the query.
      Specified by:
      score in class Scorable
      Throws:
      IOException
    • setMinCompetitiveScore

      public void setMinCompetitiveScore(float minScore) throws IOException
      Description copied from class: Scorable
      Optional method: Tell the scorer that its iterator may safely ignore all documents whose score is less than the given minScore. This is a no-op by default.

      This method may only be called from collectors that use ScoreMode.TOP_SCORES, and successive calls may only set increasing values of minScore.

      Overrides:
      setMinCompetitiveScore in class Scorable
      Throws:
      IOException
    • getChildren

      public Collection<Scorable.ChildScorable> getChildren()
      Description copied from class: Scorable
      Returns child sub-scorers positioned on the current document
      Overrides:
      getChildren in class Scorable