Class FSTCompletion

  • public class FSTCompletion
    extends Object
    Finite state automata based implementation of "autocomplete" functionality.
    See Also:
    WARNING: This API is experimental and might change in incompatible ways in the next release.
    • Field Detail


        public static final int DEFAULT_BUCKETS
        Default number of buckets.
        See Also:
        Constant Field Values
    • Constructor Detail

      • FSTCompletion

        public FSTCompletion​(FST<Object> automaton,
                             boolean higherWeightsFirst,
                             boolean exactFirst)
        Constructs an FSTCompletion, specifying higherWeightsFirst and exactFirst.
        automaton - Automaton with completions. See FSTCompletionBuilder.
        higherWeightsFirst - Return most popular suggestions first. This is the default behavior for this implementation. Setting it to false has no effect (use constant term weights to sort alphabetically only).
        exactFirst - Find and push an exact match to the first position of the result list if found.
    • Method Detail

      • lookup

        public List<FSTCompletion.Completion> lookup​(CharSequence key,
                                                     int num)
        Lookup suggestions to key.
        key - The prefix to which suggestions should be sought.
        num - At most this number of suggestions will be returned.
        Returns the suggestions, sorted by their approximated weight first (decreasing) and then alphabetically (UTF-8 codepoint order).
      • lookup

        public Stream<FSTCompletion.Completion> lookup​(CharSequence key)
        Lookup suggestions to key and return a stream of matching completions. The stream fetches completions dynamically - it can be filtered and limited to acquire the desired number of completions without collecting all of them.
        key - The prefix to which suggestions should be sought.
        Returns the suggestions
      • getBucketCount

        public int getBucketCount()
        Returns the bucket count (discretization thresholds).
      • getBucket

        public int getBucket​(CharSequence key)
        Returns the bucket assigned to a given key (if found) or -1 if no exact match exists.
      • getFST

        public FST<Object> getFST()
        Returns the internal automaton.