Search in sources :

Example 1 with LindenRangeQuery

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

LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)1 LindenRange (com.xiaomi.linden.thrift.common.LindenRange)1 LindenRangeQuery (com.xiaomi.linden.thrift.common.LindenRangeQuery)1 LindenType (com.xiaomi.linden.thrift.common.LindenType)1 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)1 Query (org.apache.lucene.search.Query)1 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)1