Search in sources :

Example 6 with LindenBooleanSubFilter

use of com.xiaomi.linden.thrift.common.LindenBooleanSubFilter 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

LindenBooleanSubFilter (com.xiaomi.linden.thrift.common.LindenBooleanSubFilter)6 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)6 LindenBooleanFilter (com.xiaomi.linden.thrift.common.LindenBooleanFilter)5 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)4 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)4 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)4 Test (org.junit.Test)4 LindenWildcardQuery (com.xiaomi.linden.thrift.common.LindenWildcardQuery)3 LindenQueryFilter (com.xiaomi.linden.thrift.common.LindenQueryFilter)2 LindenBooleanFilterBuilder (com.xiaomi.linden.thrift.builder.filter.LindenBooleanFilterBuilder)1 LindenFacet (com.xiaomi.linden.thrift.common.LindenFacet)1 LindenFacetDimAndPath (com.xiaomi.linden.thrift.common.LindenFacetDimAndPath)1 LindenFacetParam (com.xiaomi.linden.thrift.common.LindenFacetParam)1 LindenTerm (com.xiaomi.linden.thrift.common.LindenTerm)1 LindenType (com.xiaomi.linden.thrift.common.LindenType)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1 BooleanFilter (org.apache.lucene.queries.BooleanFilter)1