ScoringRewrite (Lucene 10.5.1 core API)
Description: declaration: package: org.apache.lucene.search, class: ScoringRewrite

Package org.apache.lucene.search

# Class ScoringRewrite<B>

java.lang.Object
org.apache.lucene.search.MultiTermQuery.RewriteMethod
org.apache.lucene.search.ScoringRewrite<B>

public abstract class ScoringRewrite<B> extends MultiTermQuery.RewriteMethod
Base rewrite method that translates each term into a query, and keeps the scores as computed by the query.

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
  Only public to be accessible by spans package.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final MultiTermQuery.RewriteMethod`
  `CONSTANT_SCORE_BOOLEAN_REWRITE`
  Like `SCORING_BOOLEAN_REWRITE` except scores are not computed.
  `static final ScoringRewrite<BooleanQuery.Builder>`
  `SCORING_BOOLEAN_REWRITE`
  A rewrite method that first translates each term into `BooleanClause.Occur.SHOULD` clause in a BooleanQuery, and keeps the scores as computed by the query.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ScoringRewrite()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected final void`
  `addClause(B topLevel, Term term, int docCount, float boost)`
  Add a MultiTermQuery term to the top-level query builder.
  `protected abstract void`
  `addClause(B topLevel, Term term, int docCount, float boost, TermStates states)`
  `protected abstract Query`
  `build(B builder)`
  Finalize the creation of the query from the builder.
  `protected abstract void`
  `checkMaxClauseCount(int count)`
  This method is called after every new term to check if the number of max clauses (e.g.
  `protected abstract B`
  `getTopLevelBuilder()`
  Return a suitable builder for the top-level Query for holding all expanded terms.
  `final Query`
  `rewrite(IndexSearcher indexSearcher, MultiTermQuery query)`

  ### Methods inherited from class org.apache.lucene.search.MultiTermQuery.RewriteMethod

  `getTermsEnum`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### SCORING_BOOLEAN_REWRITE

    public static final ScoringRewrite<BooleanQuery.Builder> SCORING_BOOLEAN_REWRITE
    A rewrite method that first translates each term into `BooleanClause.Occur.SHOULD` clause in a BooleanQuery, and keeps the scores as computed by the query. Note that typically such scores are meaningless to the user, and require non-trivial CPU to compute, so it's almost always better to use `MultiTermQuery.CONSTANT_SCORE_BLENDED_REWRITE` or `MultiTermQuery.CONSTANT_SCORE_REWRITE` instead.

    NOTE: This rewrite method will hit `IndexSearcher.TooManyClauses` if the number of terms exceeds `IndexSearcher.getMaxClauseCount()`.

  - ### CONSTANT_SCORE_BOOLEAN_REWRITE

    public static final MultiTermQuery.RewriteMethod CONSTANT_SCORE_BOOLEAN_REWRITE
    Like `SCORING_BOOLEAN_REWRITE` except scores are not computed. Instead, each matching document receives a constant score equal to the query's boost.

    NOTE: This rewrite method will hit `IndexSearcher.TooManyClauses` if the number of terms exceeds `IndexSearcher.getMaxClauseCount()`.

- ## Constructor Details

  - ### ScoringRewrite

    public ScoringRewrite()

- ## Method Details

  - ### checkMaxClauseCount

    protected abstract void checkMaxClauseCount(int count) throws IOException
    This method is called after every new term to check if the number of max clauses (e.g. in BooleanQuery) is not exceeded. Throws the corresponding `RuntimeException`.
    Throws:
      `IOException`

  - ### rewrite

    public final Query rewrite(IndexSearcher indexSearcher, MultiTermQuery query) throws IOException
    Specified by:
      `rewrite` in class `MultiTermQuery.RewriteMethod`
    Throws:
      `IOException`

  - ### getTopLevelBuilder

    protected abstract B getTopLevelBuilder() throws IOException
    Return a suitable builder for the top-level Query for holding all expanded terms.
    Throws:
      `IOException`

  - ### build

    protected abstract Query build(B builder)
    Finalize the creation of the query from the builder.

  - ### addClause

    protected final void addClause(B topLevel, Term term, int docCount, float boost) throws IOException
    Add a MultiTermQuery term to the top-level query builder.
    Throws:
      `IOException`

  - ### addClause

    protected abstract void addClause(B topLevel, Term term, int docCount, float boost, TermStates states) throws IOException
    Throws:
      `IOException`