org.apache.lucene.search

## Class WildcardQuery

- java.lang.Object
- - org.apache.lucene.search.Query
  - - org.apache.lucene.search.MultiTermQuery
    - - org.apache.lucene.search.AutomatonQuery
      - - org.apache.lucene.search.WildcardQuery

-     public class WildcardQuery
      extends AutomatonQuery

  Implements the wildcard search query. Supported wildcards are `*`, which matches any character sequence (including the empty one), and `?`, which matches any single character. '\' is the escape character.

  Note this query can be slow, as it needs to iterate over many terms. In order to prevent extremely slow WildcardQueries, a Wildcard term should not start with the wildcard `*`

  This query uses the `MultiTermQuery.CONSTANT_SCORE_REWRITE` rewrite method.

  See Also:
    `AutomatonQuery`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.apache.lucene.search.MultiTermQuery

      `MultiTermQuery.RewriteMethod, MultiTermQuery.TopTermsBlendedFreqScoringRewrite, MultiTermQuery.TopTermsBoostOnlyBooleanQueryRewrite, MultiTermQuery.TopTermsScoringBooleanQueryRewrite`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static char` | `WILDCARD_CHAR` Char equality with support for wildcards
    `static char` | `WILDCARD_ESCAPE` Escape character
    `static char` | `WILDCARD_STRING` String equality with support for wildcards

    - ### Fields inherited from class org.apache.lucene.search.AutomatonQuery

      `automaton, compiled, term`

    - ### Fields inherited from class org.apache.lucene.search.MultiTermQuery

      `CONSTANT_SCORE_BOOLEAN_REWRITE, CONSTANT_SCORE_REWRITE, field, rewriteMethod, SCORING_BOOLEAN_REWRITE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `WildcardQuery(Term term)` Constructs a query for terms matching `term`.
    `WildcardQuery(Term term, int maxDeterminizedStates)` Constructs a query for terms matching `term`.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Term` | `getTerm()` Returns the pattern term.
    `static Automaton` | `toAutomaton(Term wildcardquery)` Convert Lucene wildcard syntax into an automaton.
    `String` | `toString(String field)` Prints a user-readable version of this query.

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

      `equals, getAutomaton, getTermsEnum, hashCode`

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

      `getField, getRewriteMethod, getTermsEnum, rewrite, setRewriteMethod`

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

      `classHash, createWeight, sameClassAs, toString`

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

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

- - ### Field Detail

    - #### WILDCARD_STRING

          public static final char WILDCARD_STRING

      String equality with support for wildcards
      See Also:
        Constant Field Values

    - #### WILDCARD_CHAR

          public static final char WILDCARD_CHAR

      Char equality with support for wildcards
      See Also:
        Constant Field Values

    - #### WILDCARD_ESCAPE

          public static final char WILDCARD_ESCAPE

      Escape character
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### WildcardQuery

          public WildcardQuery(Term term)

      Constructs a query for terms matching `term`.

    - #### WildcardQuery

          public WildcardQuery(Term term,
                               int maxDeterminizedStates)

      Constructs a query for terms matching `term`.
      Parameters:
        `maxDeterminizedStates` - maximum number of states in the resulting automata. If the automata would need more than this many states TooComplextToDeterminizeException is thrown. Higher number require more space but can process more complex automata.

  - ### Method Detail

    - #### toAutomaton

          public static Automaton toAutomaton(Term wildcardquery)

      Convert Lucene wildcard syntax into an automaton.
      NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

    - #### getTerm

          public Term getTerm()

      Returns the pattern term.

    - #### toString

          public String toString(String field)

      Prints a user-readable version of this query.
      Overrides:
        `toString` in class `AutomatonQuery`

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