Search in sources :

Example 1 with SuggesterRegexpQuery

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

the class SuggesterSearcherTest method suggesterRegexpQueryTest.

@Test
public void suggesterRegexpQueryTest() {
    List<LookupResultItem> suggestions = searcher.suggest(new TermQuery(new Term("test", "test")), "test", new SuggesterRegexpQuery(new Term("test", ".pengrok")), 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) SuggesterRegexpQuery(org.opengrok.suggest.query.SuggesterRegexpQuery) Term(org.apache.lucene.index.Term) Test(org.junit.jupiter.api.Test)

Example 2 with SuggesterRegexpQuery

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

the class SuggesterQueryParser method newRegexpQuery.

@Override
protected Query newRegexpQuery(final Term regexp) {
    if (regexp.text().contains(identifier)) {
        Term newTerm = replaceIdentifier(regexp, identifier);
        replaceIdentifier(regexp.field(), "/" + regexp.text() + "/");
        SuggesterRegexpQuery q = new SuggesterRegexpQuery(newTerm);
        this.suggesterQuery = q;
        return q;
    }
    return super.newRegexpQuery(regexp);
}
Also used : SuggesterRegexpQuery(org.opengrok.suggest.query.SuggesterRegexpQuery) Term(org.apache.lucene.index.Term)

Aggregations

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