use of org.opengrok.suggest.query.SuggesterPhraseQuery in project OpenGrok by OpenGrok.
the class SuggesterQueryParser method newBooleanClause.
@Override
protected BooleanClause newBooleanClause(final Query q, final BooleanClause.Occur occur) {
BooleanClause bc;
if (q instanceof SuggesterPhraseQuery) {
bc = super.newBooleanClause(((SuggesterPhraseQuery) q).getPhraseQuery(), BooleanClause.Occur.MUST);
suggesterClauses.add(bc);
} else if (q instanceof SuggesterQuery) {
bc = super.newBooleanClause(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
suggesterClauses.add(bc);
} else if (q instanceof BooleanQuery) {
bc = super.newBooleanClause(q, occur);
for (BooleanClause clause : ((BooleanQuery) q).clauses()) {
if (suggesterClauses.contains(clause)) {
suggesterClauses.add(bc);
}
}
} else {
bc = super.newBooleanClause(q, occur);
}
return bc;
}
use of org.opengrok.suggest.query.SuggesterPhraseQuery in project OpenGrok by OpenGrok.
the class SuggesterQueryParser method newFieldQuery.
@Override
protected Query newFieldQuery(final Analyzer analyzer, final String field, final String queryText, final boolean quoted) throws ParseException {
if (quoted && queryText.contains(identifier)) {
List<String> tokens = getAllTokens(analyzer, field, queryText);
SuggesterPhraseQuery spq = new SuggesterPhraseQuery(field, identifier, tokens, this.getPhraseSlop());
this.suggesterQuery = spq.getSuggesterQuery();
replaceIdentifier(field, tokens.stream().filter(t -> t.contains(identifier)).findAny().get());
return spq;
}
return super.newFieldQuery(analyzer, field, queryText, quoted);
}
use of org.opengrok.suggest.query.SuggesterPhraseQuery in project OpenGrok by OpenGrok.
the class SuggesterSearcherTest method suggesterPhraseQueryTest.
@Test
public void suggesterPhraseQueryTest() {
SuggesterPhraseQuery q = new SuggesterPhraseQuery("test", "abc", Arrays.asList("opengrok", "openabc"), 0);
List<LookupResultItem> suggestions = searcher.suggest(q.getPhraseQuery(), "test", q.getSuggesterQuery(), k -> 0);
List<String> tokens = suggestions.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList());
assertThat(tokens, contains("opengrok2"));
}
Aggregations