|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.search.suggest.fst.FSTCompletionBuilder
public class FSTCompletionBuilder
Finite state automata based implementation of "autocomplete" functionality.
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
Field Summary | |
---|---|
static int |
DEFAULT_BUCKETS
Default number of buckets. |
Constructor Summary | |
---|---|
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)
|
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_BUCKETS
Constructor Detail |
---|
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
.Method Detail |
---|
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
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |