Search in sources :

Example 1 with WFSTCompletionLookup

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

the class Suggester method getSuggestions.

@Override
public SpellingResult getSuggestions(SpellingOptions options) throws IOException {
    LOG.debug("getSuggestions: " + options.tokens);
    if (lookup == null) {
        LOG.info("Lookup is null - invoke spellchecker.build first");
        return EMPTY_RESULT;
    }
    SpellingResult res = new SpellingResult();
    CharsRef scratch = new CharsRef();
    for (Token t : options.tokens) {
        scratch.chars = t.buffer();
        scratch.offset = 0;
        scratch.length = t.length();
        boolean onlyMorePopular = (options.suggestMode == SuggestMode.SUGGEST_MORE_POPULAR) && !(lookup instanceof WFSTCompletionLookup) && !(lookup instanceof AnalyzingSuggester);
        List<LookupResult> suggestions = lookup.lookup(scratch, onlyMorePopular, options.count);
        if (suggestions == null) {
            continue;
        }
        if (options.suggestMode != SuggestMode.SUGGEST_MORE_POPULAR) {
            Collections.sort(suggestions);
        }
        for (LookupResult lr : suggestions) {
            res.add(t, lr.key.toString(), (int) lr.value);
        }
    }
    return res;
}
Also used : WFSTCompletionLookup(org.apache.lucene.search.suggest.fst.WFSTCompletionLookup) SpellingResult(org.apache.solr.spelling.SpellingResult) LookupResult(org.apache.lucene.search.suggest.Lookup.LookupResult) Token(org.apache.lucene.analysis.Token) AnalyzingSuggester(org.apache.lucene.search.suggest.analyzing.AnalyzingSuggester) CharsRef(org.apache.lucene.util.CharsRef)

Aggregations

Token (org.apache.lucene.analysis.Token)1 LookupResult (org.apache.lucene.search.suggest.Lookup.LookupResult)1 AnalyzingSuggester (org.apache.lucene.search.suggest.analyzing.AnalyzingSuggester)1 WFSTCompletionLookup (org.apache.lucene.search.suggest.fst.WFSTCompletionLookup)1 CharsRef (org.apache.lucene.util.CharsRef)1 SpellingResult (org.apache.solr.spelling.SpellingResult)1