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, highestweight 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 byweight 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 nonconstant weights are used, but the algorithm for doing this is suboptimal.
"alphabetically" in any of the documentation above indicates UTF8 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) 
Modifier and Type  Method and Description 

void 
add(org.apache.lucene.util.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 resorting input for the automaton.
For large inputs, use ondisk 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 nonminimal
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(org.apache.lucene.util.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 nonnegative 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