Search in sources :

Example 21 with LindenFilter

use of com.xiaomi.linden.thrift.common.LindenFilter in project linden by XiaoMi.

the class TestBQL method testNotEqualPred.

@Test
public void testNotEqualPred() throws Exception {
    String bql = "SELECT * FROM linden  WHERE title <> 'red'";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenBooleanFilter booleanFilter = new LindenBooleanFilter();
    LindenFilter termFilter = LindenTermFilterBuilder.buildTermFilter("title", "red");
    booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(termFilter).setClause(LindenBooleanClause.MUST_NOT));
    Assert.assertEquals(booleanFilter, lindenRequest.getFilter().getBooleanFilter());
    bql = "SELECT * FROM linden  WHERE title <> 're''d'";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    booleanFilter = new LindenBooleanFilter();
    termFilter = LindenTermFilterBuilder.buildTermFilter("title", "re'd");
    booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(termFilter).setClause(LindenBooleanClause.MUST_NOT));
    Assert.assertEquals(booleanFilter, lindenRequest.getFilter().getBooleanFilter());
    bql = "SELECT * FROM linden  WHERE id <> 2000";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    booleanFilter = new LindenBooleanFilter();
    LindenFilter rangeFilter = LindenRangeFilterBuilder.buildRangeFilter("id", LindenType.LONG, "2000", "2000", true, true);
    booleanFilter.addToFilters(new LindenBooleanSubFilter().setFilter(rangeFilter).setClause(LindenBooleanClause.MUST_NOT));
    Assert.assertEquals(booleanFilter, lindenRequest.getFilter().getBooleanFilter());
    bql = "SELECT * FROM linden WHERE id <> $id";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertEquals(null, lindenRequest.getFilter());
    bql = "SELECT * FROM linden BY title <> 're''d'";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
    builder.addQuery(LindenRangeQueryBuilder.buildMatchAllQuery(), LindenBooleanClause.MUST);
    builder.addQuery(LindenRangeQueryBuilder.buildTermQuery("title", "re'd"), LindenBooleanClause.MUST_NOT);
    Assert.assertEquals(builder.build(), lindenRequest.getQuery());
    bql = "SELECT * FROM linden BY id <> $id";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertEquals(LindenQueryBuilder.buildMatchAllQuery(), lindenRequest.getQuery());
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenBooleanFilter(com.xiaomi.linden.thrift.common.LindenBooleanFilter) LindenBooleanSubFilter(com.xiaomi.linden.thrift.common.LindenBooleanSubFilter) LindenBooleanQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 22 with LindenFilter

use of com.xiaomi.linden.thrift.common.LindenFilter in project linden by XiaoMi.

the class RangeFilterConstructor method construct.

@Override
protected Filter construct(LindenFilter lindenFilter, LindenConfig config) throws IOException {
    LindenRangeFilter lindenRangeFilter = lindenFilter.getRangeFilter();
    LindenRange range = lindenRangeFilter.getRange();
    LindenType type = range.getType();
    String start = range.getStartValue();
    String end = range.getEndValue();
    String fieldName = range.getField();
    boolean startClose = range.isStartClosed();
    boolean endClose = range.isEndClosed();
    Filter filter = null;
    switch(type) {
        case STRING:
        case FACET:
            filter = new TermRangeFilter(fieldName, bytesRefVal(start), bytesRefVal(end), startClose, endClose);
            break;
        case INTEGER:
            filter = NumericRangeFilter.newIntRange(fieldName, intVal(start), intVal(end), startClose, endClose);
            break;
        case LONG:
            filter = NumericRangeFilter.newLongRange(fieldName, longVal(start), longVal(end), startClose, endClose);
            break;
        case DOUBLE:
            filter = NumericRangeFilter.newDoubleRange(fieldName, doubleVal(start), doubleVal(end), startClose, endClose);
            break;
        case FLOAT:
            filter = NumericRangeFilter.newFloatRange(fieldName, floatVal(start), floatVal(end), startClose, endClose);
            break;
    }
    return filter;
}
Also used : LindenRangeFilter(com.xiaomi.linden.thrift.common.LindenRangeFilter) LindenRangeFilter(com.xiaomi.linden.thrift.common.LindenRangeFilter) LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) TermRangeFilter(org.apache.lucene.search.TermRangeFilter) Filter(org.apache.lucene.search.Filter) NumericRangeFilter(org.apache.lucene.search.NumericRangeFilter) LindenType(com.xiaomi.linden.thrift.common.LindenType) LindenRange(com.xiaomi.linden.thrift.common.LindenRange) TermRangeFilter(org.apache.lucene.search.TermRangeFilter)

Aggregations

LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)22 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)17 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)10 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)9 Test (org.junit.Test)8 LindenType (com.xiaomi.linden.thrift.common.LindenType)7 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)7 LindenBooleanFilterBuilder (com.xiaomi.linden.thrift.builder.filter.LindenBooleanFilterBuilder)6 LindenBooleanSubFilter (com.xiaomi.linden.thrift.common.LindenBooleanSubFilter)6 AbstractMap (java.util.AbstractMap)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 LindenBooleanFilter (com.xiaomi.linden.thrift.common.LindenBooleanFilter)5 LindenWildcardQuery (com.xiaomi.linden.thrift.common.LindenWildcardQuery)3 ArrayList (java.util.ArrayList)3 LindenQueryFilter (com.xiaomi.linden.thrift.common.LindenQueryFilter)2 LindenQueryStringQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenQueryStringQueryBuilder)1 GroupParam (com.xiaomi.linden.thrift.common.GroupParam)1 LindenBooleanClause (com.xiaomi.linden.thrift.common.LindenBooleanClause)1 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)1