Search in sources :

Example 1 with LindenType

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

the class LindenQueryParser method getRangeQuery.

@Override
protected Query getRangeQuery(String field, String min, String max, boolean startInclusive, boolean endInclusive) {
    LindenFieldSchema fieldSchema = config.getFieldSchema(field);
    String name = fieldSchema.getName();
    LindenType indexFieldType = fieldSchema.getType();
    Query query = null;
    switch(indexFieldType) {
        case STRING:
            query = new TermRangeQuery(name, bytesRefVal(min), bytesRefVal(max), startInclusive, endInclusive);
            break;
        case INTEGER:
            query = NumericRangeQuery.newIntRange(name, intVal(min), intVal(max), startInclusive, endInclusive);
            break;
        case LONG:
            query = NumericRangeQuery.newLongRange(name, longVal(min), longVal(max), startInclusive, endInclusive);
            break;
        case DOUBLE:
            query = NumericRangeQuery.newDoubleRange(name, doubleVal(min), doubleVal(max), startInclusive, endInclusive);
            break;
        case FLOAT:
            query = NumericRangeQuery.newFloatRange(name, floatVal(min), floatVal(max), startInclusive, endInclusive);
            break;
        default:
            break;
    }
    return query;
}
Also used : LindenFieldSchema(com.xiaomi.linden.thrift.common.LindenFieldSchema) Query(org.apache.lucene.search.Query) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) LindenType(com.xiaomi.linden.thrift.common.LindenType)

Example 2 with LindenType

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

the class BQLCompilerAnalyzer method exitSnippet_clause.

@Override
public void exitSnippet_clause(BQLParser.Snippet_clauseContext ctx) {
    if (ctx.selection_list() != null) {
        List<String> selections = (List<String>) valProperty.get(ctx.selection_list());
        if (selections != null && !selections.isEmpty()) {
            SnippetParam snippet = new SnippetParam();
            for (String selection : selections) {
                Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(selection);
                LindenType type = fieldNameAndType.getValue();
                String col = fieldNameAndType.getKey();
                if (type == LindenType.STRING) {
                    snippet.addToFields(new SnippetField(col));
                } else {
                    throw new ParseCancellationException("Snippet doesn't support this type " + type);
                }
            }
            valProperty.put(ctx, snippet);
        }
    }
}
Also used : ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) LindenType(com.xiaomi.linden.thrift.common.LindenType) SnippetField(com.xiaomi.linden.thrift.common.SnippetField) List(java.util.List) ArrayList(java.util.ArrayList) SnippetParam(com.xiaomi.linden.thrift.common.SnippetParam) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 3 with LindenType

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

the class BQLCompilerAnalyzer method exitFlexible_field.

@Override
public void exitFlexible_field(BQLParser.Flexible_fieldContext ctx) {
    String col = unescapeColumnName(ctx.column_name());
    Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
    col = fieldNameAndType.getKey();
    LindenSearchField field = new LindenSearchField().setName(col);
    if (ctx.boost != null && ctx.boost.PLACEHOLDER() == null) {
        field.setBoost(Double.valueOf(ctx.boost.getText()));
    }
    valProperty.put(ctx, field);
}
Also used : LindenSearchField(com.xiaomi.linden.thrift.common.LindenSearchField) LindenType(com.xiaomi.linden.thrift.common.LindenType) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 4 with LindenType

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

the class BQLCompilerAnalyzer method exitNull_predicate.

@Override
public void exitNull_predicate(BQLParser.Null_predicateContext ctx) {
    String col = unescapeColumnName(ctx.column_name());
    Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
    col = fieldNameAndType.getKey();
    LindenFilter filter;
    if (ctx.NOT() != null) {
        filter = LindenNotNullFieldFilterBuilder.buildNotNullFieldFilterBuilder(col, false);
    } else {
        filter = LindenNotNullFieldFilterBuilder.buildNotNullFieldFilterBuilder(col, true);
    }
    if (inQueryWhere) {
        LindenQuery query = LindenQueryBuilder.buildFilteredQuery(LindenQueryBuilder.buildMatchAllQuery(), filter);
        queryProperty.put(ctx, query);
    } else {
        filterProperty.put(ctx, filter);
    }
}
Also used : LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenType(com.xiaomi.linden.thrift.common.LindenType) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Example 5 with LindenType

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

the class BQLCompilerAnalyzer method exitSort_spec.

@Override
public void exitSort_spec(BQLParser.Sort_specContext ctx) {
    LindenSortField sortField;
    if (ctx.DISTANCE() != null) {
        sortField = new LindenSortField().setName("").setType(LindenSortType.DISTANCE);
    } else if (ctx.SCORE() != null) {
        sortField = new LindenSortField().setName("").setType(LindenSortType.SCORE);
    } else {
        String col = unescapeColumnName(ctx.column_name());
        Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
        LindenType type = fieldNameAndType.getValue();
        col = fieldNameAndType.getKey();
        LindenSortType sortType = LindenSortType.findByValue(type.getValue());
        sortField = new LindenSortField().setName(col).setType(sortType).setReverse(true);
    }
    if (ctx.ASC() != null) {
        sortField.setReverse(false);
    } else if (ctx.DESC() != null) {
        sortField.setReverse(true);
    }
    valProperty.put(ctx, sortField);
}
Also used : LindenType(com.xiaomi.linden.thrift.common.LindenType) LindenSortField(com.xiaomi.linden.thrift.common.LindenSortField) LindenSortType(com.xiaomi.linden.thrift.common.LindenSortType)

Aggregations

LindenType (com.xiaomi.linden.thrift.common.LindenType)20 AbstractMap (java.util.AbstractMap)14 HashMap (java.util.HashMap)14 Map (java.util.Map)14 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)10 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)7 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)7 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 LindenBooleanFilterBuilder (com.xiaomi.linden.thrift.builder.filter.LindenBooleanFilterBuilder)3 Aggregation (com.xiaomi.linden.thrift.common.Aggregation)2 Bucket (com.xiaomi.linden.thrift.common.Bucket)2 LindenFacetDimAndPath (com.xiaomi.linden.thrift.common.LindenFacetDimAndPath)2 LindenFacetParam (com.xiaomi.linden.thrift.common.LindenFacetParam)2 LindenFieldSchema (com.xiaomi.linden.thrift.common.LindenFieldSchema)2 LindenRange (com.xiaomi.linden.thrift.common.LindenRange)2 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)2 Query (org.apache.lucene.search.Query)2 AggregationResult (com.xiaomi.linden.thrift.common.AggregationResult)1