public class FSTCompletionBuilder extends Object
The construction step in
Object.finalize() works as follows:
abcwith a discretized weight equal '1' would become
FST) is constructed from the input. The root node has arcs labeled with all possible weights. We cache all these arcs, highest-weight first.
At runtime, in
the automaton is utilized as follows:
If there is an exact match in the automaton, it is returned first on the results list (even with by-weight sorting).
Note that the maximum lookup time for any prefix is the time of descending to the subtree, plus traversal of the subtree up to the number of requested suggestions (because they are already presorted by weight on the root level and alphabetically at any node level).
To order alphabetically only (no ordering by priorities), use identical term weights for all terms. Alphabetical suggestions are returned even if non-constant weights are used, but the algorithm for doing this is suboptimal.
"alphabetically" in any of the documentation above indicates UTF-8 representation order, nothing else.
NOTE: the FST file format is experimental and subject to suddenly change, requiring you to rebuild the FST suggest index.
|Modifier and Type||Field and Description|
Default number of buckets.
|Constructor and Description|
|Modifier and Type||Method and Description|
Appends a single suggestion and its weight to the internal buffers.
Builds the final automaton from a list of added entries.
public static final int DEFAULT_BUCKETS
FSTCompletionwith default options: 10 buckets, exact match promoted to first position and
InMemorySorterwith a comparator obtained from
public FSTCompletionBuilder(int buckets, BytesRefSorter sorter, int shareMaxTailLength)
buckets- The number of buckets for weight discretization. Buckets are used in
add(BytesRef, int)and must be smaller than the number given here.
BytesRefSorterused for re-sorting input for the automaton. For large inputs, use on-disk sorting implementations. The sorter is closed automatically in
build()if it implements
shareMaxTailLength- Max shared suffix sharing length. See the description of this parameter in
Builder's constructor. In general, for very large inputs you'll want to construct a non-minimal automaton which will be larger, but the construction will take far less ram. For minimal automata, set it to
public void add(BytesRef utf8, int bucket) throws IOException
utf8- The suggestion (utf8 representation) to be added. The content is copied and the object can be reused.
bucket- The bucket to place this suggestion in. Must be non-negative and smaller than the number of buckets passed in the constructor. Higher numbers indicate suggestions that should be presented before suggestions placed in smaller buckets.
public FSTCompletion build() throws IOException