use of org.opengrok.suggest.query.SuggesterWildcardQuery in project OpenGrok by OpenGrok.
the class SuggesterSearcherTest method suggesterWildcardQueryTest.
@Test
public void suggesterWildcardQueryTest() {
List<LookupResultItem> suggestions = searcher.suggest(new TermQuery(new Term("test", "test")), "test", new SuggesterWildcardQuery(new Term("test", "?pengrok")), k -> 0);
List<String> tokens = suggestions.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList());
assertThat(tokens, contains("opengrok"));
}
use of org.opengrok.suggest.query.SuggesterWildcardQuery in project OpenGrok by OpenGrok.
the class SuggesterTest method testComplexQuerySearch.
@Test
public void testComplexQuerySearch() throws IOException {
SuggesterTestData t = initSuggester();
List<LookupResultItem> res = t.s.search(Collections.singletonList(t.getNamedIndexReader()), new SuggesterWildcardQuery(new Term("test", "*1")), null).getItems();
assertThat(res.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList()), contains("term1"));
t.close();
}
use of org.opengrok.suggest.query.SuggesterWildcardQuery in project OpenGrok by OpenGrok.
the class SuggesterQueryParser method newWildcardQuery.
@Override
protected Query newWildcardQuery(final Term t) {
if (t.text().contains(identifier)) {
String term = t.text().replace(identifier, "");
if (term.endsWith("*") && !containsWildcardCharacter(term.substring(0, term.length() - 1))) {
// the term ends with "*" but contains no other wildcard characters so faster method can be used
replaceIdentifier(t.field(), t.text());
term = term.substring(0, term.length() - 1);
SuggesterPrefixQuery q = new SuggesterPrefixQuery(new Term(t.field(), term));
this.suggesterQuery = q;
return q;
} else {
SuggesterWildcardQuery q = new SuggesterWildcardQuery(replaceIdentifier(t, identifier));
replaceIdentifier(t.field(), t.text());
this.suggesterQuery = q;
return q;
}
}
return super.newWildcardQuery(t);
}
Aggregations