Search in sources :

Example 1 with SuggesterRangeQuery

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

the class SuggesterSearcherTest method testRangeQueryUpper.

@Test
public void testRangeQueryUpper() {
    SuggesterRangeQuery q = new SuggesterRangeQuery("test", new BytesRef("opengrok"), new BytesRef("t"), true, true, SuggesterRangeQuery.SuggestPosition.UPPER);
    List<LookupResultItem> suggestions = searcher.suggest(null, "test", q, k -> 0);
    List<String> tokens = suggestions.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList());
    assertThat(tokens, contains("test"));
}
Also used : SuggesterRangeQuery(org.opengrok.suggest.query.SuggesterRangeQuery) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.jupiter.api.Test)

Example 2 with SuggesterRangeQuery

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

the class SuggesterSearcherTest method testRangeQueryLower.

@Test
public void testRangeQueryLower() {
    SuggesterRangeQuery q = new SuggesterRangeQuery("test", new BytesRef("o"), new BytesRef("test"), true, true, SuggesterRangeQuery.SuggestPosition.LOWER);
    List<LookupResultItem> suggestions = searcher.suggest(null, "test", q, k -> 0);
    List<String> tokens = suggestions.stream().map(LookupResultItem::getPhrase).collect(Collectors.toList());
    assertThat(tokens, contains("opengrok", "opengrok2"));
}
Also used : SuggesterRangeQuery(org.opengrok.suggest.query.SuggesterRangeQuery) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.jupiter.api.Test)

Example 3 with SuggesterRangeQuery

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

the class SuggesterQueryParser method newRangeQuery.

@Override
protected Query newRangeQuery(final String field, final String lowerTerm, final String upperTerm, final boolean startInclusive, final boolean endInclusive) {
    if (lowerTerm.contains(identifier)) {
        String bareLowerTerm = lowerTerm.replace(identifier, "");
        replaceIdentifier(field, lowerTerm);
        SuggesterRangeQuery rangeQuery = new SuggesterRangeQuery(field, new BytesRef(bareLowerTerm), new BytesRef(upperTerm), startInclusive, endInclusive, SuggesterRangeQuery.SuggestPosition.LOWER);
        this.suggesterQuery = rangeQuery;
        return rangeQuery;
    } else if (upperTerm.contains(identifier)) {
        String bareUpperTerm = upperTerm.replace(identifier, "");
        replaceIdentifier(field, upperTerm);
        SuggesterRangeQuery rangeQuery = new SuggesterRangeQuery(field, new BytesRef(lowerTerm), new BytesRef(bareUpperTerm), startInclusive, endInclusive, SuggesterRangeQuery.SuggestPosition.UPPER);
        this.suggesterQuery = rangeQuery;
        return rangeQuery;
    }
    return super.newRangeQuery(field, lowerTerm, upperTerm, startInclusive, endInclusive);
}
Also used : SuggesterRangeQuery(org.opengrok.suggest.query.SuggesterRangeQuery) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

BytesRef (org.apache.lucene.util.BytesRef)3 SuggesterRangeQuery (org.opengrok.suggest.query.SuggesterRangeQuery)3 Test (org.junit.jupiter.api.Test)2