org.apache.lucene.search

## Class PhraseQuery.Builder

- java.lang.Object
- - org.apache.lucene.search.PhraseQuery.Builder

- Enclosing class:
    PhraseQuery

      public static class PhraseQuery.Builder
      extends Object

  A builder for phrase queries.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Builder()` Sole constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `PhraseQuery.Builder` | `add(Term term)` Adds a term to the end of the query phrase.
    `PhraseQuery.Builder` | `add(Term term, int position)` Adds a term to the end of the query phrase.
    `PhraseQuery` | `build()` Build a phrase query based on the terms that have been added.
    `PhraseQuery.Builder` | `setSlop(int slop)` Set the slop.

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

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

- - ### Constructor Detail

    - #### Builder

          public Builder()

      Sole constructor.

  - ### Method Detail

    - #### setSlop

          public PhraseQuery.Builder setSlop(int slop)

      Set the slop.
      See Also:
        `PhraseQuery.getSlop()`

    - #### add

          public PhraseQuery.Builder add(Term term)

      Adds a term to the end of the query phrase. The relative position of the term is the one immediately after the last term added.

    - #### add

          public PhraseQuery.Builder add(Term term,
                                         int position)

      Adds a term to the end of the query phrase. The relative position of the term within the phrase is specified explicitly, but must be greater than or equal to that of the previously added term. A greater position allows phrases with gaps (e.g. in connection with stopwords). If the position is equal, you most likely should be using `MultiPhraseQuery` instead which only requires one term at each position to match; this class requires all of them.

    - #### build

          public PhraseQuery build()

      Build a phrase query based on the terms that have been added.

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