public class FSTCompletionBuilder extends Object
The construction step in Object.finalize()
works as follows:
abc
with a discretized weight equal '1' would become
1abc
.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 FSTCompletion.lookup(CharSequence, int)
,
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.
FSTCompletion
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUCKETS
Default number of buckets.
|
Constructor and Description |
---|
FSTCompletionBuilder()
Creates an
FSTCompletion with default options: 10 buckets, exact match
promoted to first position and InMemorySorter with a comparator obtained from
BytesRef.getUTF8SortedAsUnicodeComparator() . |
FSTCompletionBuilder(int buckets,
BytesRefSorter sorter,
int shareMaxTailLength)
Creates an FSTCompletion with the specified options.
|
Modifier and Type | Method and Description |
---|---|
void |
add(BytesRef utf8,
int bucket)
Appends a single suggestion and its weight to the internal buffers.
|
FSTCompletion |
build()
Builds the final automaton from a list of added entries.
|
public static final int DEFAULT_BUCKETS
public FSTCompletionBuilder()
FSTCompletion
with default options: 10 buckets, exact match
promoted to first position and InMemorySorter
with a comparator obtained from
BytesRef.getUTF8SortedAsUnicodeComparator()
.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.sorter
- BytesRefSorter
used 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
Closeable
.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 Integer.MAX_VALUE
.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.IOException
public FSTCompletion build() throws IOException
IOException
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.