Search in sources :

Example 1 with SuggesterWildcardQuery

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"));
}
Also used : TermQuery(org.apache.lucene.search.TermQuery) SuggesterWildcardQuery(org.opengrok.suggest.query.SuggesterWildcardQuery) Term(org.apache.lucene.index.Term) Test(org.junit.jupiter.api.Test)

Example 2 with SuggesterWildcardQuery

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();
}
Also used : SuggesterWildcardQuery(org.opengrok.suggest.query.SuggesterWildcardQuery) Term(org.apache.lucene.index.Term) Test(org.junit.jupiter.api.Test)

Example 3 with SuggesterWildcardQuery

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);
}
Also used : SuggesterWildcardQuery(org.opengrok.suggest.query.SuggesterWildcardQuery) SuggesterPrefixQuery(org.opengrok.suggest.query.SuggesterPrefixQuery) Term(org.apache.lucene.index.Term)

Aggregations

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