MultiTermQuery.TopTermsScoringBooleanQueryRewrite (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.search, class: MultiTermQuery, class: TopTermsScoringBooleanQueryRewrite

Package org.apache.lucene.search

# Class MultiTermQuery.TopTermsScoringBooleanQueryRewrite

java.lang.Object
org.apache.lucene.search.MultiTermQuery.RewriteMethod
org.apache.lucene.search.TopTermsRewrite<BooleanQuery.Builder>
org.apache.lucene.search.MultiTermQuery.TopTermsScoringBooleanQueryRewrite

Enclosing class:
  `MultiTermQuery`

public static final class MultiTermQuery.TopTermsScoringBooleanQueryRewrite extends TopTermsRewrite<BooleanQuery.Builder>
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.

This rewrite method only uses the top scoring terms so it will not overflow the boolean max clause count.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TopTermsScoringBooleanQueryRewrite(int size)`
  Create a TopTermsScoringBooleanQueryRewrite for at most `size` terms.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected final void`
  `addClause(BooleanQuery.Builder topLevel, Term term, int docCount, float boost)`
  Add a MultiTermQuery term to the top-level query builder.
  `protected void`
  `addClause(BooleanQuery.Builder topLevel, Term term, int docCount, float boost, TermStates states)`
  `protected Query`
  `build(BooleanQuery.Builder builder)`
  Finalize the creation of the query from the builder.
  `protected int`
  `getMaxSize()`
  return the maximum size of the priority queue (for boolean rewrites this is BooleanQuery#getMaxClauseCount).
  `protected BooleanQuery.Builder`
  `getTopLevelBuilder()`
  Return a suitable builder for the top-level Query for holding all expanded terms.

  ### Methods inherited from class org.apache.lucene.search.TopTermsRewrite

  `equals, getSize, hashCode, rewrite`

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

  `getTermsEnum`

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

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

- ## Constructor Details

  - ### TopTermsScoringBooleanQueryRewrite

    public TopTermsScoringBooleanQueryRewrite(int size)
    Create a TopTermsScoringBooleanQueryRewrite for at most `size` terms.

    NOTE: if `IndexSearcher.getMaxClauseCount()` is smaller than `size`, then it will be used instead.

- ## Method Details

  - ### getMaxSize

    protected int getMaxSize()
    Description copied from class: `TopTermsRewrite`
    return the maximum size of the priority queue (for boolean rewrites this is BooleanQuery#getMaxClauseCount).
    Specified by:
      `getMaxSize` in class `TopTermsRewrite<BooleanQuery.Builder>`

  - ### getTopLevelBuilder

    protected BooleanQuery.Builder getTopLevelBuilder()
    Return a suitable builder for the top-level Query for holding all expanded terms.

  - ### build

    protected Query build(BooleanQuery.Builder builder)
    Finalize the creation of the query from the builder.

  - ### addClause

    protected void addClause(BooleanQuery.Builder topLevel, Term term, int docCount, float boost, TermStates states)

  - ### addClause

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