Search in sources :

Example 1 with LindenRange

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

the class TestBQL method testEqualPredicate.

@Test
public void testEqualPredicate() {
    String bql = "select * from linden where title = \"qq\" and id = 211 limit 10, 50";
    LindenSearchRequest lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
    LindenBooleanFilter booleanFilter = lindenRequest.getFilter().getBooleanFilter();
    Assert.assertEquals(2, booleanFilter.getFiltersSize());
    Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(0).getClause());
    Assert.assertEquals(new LindenTerm("title", "qq"), booleanFilter.getFilters().get(0).getFilter().getTermFilter().getTerm());
    Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(1).getClause());
    Assert.assertEquals(new LindenRange("id", LindenType.LONG, true, true).setStartValue("211").setEndValue("211"), booleanFilter.getFilters().get(1).getFilter().getRangeFilter().getRange());
    Assert.assertEquals(10, lindenRequest.getOffset());
    Assert.assertEquals(50, lindenRequest.getLength());
    bql = "delete from default where title = \"q\"\"q\" and id = 211";
    LindenDeleteRequest deleteRequest = compiler.compile(bql).getDeleteRequest();
    Assert.assertTrue(deleteRequest.getQuery().isSetFilteredQuery());
    Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().isSetLindenFilter());
    Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().getLindenFilter().isSetBooleanFilter());
    booleanFilter = deleteRequest.getQuery().getFilteredQuery().getLindenFilter().getBooleanFilter();
    Assert.assertEquals(2, booleanFilter.getFiltersSize());
    Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(0).getClause());
    Assert.assertEquals(new LindenTerm("title", "q\"q"), booleanFilter.getFilters().get(0).getFilter().getTermFilter().getTerm());
    Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(1).getClause());
    Assert.assertEquals(new LindenRange("id", LindenType.LONG, true, true).setStartValue("211").setEndValue("211"), booleanFilter.getFilters().get(1).getFilter().getRangeFilter().getRange());
    bql = "delete from default where title = $a and id = 211";
    deleteRequest = compiler.compile(bql).getDeleteRequest();
    Assert.assertTrue(deleteRequest.getQuery().isSetFilteredQuery());
    Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().isSetLindenFilter());
    Assert.assertTrue(deleteRequest.getQuery().getFilteredQuery().getLindenFilter().isSetRangeFilter());
    bql = "select * from linden where dynmaicTitle.STRING = \"qq\" and dynamicId.int = 211 limit 10, 50";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertTrue(lindenRequest.getFilter().isSetBooleanFilter());
    booleanFilter = lindenRequest.getFilter().getBooleanFilter();
    Assert.assertEquals(2, booleanFilter.getFiltersSize());
    Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(0).getClause());
    Assert.assertEquals(new LindenTerm("dynmaicTitle", "qq"), booleanFilter.getFilters().get(0).getFilter().getTermFilter().getTerm());
    Assert.assertEquals(LindenBooleanClause.MUST, booleanFilter.getFilters().get(1).getClause());
    Assert.assertEquals(new LindenRange("dynamicId", LindenType.INTEGER, true, true).setStartValue("211").setEndValue("211"), booleanFilter.getFilters().get(1).getFilter().getRangeFilter().getRange());
    Assert.assertEquals(10, lindenRequest.getOffset());
    Assert.assertEquals(50, lindenRequest.getLength());
    bql = "select * from linden by title = \"qq\" subBoost by 0.5 and id = 211 andDisableCoord limit 10, 50";
    lindenRequest = compiler.compile(bql).getSearchRequest();
    Assert.assertFalse(lindenRequest.isSetFilter());
    Assert.assertTrue(lindenRequest.getQuery().isSetBooleanQuery());
    LindenBooleanQuery query = lindenRequest.getQuery().getBooleanQuery();
    Assert.assertTrue(query.isDisableCoord());
    Assert.assertEquals(2, query.getQueriesSize());
    Assert.assertEquals(LindenBooleanClause.MUST, query.getQueries().get(0).clause);
    Assert.assertEquals(new LindenTerm("title", "qq"), query.getQueries().get(0).getQuery().getTermQuery().getTerm());
    Assert.assertEquals(0.5, query.getQueries().get(0).getQuery().getBoost(), 0.001);
    Assert.assertEquals(LindenBooleanClause.MUST, query.getQueries().get(1).clause);
    Assert.assertEquals(new LindenRange("id", LindenType.LONG, true, true).setStartValue("211").setEndValue("211"), query.getQueries().get(1).getQuery().getRangeQuery().getRange());
    Assert.assertEquals(10, lindenRequest.getOffset());
    Assert.assertEquals(50, lindenRequest.getLength());
}
Also used : LindenBooleanQuery(com.xiaomi.linden.thrift.common.LindenBooleanQuery) LindenDeleteRequest(com.xiaomi.linden.thrift.common.LindenDeleteRequest) LindenBooleanFilter(com.xiaomi.linden.thrift.common.LindenBooleanFilter) LindenTerm(com.xiaomi.linden.thrift.common.LindenTerm) LindenRange(com.xiaomi.linden.thrift.common.LindenRange) LindenSearchRequest(com.xiaomi.linden.thrift.common.LindenSearchRequest) Test(org.junit.Test)

Example 2 with LindenRange

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

Example 3 with LindenRange

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

the class RangeQueryConstructor method construct.

@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws IOException {
    if (lindenQuery.isSetRangeQuery()) {
        LindenRangeQuery lindenRangeQuery = lindenQuery.getRangeQuery();
        LindenRange range = lindenRangeQuery.getRange();
        String fieldName = range.getField();
        LindenType type = range.getType();
        String start = range.getStartValue();
        String end = range.getEndValue();
        boolean startClose = range.isStartClosed();
        boolean endClose = range.isEndClosed();
        Query query = null;
        switch(type) {
            case STRING:
            case FACET:
                query = new TermRangeQuery(fieldName, bytesRefVal(start), bytesRefVal(end), startClose, endClose);
                break;
            case INTEGER:
                query = NumericRangeQuery.newIntRange(fieldName, intVal(start), intVal(end), startClose, endClose);
                break;
            case LONG:
                query = NumericRangeQuery.newLongRange(fieldName, longVal(start), longVal(end), startClose, endClose);
                break;
            case DOUBLE:
                query = NumericRangeQuery.newDoubleRange(fieldName, doubleVal(start), doubleVal(end), startClose, endClose);
                break;
            case FLOAT:
                query = NumericRangeQuery.newFloatRange(fieldName, floatVal(start), floatVal(end), startClose, endClose);
                break;
        }
        return query;
    }
    // todo throw exception.
    return null;
}
Also used : Query(org.apache.lucene.search.Query) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenRangeQuery(com.xiaomi.linden.thrift.common.LindenRangeQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) LindenRangeQuery(com.xiaomi.linden.thrift.common.LindenRangeQuery) LindenType(com.xiaomi.linden.thrift.common.LindenType) LindenRange(com.xiaomi.linden.thrift.common.LindenRange)

Aggregations

LindenRange (com.xiaomi.linden.thrift.common.LindenRange)3 LindenType (com.xiaomi.linden.thrift.common.LindenType)2 LindenBooleanFilter (com.xiaomi.linden.thrift.common.LindenBooleanFilter)1 LindenBooleanQuery (com.xiaomi.linden.thrift.common.LindenBooleanQuery)1 LindenDeleteRequest (com.xiaomi.linden.thrift.common.LindenDeleteRequest)1 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)1 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)1 LindenRangeFilter (com.xiaomi.linden.thrift.common.LindenRangeFilter)1 LindenRangeQuery (com.xiaomi.linden.thrift.common.LindenRangeQuery)1 LindenSearchRequest (com.xiaomi.linden.thrift.common.LindenSearchRequest)1 LindenTerm (com.xiaomi.linden.thrift.common.LindenTerm)1 Filter (org.apache.lucene.search.Filter)1 NumericRangeFilter (org.apache.lucene.search.NumericRangeFilter)1 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)1 Query (org.apache.lucene.search.Query)1 TermRangeFilter (org.apache.lucene.search.TermRangeFilter)1 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)1 Test (org.junit.Test)1