Class AnalyzingInfixSuggester

  • All Implemented Interfaces:
    Closeable, AutoCloseable
    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 just uses an ordinary Lucene index. It supports payloads, and records these as a BinaryDocValues field. 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 apriori ranking of all the suggestions.

    • Field Detail

      • 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:
        Constant Field Values
    • Constructor Detail

      • AnalyzingInfixSuggester

        public AnalyzingInfixSuggester​(Version matchVersion,
                                       File indexPath,
                                       Analyzer analyzer)
                                throws IOException
        Create a new instance, loading from a previously built directory, if it exists.
        Throws:
        IOException
      • AnalyzingInfixSuggester

        public AnalyzingInfixSuggester​(Version matchVersion,
                                       File indexPath,
                                       Analyzer indexAnalyzer,
                                       Analyzer queryAnalyzer,
                                       int minPrefixChars)
                                throws IOException
        Create a new instance, loading from a previously built directory, if it exists.
        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).
        Throws:
        IOException
    • Method Detail

      • lookup

        public List<Lookup.LookupResult> lookup​(CharSequence key,
                                                boolean onlyMorePopular,
                                                int num)
        Description copied from class: Lookup
        Look up a key and return possible completion for this key.
        Specified by:
        lookup in class Lookup
        Parameters:
        key - lookup key. Depending on the implementation this may be a prefix, misspelling, or even infix.
        onlyMorePopular - return only more popular results
        num - maximum number of results to return
        Returns:
        a list of possible completions, with their relative weight (e.g. popularity)
      • lookup

        public List<Lookup.LookupResult> lookup​(CharSequence key,
                                                int num,
                                                boolean allTermsRequired,
                                                boolean doHighlight)
        Retrieve suggestions, specifying whether all terms must match (allTermsRequired) and whether the hits should be highlighted (doHighlight).
      • store

        public boolean store​(DataOutput in)
                      throws IOException
        Description copied from class: Lookup
        Persist the constructed lookup data to a directory. Optional operation.
        Specified by:
        store in class Lookup
        Parameters:
        in - DataOutput to write the data to.
        Returns:
        true if successful, false if unsuccessful or not supported.
        Throws:
        IOException - when fatal IO error occurs.
      • load

        public boolean load​(DataInput out)
                     throws IOException
        Description copied from class: Lookup
        Discard current lookup data and load it from a previously saved copy. Optional operation.
        Specified by:
        load in class Lookup
        Parameters:
        out - the DataInput to load the lookup data.
        Returns:
        true if completed successfully, false if unsuccessful or not supported.
        Throws:
        IOException - when fatal IO error occurs.
      • sizeInBytes

        public long sizeInBytes()
        Description copied from class: Lookup
        Get the size of the underlying lookup implementation in memory
        Specified by:
        sizeInBytes in class Lookup
        Returns:
        ram size of the lookup implementation in bytes
      • getCount

        public long getCount()
        Description copied from class: Lookup
        Get the number of entries the lookup was built with
        Specified by:
        getCount in class Lookup
        Returns:
        total number of suggester entries