Search in sources :

Example 1 with SuggesterFuzzyQuery

use of org.opengrok.suggest.query.SuggesterFuzzyQuery in project OpenGrok by OpenGrok.

the class SuggesterQueryParser method newFuzzyQuery.

@Override
protected Query newFuzzyQuery(final Term term, final float minimumSimilarity, final int prefixLength) {
    if (term.text().contains(identifier)) {
        Term newTerm = replaceIdentifier(term, identifier);
        if (minimumSimilarity < 1) {
            replaceIdentifier(term.field(), term.text() + "~" + minimumSimilarity);
        } else {
            // similarity greater than 1 must be an integer
            replaceIdentifier(term.field(), term.text() + "~" + ((int) minimumSimilarity));
        }
        @SuppressWarnings("deprecation") int numEdits = FuzzyQuery.floatToEdits(minimumSimilarity, newTerm.text().codePointCount(0, newTerm.text().length()));
        SuggesterFuzzyQuery q = new SuggesterFuzzyQuery(newTerm, numEdits, prefixLength);
        this.suggesterQuery = q;
        return q;
    }
    return super.newFuzzyQuery(term, minimumSimilarity, prefixLength);
}
Also used : SuggesterFuzzyQuery(org.opengrok.suggest.query.SuggesterFuzzyQuery) Term(org.apache.lucene.index.Term)

Example 2 with SuggesterFuzzyQuery

use of org.opengrok.suggest.query.SuggesterFuzzyQuery in project OpenGrok by OpenGrok.

the class SuggesterSearcherTest method suggesterFuzzyQueryTest.

@Test
public void suggesterFuzzyQueryTest() {
    List<LookupResultItem> suggestions = searcher.suggest(new TermQuery(new Term("test", "test")), "test", new SuggesterFuzzyQuery(new Term("test", "opengroc"), 1, 0), k -> 0);
    List<String> tokens = suggestions.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList());
    assertThat(tokens, contains("opengrok"));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) SuggesterFuzzyQuery(org.opengrok.suggest.query.SuggesterFuzzyQuery) Term(org.apache.lucene.index.Term) Test(org.junit.jupiter.api.Test)

Aggregations

Term (org.apache.lucene.index.Term)2 SuggesterFuzzyQuery (org.opengrok.suggest.query.SuggesterFuzzyQuery)2 TermQuery (org.apache.lucene.search.TermQuery)1 Test (org.junit.jupiter.api.Test)1