Class AnalyzingInfixSuggester

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    BlendedInfixSuggester

    public class AnalyzingInfixSuggester
    extends Lookup
    implements java.io.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.

    • Constructor Summary

      Constructors 
      Constructor Description
      AnalyzingInfixSuggester​(Version matchVersion, java.io.File indexPath, Analyzer analyzer)
      Create a new instance, loading from a previously built directory, if it exists.
      AnalyzingInfixSuggester​(Version matchVersion, java.io.File indexPath, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars)
      Create a new instance, loading from a previously built directory, if it exists.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void build​(InputIterator iter)
      Builds up a new internal Lookup representation based on the given InputIterator.
      void close()  
      long getCount()
      Get the number of entries the lookup was built with
      boolean load​(DataInput out)
      Discard current lookup data and load it from a previously saved copy.
      java.util.List<Lookup.LookupResult> lookup​(java.lang.CharSequence key, boolean onlyMorePopular, int num)
      Look up a key and return possible completion for this key.
      java.util.List<Lookup.LookupResult> lookup​(java.lang.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).
      long sizeInBytes()
      Get the size of the underlying lookup implementation in memory
      boolean store​(DataOutput in)
      Persist the constructed lookup data to a directory.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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,
                                       java.io.File indexPath,
                                       Analyzer analyzer)
                                throws java.io.IOException
        Create a new instance, loading from a previously built directory, if it exists.
        Throws:
        java.io.IOException
      • AnalyzingInfixSuggester

        public AnalyzingInfixSuggester​(Version matchVersion,
                                       java.io.File indexPath,
                                       Analyzer indexAnalyzer,
                                       Analyzer queryAnalyzer,
                                       int minPrefixChars)
                                throws java.io.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:
        java.io.IOException
    • Method Detail

      • build

        public void build​(InputIterator iter)
                   throws java.io.IOException
        Description copied from class: Lookup
        Builds up a new internal Lookup representation based on the given InputIterator. The implementation might re-sort the data internally.
        Specified by:
        build in class Lookup
        Throws:
        java.io.IOException
      • lookup

        public java.util.List<Lookup.LookupResult> lookup​(java.lang.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 java.util.List<Lookup.LookupResult> lookup​(java.lang.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 java.io.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:
        java.io.IOException - when fatal IO error occurs.
      • load

        public boolean load​(DataInput out)
                     throws java.io.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:
        java.io.IOException - when fatal IO error occurs.
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • 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