Search in sources :

Example 6 with SuggesterPrefixQuery

use of org.opengrok.suggest.query.SuggesterPrefixQuery 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)

Example 7 with SuggesterPrefixQuery

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

the class SuggesterQueryParser method newPrefixQuery.

@Override
protected Query newPrefixQuery(final Term prefix) {
    if (prefix.text().contains(identifier)) {
        SuggesterPrefixQuery q = new SuggesterPrefixQuery(replaceIdentifier(prefix, identifier));
        this.suggesterQuery = q;
        return q;
    }
    return super.newPrefixQuery(prefix);
}
Also used : SuggesterPrefixQuery(org.opengrok.suggest.query.SuggesterPrefixQuery)

Aggregations

SuggesterPrefixQuery (org.opengrok.suggest.query.SuggesterPrefixQuery)7 Term (org.apache.lucene.index.Term)5 Test (org.junit.jupiter.api.Test)4 SuggesterWildcardQuery (org.opengrok.suggest.query.SuggesterWildcardQuery)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 BoostQuery (org.apache.lucene.search.BoostQuery)1 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Query (org.apache.lucene.search.Query)1 TermQuery (org.apache.lucene.search.TermQuery)1 SuggesterFuzzyQuery (org.opengrok.suggest.query.SuggesterFuzzyQuery)1 SuggesterPhraseQuery (org.opengrok.suggest.query.SuggesterPhraseQuery)1 SuggesterQuery (org.opengrok.suggest.query.SuggesterQuery)1 SuggesterRangeQuery (org.opengrok.suggest.query.SuggesterRangeQuery)1 SuggesterRegexpQuery (org.opengrok.suggest.query.SuggesterRegexpQuery)1