Search in sources :

Example 1 with Completion

use of org.apache.lucene.search.suggest.fst.FSTCompletion.Completion in project lucene-solr by apache.

the class FSTCompletionLookup method lookup.

@Override
public List<LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, boolean higherWeightsFirst, int num) {
    if (contexts != null) {
        throw new IllegalArgumentException("this suggester doesn't support contexts");
    }
    final List<Completion> completions;
    if (higherWeightsFirst) {
        completions = higherWeightsCompletion.lookup(key, num);
    } else {
        completions = normalCompletion.lookup(key, num);
    }
    final ArrayList<LookupResult> results = new ArrayList<>(completions.size());
    CharsRefBuilder spare = new CharsRefBuilder();
    for (Completion c : completions) {
        spare.copyUTF8Bytes(c.utf8);
        results.add(new LookupResult(spare.toString(), c.bucket));
    }
    return results;
}
Also used : Completion(org.apache.lucene.search.suggest.fst.FSTCompletion.Completion) ArrayList(java.util.ArrayList) CharsRefBuilder(org.apache.lucene.util.CharsRefBuilder)

Aggregations

ArrayList (java.util.ArrayList)1 Completion (org.apache.lucene.search.suggest.fst.FSTCompletion.Completion)1 CharsRefBuilder (org.apache.lucene.util.CharsRefBuilder)1