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

Package org.apache.lucene.search

# Class BooleanQuery.Builder

java.lang.Object
org.apache.lucene.search.BooleanQuery.Builder

Enclosing class:
  `BooleanQuery`

public static class BooleanQuery.Builder extends Object
A builder for boolean queries.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Builder()`
  Sole constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `BooleanQuery.Builder`
  `add(Collection<BooleanClause> collection)`
  Add a collection of BooleanClauses to this `BooleanQuery.Builder`.
  `BooleanQuery.Builder`
  `add(BooleanClause clause)`
  Add a new clause to this `BooleanQuery.Builder`.
  `BooleanQuery.Builder`
  `add(Query query, BooleanClause.Occur occur)`
  Add a new clause to this `BooleanQuery.Builder`.
  `BooleanQuery`
  `build()`
  Create a new `BooleanQuery` based on the parameters that have been set on this builder.
  `BooleanQuery.Builder`
  `setMinimumNumberShouldMatch(int min)`
  Specifies a minimum number of the optional BooleanClauses which must be satisfied.

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

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

- ## Constructor Details

  - ### Builder

    public Builder()
    Sole constructor.

- ## Method Details

  - ### setMinimumNumberShouldMatch

    public BooleanQuery.Builder setMinimumNumberShouldMatch(int min)
    Specifies a minimum number of the optional BooleanClauses which must be satisfied.

    By default no optional clauses are necessary for a match (unless there are no required clauses). If this method is used, then the specified number of clauses is required.

    Use of this method is totally independent of specifying that any specific clauses are required (or prohibited). This number will only be compared against the number of matching optional clauses.

    Parameters:
      `min` - the number of optional clauses that must match

  - ### add

    public BooleanQuery.Builder add(BooleanClause clause)
    Add a new clause to this `BooleanQuery.Builder`. Note that the order in which clauses are added does not have any impact on matching documents or query performance.
    Throws:
      `IndexSearcher.TooManyClauses` - if the new number of clauses exceeds the maximum clause number

  - ### add

    public BooleanQuery.Builder add(Collection<BooleanClause> collection)
    Add a collection of BooleanClauses to this `BooleanQuery.Builder`. Note that the order in which clauses are added does not have any impact on matching documents or query performance.
    Throws:
      `IndexSearcher.TooManyClauses` - if the new number of clauses exceeds the maximum clause number

  - ### add

    public BooleanQuery.Builder add(Query query, BooleanClause.Occur occur)
    Add a new clause to this `BooleanQuery.Builder`. Note that the order in which clauses are added does not have any impact on matching documents or query performance.
    Throws:
      `IndexSearcher.TooManyClauses` - if the new number of clauses exceeds the maximum clause number

  - ### build

    public BooleanQuery build()
    Create a new `BooleanQuery` based on the parameters that have been set on this builder.