Search in sources :

Example 1 with LindenQueryStringQueryBuilder

use of com.xiaomi.linden.thrift.builder.query.LindenQueryStringQueryBuilder in project linden by XiaoMi.

the class BQLCompilerAnalyzer method exitQuery_predicate.

@Override
public void exitQuery_predicate(BQLParser.Query_predicateContext ctx) {
    String orig = unescapeStringLiteral(ctx.STRING_LITERAL());
    LindenQueryStringQueryBuilder builder = new LindenQueryStringQueryBuilder().setQuery(orig);
    if (ctx.disable_coord != null) {
        builder.setDisableCoord((Boolean) valProperty.get(ctx.disable_coord));
    }
    if (ctx.AND() != null) {
        builder.setOperator(Operator.AND);
    }
    LindenQuery stringQuery = builder.build();
    if (inQueryWhere) {
        queryProperty.put(ctx, stringQuery);
    } else {
        LindenFilter filter = LindenQueryFilterBuilder.buildQueryFilter(stringQuery);
        filterProperty.put(ctx, filter);
    }
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenQueryStringQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenQueryStringQueryBuilder)

Example 2 with LindenQueryStringQueryBuilder

use of com.xiaomi.linden.thrift.builder.query.LindenQueryStringQueryBuilder in project linden by XiaoMi.

the class TestBQL method testQueryPredicate.

@Test
public void testQueryPredicate() {
    String bql = "select * from linden where query is 'title:a' and id = 233";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
    Assert.assertEquals(2, lindenRequest.getFilter().getBooleanFilter().getFilters().size());
    Assert.assertTrue(lindenRequest.getFilter().getBooleanFilter().getFilters().get(0).getFilter().isSetQueryFilter());
    bql = "select * from linden by query is 'abc' and query is 'def' where id = 1 or id = 3";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertTrue(lindenRequest.getQuery().isSetBooleanQuery());
    Assert.assertEquals(2, lindenRequest.getQuery().getBooleanQuery().getQueriesSize());
    Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
    Assert.assertEquals(2, lindenRequest.getFilter().getBooleanFilter().getFilters().size());
    bql = "select * from linden by query is 'title:abc bcd' disableCoord OP(AND)";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    LindenQueryStringQueryBuilder builder = new LindenQueryStringQueryBuilder();
    builder.setQuery("title:abc bcd").setOperator(Operator.AND);
    builder.setDisableCoord(true);
    LindenQuery expected = builder.build();
    Assert.assertEquals(expected, lindenRequest.getQuery());
}
Also used : LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) LindenQueryStringQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenQueryStringQueryBuilder) Test(org.junit.Test)

Aggregations

LindenQueryStringQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenQueryStringQueryBuilder)2 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)2 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)1 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)1 Test (org.junit.Test)1