Search in sources :

Example 11 with LindenBooleanQueryBuilder

use of com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder 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)

Aggregations

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