Class CompletionAnalyzer

java.lang.Object
org.apache.lucene.analysis.Analyzer
org.apache.lucene.analysis.AnalyzerWrapper
org.apache.lucene.search.suggest.document.CompletionAnalyzer
All Implemented Interfaces:
Closeable, AutoCloseable

public final class CompletionAnalyzer extends AnalyzerWrapper
Wraps an Analyzer to provide additional completion-only tuning (e.g. preserving token separators, preserving position increments while converting a token stream to an automaton)

Can be used to index SuggestField and ContextSuggestField and as a query analyzer to PrefixCompletionQuery amd FuzzyCompletionQuery

NOTE: In most cases, index and query analyzer should have same values for preservePositionIncrements() and preserveSep()

Since:
5.1.0
  • Field Details

    • HOLE_CHARACTER

      static final int HOLE_CHARACTER
      Represent a hole character, inserted by TokenStreamToAutomaton
      See Also:
    • analyzer

      private final Analyzer analyzer
    • preserveSep

      private final boolean preserveSep
      Preserve separation between tokens when converting to an automaton

      Defaults to true

    • preservePositionIncrements

      private final boolean preservePositionIncrements
      Preserve position increments for tokens when converting to an automaton

      Defaults to true

    • maxGraphExpansions

      private final int maxGraphExpansions
      Sets the maximum number of graph expansions of a completion automaton

      Defaults to -1 (no limit)

  • Constructor Details

  • Method Details

    • preserveSep

      public boolean preserveSep()
      Returns true if separation between tokens are preserved when converting the token stream to an automaton
    • preservePositionIncrements

      public boolean preservePositionIncrements()
      Returns true if position increments are preserved when converting the token stream to an automaton
    • getWrappedAnalyzer

      protected Analyzer getWrappedAnalyzer(String fieldName)
      Description copied from class: AnalyzerWrapper
      Retrieves the wrapped Analyzer appropriate for analyzing the field with the given name
      Specified by:
      getWrappedAnalyzer in class AnalyzerWrapper
      Parameters:
      fieldName - Name of the field which is to be analyzed
      Returns:
      Analyzer for the field with the given name. Assumed to be non-null
    • wrapComponents

      protected Analyzer.TokenStreamComponents wrapComponents(String fieldName, Analyzer.TokenStreamComponents components)
      Description copied from class: AnalyzerWrapper
      Wraps / alters the given TokenStreamComponents, taken from the wrapped Analyzer, to form new components. It is through this method that new TokenFilters can be added by AnalyzerWrappers. By default, the given components are returned.
      Overrides:
      wrapComponents in class AnalyzerWrapper
      Parameters:
      fieldName - Name of the field which is to be analyzed
      components - TokenStreamComponents taken from the wrapped Analyzer
      Returns:
      Wrapped / altered TokenStreamComponents.