Class AnalyzingInfixSuggester

java.lang.Object
org.apache.lucene.search.suggest.Lookup
org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester
All Implemented Interfaces:
Closeable, AutoCloseable, Accountable
Direct Known Subclasses:
BlendedInfixSuggester

public class AnalyzingInfixSuggester extends Lookup implements Closeable
Analyzes the input text and then suggests matches based on prefix matches to any tokens in the indexed text. This also highlights the tokens that match.

This suggester supports payloads. Matches are sorted only by the suggest weight; it would be nice to support blended score + weight sort in the future. This means this suggester best applies when there is a strong a-priori ranking of all the suggestions.

This suggester supports contexts, including arbitrary binary terms.

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

    • TEXTGRAMS_FIELD_NAME

      protected static final String TEXTGRAMS_FIELD_NAME
      edgegrams for searching short prefixes without Prefix Query that's controlled by minPrefixChars
      See Also:
    • TEXT_FIELD_NAME

      protected static final String TEXT_FIELD_NAME
      Field name used for the indexed text.
      See Also:
    • EXACT_TEXT_FIELD_NAME

      protected static final String EXACT_TEXT_FIELD_NAME
      Field name used for the indexed text, as a StringField, for exact lookup.
      See Also:
    • CONTEXTS_FIELD_NAME

      protected static final String CONTEXTS_FIELD_NAME
      Field name used for the indexed context, as a StringField and a SortedSetDVField, for filtering.
      See Also:
    • queryAnalyzer

      protected final Analyzer queryAnalyzer
      Analyzer used at search time
    • indexAnalyzer

      protected final Analyzer indexAnalyzer
      Analyzer used at index time
    • writer

      protected IndexWriter writer
      Used for ongoing NRT additions/updates.
    • searcherMgr

      protected SearcherManager searcherMgr
      IndexSearcher used for lookups.
    • searcherMgrLock

      protected final Object searcherMgrLock
      Used to manage concurrent access to searcherMgr
    • DEFAULT_MIN_PREFIX_CHARS

      public static final int DEFAULT_MIN_PREFIX_CHARS
      Default minimum number of leading characters before PrefixQuery is used (4).
      See Also:
    • DEFAULT_ALL_TERMS_REQUIRED

      public static final boolean DEFAULT_ALL_TERMS_REQUIRED
      Default boolean clause option for multiple terms matching (all terms required).
      See Also:
    • DEFAULT_HIGHLIGHT

      public static final boolean DEFAULT_HIGHLIGHT
      Default higlighting option.
      See Also:
    • DEFAULT_CLOSE_INDEXWRITER_ON_BUILD

      protected static final boolean DEFAULT_CLOSE_INDEXWRITER_ON_BUILD
      Default option to close the IndexWriter once the index has been built.
      See Also:
  • Constructor Details

    • AnalyzingInfixSuggester

      public AnalyzingInfixSuggester(Directory dir, Analyzer analyzer) throws IOException
      Create a new instance, loading from a previously built AnalyzingInfixSuggester directory, if it exists. This directory must be private to the infix suggester (i.e., not an external Lucene index). Note that close() will also close the provided directory.
      Throws:
      IOException
    • AnalyzingInfixSuggester

      public AnalyzingInfixSuggester(Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, boolean commitOnBuild) throws IOException
      Create a new instance, loading from a previously built AnalyzingInfixSuggester directory, if it exists. This directory must be private to the infix suggester (i.e., not an external Lucene index). Note that close() will also close the provided directory.
      Parameters:
      minPrefixChars - Minimum number of leading characters before PrefixQuery is used (default 4). Prefixes shorter than this are indexed as character ngrams (increasing index size but making lookups faster).
      commitOnBuild - Call commit after the index has finished building. This would persist the suggester index to disk and future instances of this suggester can use this pre-built dictionary.
      Throws:
      IOException
    • AnalyzingInfixSuggester

      public AnalyzingInfixSuggester(Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, boolean commitOnBuild, boolean allTermsRequired, boolean highlight) throws IOException
      Create a new instance, loading from a previously built AnalyzingInfixSuggester directory, if it exists. This directory must be private to the infix suggester (i.e., not an external Lucene index). Note that close() will also close the provided directory.
      Parameters:
      minPrefixChars - Minimum number of leading characters before PrefixQuery is used (default 4). Prefixes shorter than this are indexed as character ngrams (increasing index size but making lookups faster).
      commitOnBuild - Call commit after the index has finished building. This would persist the suggester index to disk and future instances of this suggester can use this pre-built dictionary.
      allTermsRequired - All terms in the suggest query must be matched.
      highlight - Highlight suggest query in suggestions.
      Throws:
      IOException
    • AnalyzingInfixSuggester

      public AnalyzingInfixSuggester(Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars, boolean commitOnBuild, boolean allTermsRequired, boolean highlight, boolean closeIndexWriterOnBuild) throws IOException
      Create a new instance, loading from a previously built AnalyzingInfixSuggester directory, if it exists. This directory must be private to the infix suggester (i.e., not an external Lucene index). Note that close() will also close the provided directory.
      Parameters:
      minPrefixChars - Minimum number of leading characters before PrefixQuery is used (default 4). Prefixes shorter than this are indexed as character ngrams (increasing index size but making lookups faster).
      commitOnBuild - Call commit after the index has finished building. This would persist the suggester index to disk and future instances of this suggester can use this pre-built dictionary.
      allTermsRequired - All terms in the suggest query must be matched.
      highlight - Highlight suggest query in suggestions.
      closeIndexWriterOnBuild - If true, the IndexWriter will be closed after the index has finished building.
      Throws:
      IOException
  • Method Details