org.apache.lucene.search

## Class BooleanQuery

- java.lang.Object
- - org.apache.lucene.search.Query
  - - org.apache.lucene.search.BooleanQuery

- All Implemented Interfaces:
    Cloneable, Iterable<BooleanClause>

      public class BooleanQuery
      extends Query
      implements Iterable<BooleanClause>

  A Query that matches documents matching boolean combinations of other queries, e.g. `TermQuery`s, `PhraseQuery`s or other BooleanQuerys.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `BooleanQuery.Builder` A builder for boolean queries.
    `static class` | `BooleanQuery.TooManyClauses` Thrown when an attempt is made to add more than `getMaxClauseCount()` clauses.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BooleanQuery()` Deprecated. Use the `BooleanQuery.Builder` class to build boolean queries.
    `BooleanQuery(boolean disableCoord)` Deprecated. Use the `BooleanQuery.Builder` class to build boolean queries.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(BooleanClause clause)` Deprecated. Boolean queries should be created once with `BooleanQuery.Builder` and then considered immutable. See `BooleanQuery.Builder.add(org.apache.lucene.search.BooleanClause)`.
    `void` | `add(Query query, BooleanClause.Occur occur)` Deprecated. Boolean queries should be created once with `BooleanQuery.Builder` and then considered immutable. See `BooleanQuery.Builder.add(org.apache.lucene.search.BooleanClause)`.
    `List<BooleanClause>` | `clauses()` Return a list of the clauses of this `BooleanQuery`.
    `BooleanQuery` | `clone()` Returns a clone of this query.
    `Weight` | `createWeight(IndexSearcher searcher, boolean needsScores)` Expert: Constructs an appropriate Weight implementation for this query.
    `boolean` | `equals(Object o)` Compares the specified object with this boolean query for equality.
    `BooleanClause[]` | `getClauses()` Deprecated. Use `clauses()`.
    `static int` | `getMaxClauseCount()` Return the maximum number of clauses permitted, 1024 by default.
    `int` | `getMinimumNumberShouldMatch()` Gets the minimum number of the optional BooleanClauses which must be satisfied.
    `int` | `hashCode()`
    `boolean` | `isCoordDisabled()` Return whether the coord factor is disabled.
    `Iterator<BooleanClause>` | `iterator()` Returns an iterator on the clauses in this query.
    `Query` | `rewrite(IndexReader reader)` Expert: called to re-write queries into primitive queries.
    `static void` | `setMaxClauseCount(int maxClauseCount)` Set the maximum number of clauses permitted per BooleanQuery.
    `void` | `setMinimumNumberShouldMatch(int min)` Deprecated. Boolean queries should be created once with `BooleanQuery.Builder` and then considered immutable. See `BooleanQuery.Builder.setMinimumNumberShouldMatch(int)`.
    `String` | `toString(String field)` Prints a user-readable version of this query.

    - ### Methods inherited from class org.apache.lucene.search.Query

      `getBoost, setBoost, toString`

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

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### BooleanQuery

          @Deprecated
          public BooleanQuery()

      Deprecated. Use the `BooleanQuery.Builder` class to build boolean queries.
      Constructs an empty boolean query.

    - #### BooleanQuery

          @Deprecated
          public BooleanQuery(boolean disableCoord)

      Deprecated. Use the `BooleanQuery.Builder` class to build boolean queries.
      Constructs an empty boolean query. `Similarity.coord(int,int)` may be disabled in scoring, as appropriate. For example, this score factor does not make sense for most automatically generated queries, like `WildcardQuery` and `FuzzyQuery`.
      Parameters:
        `disableCoord` - disables `Similarity.coord(int,int)` in scoring.
      See Also:
        `BooleanQuery.Builder.setDisableCoord(boolean)`

  - ### Method Detail

    - #### getMaxClauseCount

          public static int getMaxClauseCount()

      Return the maximum number of clauses permitted, 1024 by default. Attempts to add more than the permitted number of clauses cause `BooleanQuery.TooManyClauses` to be thrown.
      See Also:
        `setMaxClauseCount(int)`

    - #### setMaxClauseCount

          public static void setMaxClauseCount(int maxClauseCount)

      Set the maximum number of clauses permitted per BooleanQuery. Default value is 1024.

    - #### isCoordDisabled

          public boolean isCoordDisabled()

      Return whether the coord factor is disabled.

    - #### getMinimumNumberShouldMatch

          public int getMinimumNumberShouldMatch()

      Gets the minimum number of the optional BooleanClauses which must be satisfied.

    - #### clauses

          public List<BooleanClause> clauses()

      Return a list of the clauses of this `BooleanQuery`.

    - #### iterator

          public final Iterator<BooleanClause> iterator()

      Returns an iterator on the clauses in this query. It implements the `Iterable` interface to make it possible to do:

          for (BooleanClause clause : booleanQuery) {}

      Specified by:
        `iterator` in interface `Iterable<BooleanClause>`

    - #### createWeight

          public Weight createWeight(IndexSearcher searcher,
                            boolean needsScores)
                              throws IOException

      Description copied from class: `Query`
      Expert: Constructs an appropriate Weight implementation for this query.

      Only implemented by primitive queries, which re-write to themselves.

      Overrides:
        `createWeight` in class `Query`
        `needsScores` - True if document scores (`Scorer.score()`) or match frequencies (`Scorer.freq()`) are needed.
      Throws:
        `IOException`

    - #### rewrite

          public Query rewrite(IndexReader reader)
                        throws IOException

      Description copied from class: `Query`
      Expert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
      Overrides:
        `rewrite` in class `Query`
      Throws:
        `IOException`

    - #### toString

          public String toString(String field)

      Prints a user-readable version of this query.
      Specified by:
        `toString` in class `Query`

    - #### equals

          public boolean equals(Object o)

      Compares the specified object with this boolean query for equality. Returns true if and only if the provided object
      - is also a `BooleanQuery`,
      - has the same value of `isCoordDisabled()`
      - has the same value of `getMinimumNumberShouldMatch()`
      - has the same `BooleanClause.Occur.SHOULD` clauses, regardless of the order
      - has the same `BooleanClause.Occur.MUST` clauses, regardless of the order
      - has the same set of `BooleanClause.Occur.FILTER` clauses, regardless of the order and regardless of duplicates
      - has the same set of `BooleanClause.Occur.MUST_NOT` clauses, regardless of the order and regardless of duplicates
      Overrides:
        `equals` in class `Query`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Query`

    - #### getClauses

          @Deprecated
          public BooleanClause[] getClauses()

      Deprecated. Use `clauses()`.
      Returns the set of clauses in this query.

    - #### clone

          public BooleanQuery clone()

      Description copied from class: `Query`
      Returns a clone of this query.
      Overrides:
        `clone` in class `Query`

    - #### setMinimumNumberShouldMatch

          @Deprecated
          public void setMinimumNumberShouldMatch(int min)

      Deprecated. Boolean queries should be created once with `BooleanQuery.Builder` and then considered immutable. See `BooleanQuery.Builder.setMinimumNumberShouldMatch(int)`.
      Set the minimum number of matching SHOULD clauses.
      See Also:
        `getMinimumNumberShouldMatch()`

    - #### add

          @Deprecated
          public void add(Query query,
                            BooleanClause.Occur occur)

      Deprecated. Boolean queries should be created once with `BooleanQuery.Builder` and then considered immutable. See `BooleanQuery.Builder.add(org.apache.lucene.search.BooleanClause)`.
      Adds a clause to a boolean query.
      Throws:
        `BooleanQuery.TooManyClauses` - if the new number of clauses exceeds the maximum clause number
      See Also:
        `getMaxClauseCount()`

    - #### add

          @Deprecated
          public void add(BooleanClause clause)

      Deprecated. Boolean queries should be created once with `BooleanQuery.Builder` and then considered immutable. See `BooleanQuery.Builder.add(org.apache.lucene.search.BooleanClause)`.
      Adds a clause to a boolean query.
      Throws:
        `BooleanQuery.TooManyClauses` - if the new number of clauses exceeds the maximum clause number
      See Also:
        `getMaxClauseCount()`

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.