org.apache.lucene.search.suggest.document

## Class FuzzyCompletionQuery

- java.lang.Object
- - org.apache.lucene.search.Query
  - - org.apache.lucene.search.suggest.document.CompletionQuery
    - - org.apache.lucene.search.suggest.document.PrefixCompletionQuery
      - - org.apache.lucene.search.suggest.document.FuzzyCompletionQuery

-     public class FuzzyCompletionQuery
      extends PrefixCompletionQuery

  A `CompletionQuery` that match documents containing terms within an edit distance of the specified prefix.

  This query boost documents relative to how similar the indexed terms are to the provided prefix.

  Example usage of querying an analyzed prefix within an edit distance of 1 of 'subg' against a field 'suggest_field' is as follows:

        CompletionQuery query = new FuzzyCompletionQuery(analyzer, new Term("suggest_field", "subg"));

  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `DEFAULT_MAX_EDITS` The default maximum number of edits for fuzzy suggestions.
    `static int` | `DEFAULT_MIN_FUZZY_LENGTH` The default minimum length of the key before any edits are allowed.
    `static int` | `DEFAULT_NON_FUZZY_PREFIX` The default prefix length where edits are not allowed.
    `static boolean` | `DEFAULT_TRANSPOSITIONS` The default transposition value passed to `LevenshteinAutomata`
    `static boolean` | `DEFAULT_UNICODE_AWARE` Measure maxEdits, minFuzzyLength, transpositions and nonFuzzyPrefix parameters in Unicode code points (actual letters) instead of bytes.

    - ### Fields inherited from class org.apache.lucene.search.suggest.document.PrefixCompletionQuery

      `analyzer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FuzzyCompletionQuery(Analyzer analyzer, Term term)` Calls `FuzzyCompletionQuery(Analyzer, Term, BitsProducer)` with no filter
    `FuzzyCompletionQuery(Analyzer analyzer, Term term, BitsProducer filter)` Calls `FuzzyCompletionQuery(Analyzer, Term, BitsProducer, int, boolean, int, int, boolean, int)` with defaults for `maxEdits`, `transpositions`, `nonFuzzyPrefix`, `minFuzzyLength`, `unicodeAware` and `maxDeterminizedStates` See `DEFAULT_MAX_EDITS`, `DEFAULT_TRANSPOSITIONS`, `DEFAULT_NON_FUZZY_PREFIX`, `DEFAULT_MIN_FUZZY_LENGTH`, `DEFAULT_UNICODE_AWARE` and `Operations.DEFAULT_MAX_DETERMINIZED_STATES` for defaults
    `FuzzyCompletionQuery(Analyzer analyzer, Term term, BitsProducer filter, int maxEdits, boolean transpositions, int nonFuzzyPrefix, int minFuzzyLength, boolean unicodeAware, int maxDeterminizedStates)` Constructs an analyzed fuzzy prefix completion query

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Weight` | `createWeight(IndexSearcher searcher, boolean needsScores, float boost)`
    `int` | `getMaxDeterminizedStates()` Get the maximum number of determinized states permitted
    `int` | `getMaxEdits()` Get the maximum edit distance for fuzzy matches
    `int` | `getMinFuzzyLength()` Get the minimum length of a term considered for matching
    `int` | `getNonFuzzyPrefix()` Get the length of a prefix where no edits are permitted
    `boolean` | `isTranspositions()` Return whether transpositions count as a single edit
    `boolean` | `isUnicodeAware()` Return true if lengths are measured in unicode code-points rather than bytes
    `String` | `toString(String field)`

    - ### Methods inherited from class org.apache.lucene.search.suggest.document.PrefixCompletionQuery

      `equals, getAnalyzer, hashCode`

    - ### Methods inherited from class org.apache.lucene.search.suggest.document.CompletionQuery

      `getField, getFilter, getTerm, rewrite`

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

      `classHash, sameClassAs, toString`

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

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

- - ### Field Detail

    - #### DEFAULT_UNICODE_AWARE

          public static final boolean DEFAULT_UNICODE_AWARE

      Measure maxEdits, minFuzzyLength, transpositions and nonFuzzyPrefix parameters in Unicode code points (actual letters) instead of bytes.
      See Also:
        Constant Field Values

    - #### DEFAULT_MIN_FUZZY_LENGTH

          public static final int DEFAULT_MIN_FUZZY_LENGTH

      The default minimum length of the key before any edits are allowed.
      See Also:
        Constant Field Values

    - #### DEFAULT_NON_FUZZY_PREFIX

          public static final int DEFAULT_NON_FUZZY_PREFIX

      The default prefix length where edits are not allowed.
      See Also:
        Constant Field Values

    - #### DEFAULT_MAX_EDITS

          public static final int DEFAULT_MAX_EDITS

      The default maximum number of edits for fuzzy suggestions.
      See Also:
        Constant Field Values

    - #### DEFAULT_TRANSPOSITIONS

          public static final boolean DEFAULT_TRANSPOSITIONS

      The default transposition value passed to `LevenshteinAutomata`
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### FuzzyCompletionQuery

          public FuzzyCompletionQuery(Analyzer analyzer,
                                      Term term)

      Calls `FuzzyCompletionQuery(Analyzer, Term, BitsProducer)` with no filter

    - #### FuzzyCompletionQuery

          public FuzzyCompletionQuery(Analyzer analyzer,
                                      Term term,
                                      BitsProducer filter)

      Calls `FuzzyCompletionQuery(Analyzer, Term, BitsProducer, int, boolean, int, int, boolean, int)` with defaults for `maxEdits`, `transpositions`, `nonFuzzyPrefix`, `minFuzzyLength`, `unicodeAware` and `maxDeterminizedStates` See `DEFAULT_MAX_EDITS`, `DEFAULT_TRANSPOSITIONS`, `DEFAULT_NON_FUZZY_PREFIX`, `DEFAULT_MIN_FUZZY_LENGTH`, `DEFAULT_UNICODE_AWARE` and `Operations.DEFAULT_MAX_DETERMINIZED_STATES` for defaults

    - #### FuzzyCompletionQuery

          public FuzzyCompletionQuery(Analyzer analyzer,
                                      Term term,
                                      BitsProducer filter,
                                      int maxEdits,
                                      boolean transpositions,
                                      int nonFuzzyPrefix,
                                      int minFuzzyLength,
                                      boolean unicodeAware,
                                      int maxDeterminizedStates)

      Constructs an analyzed fuzzy prefix completion query
      Parameters:
        `analyzer` - used to analyze the provided `Term.text()`
        `term` - query is run against `Term.field()` and `Term.text()` is analyzed with `analyzer`
        `filter` - used to query on a sub set of documents
        `maxEdits` - maximum number of acceptable edits
        `transpositions` - value passed to `LevenshteinAutomata`
        `nonFuzzyPrefix` - prefix length where edits are not allowed
        `minFuzzyLength` - minimum prefix length before any edits are allowed
        `unicodeAware` - treat prefix as unicode rather than bytes
        `maxDeterminizedStates` - maximum automaton states allowed for `LevenshteinAutomata`

  - ### Method Detail

    - #### createWeight

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

      Overrides:
        `createWeight` in class `PrefixCompletionQuery`
      Throws:
        `IOException`

    - #### getMaxEdits

          public int getMaxEdits()

      Get the maximum edit distance for fuzzy matches

    - #### isTranspositions

          public boolean isTranspositions()

      Return whether transpositions count as a single edit

    - #### getNonFuzzyPrefix

          public int getNonFuzzyPrefix()

      Get the length of a prefix where no edits are permitted

    - #### getMinFuzzyLength

          public int getMinFuzzyLength()

      Get the minimum length of a term considered for matching

    - #### isUnicodeAware

          public boolean isUnicodeAware()

      Return true if lengths are measured in unicode code-points rather than bytes

    - #### getMaxDeterminizedStates

          public int getMaxDeterminizedStates()

      Get the maximum number of determinized states permitted

    - #### toString

          public String toString(String field)

      Overrides:
        `toString` in class `CompletionQuery`

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