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);
}
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"));
}
Aggregations