Search in sources :

Example 1 with LindenBooleanClause

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

the class LindenBooleanQueryBuilder method build.

@Override
public LindenQuery build() {
    LindenBooleanQuery booleanQuery = new LindenBooleanQuery();
    for (Map.Entry<LindenQuery, LindenBooleanClause> query : queries) {
        booleanQuery.addToQueries(new LindenBooleanSubQuery().setQuery(query.getKey()).setClause(query.getValue()));
    }
    booleanQuery.setDisableCoord(disableCoord);
    return new LindenQuery().setBooleanQuery(booleanQuery).setBoost(boost);
}
Also used : LindenBooleanQuery(com.xiaomi.linden.thrift.common.LindenBooleanQuery) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) LindenBooleanSubQuery(com.xiaomi.linden.thrift.common.LindenBooleanSubQuery) LindenBooleanClause(com.xiaomi.linden.thrift.common.LindenBooleanClause) AbstractMap(java.util.AbstractMap) Map(java.util.Map)

Example 2 with LindenBooleanClause

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

the class BQLCompilerAnalyzer method exitIn_predicate.

@Override
public void exitIn_predicate(BQLParser.In_predicateContext ctx) {
    String col = unescapeColumnName(ctx.column_name());
    Map.Entry<String, LindenType> fieldNameAndType = getFieldNameAndType(col);
    LindenType type = fieldNameAndType.getValue();
    col = fieldNameAndType.getKey();
    List<Object> values = (List<Object>) valProperty.get(ctx.value_list());
    List<Object> excludes = (List<Object>) valProperty.get(ctx.except_clause());
    List<Map.Entry<String, LindenBooleanClause>> subClauses = new ArrayList<>();
    LindenBooleanClause clause = LindenBooleanClause.SHOULD;
    if (ctx.not != null) {
        clause = LindenBooleanClause.MUST_NOT;
    }
    for (int i = 0; values != null && i < values.size(); ++i) {
        if (values.get(i) == null) {
            continue;
        }
        subClauses.add(new AbstractMap.SimpleEntry<>(values.get(i).toString(), clause));
    }
    clause = LindenBooleanClause.MUST_NOT;
    if (ctx.not != null) {
        clause = LindenBooleanClause.SHOULD;
    }
    for (int i = 0; excludes != null && i < excludes.size(); ++i) {
        if (excludes.get(i) == null) {
            continue;
        }
        subClauses.add(new AbstractMap.SimpleEntry<>(excludes.get(i).toString(), clause));
    }
    if (subClauses.size() == 0) {
        return;
    }
    if (inQueryWhere) {
        LindenBooleanQueryBuilder builder = new LindenBooleanQueryBuilder();
        for (Map.Entry<String, LindenBooleanClause> clauseEntry : subClauses) {
            LindenQuery query;
            switch(type) {
                case STRING:
                case FACET:
                    query = LindenQueryBuilder.buildTermQuery(col, clauseEntry.getKey());
                    break;
                case LONG:
                case INTEGER:
                case FLOAT:
                case DOUBLE:
                    query = LindenRangeQueryBuilder.buildRangeQuery(col, type, clauseEntry.getKey(), clauseEntry.getKey(), true, true);
                    break;
                default:
                    throw new ParseCancellationException("IN predicate doesn't support this type " + type);
            }
            builder.addQuery(query, clauseEntry.getValue());
        }
        queryProperty.put(ctx, builder.build());
    } else {
        LindenBooleanFilterBuilder builder = new LindenBooleanFilterBuilder();
        for (Map.Entry<String, LindenBooleanClause> clauseEntry : subClauses) {
            LindenFilter filter;
            switch(type) {
                case STRING:
                case FACET:
                    filter = LindenTermFilterBuilder.buildTermFilter(col, clauseEntry.getKey());
                    break;
                case LONG:
                case INTEGER:
                case FLOAT:
                case DOUBLE:
                    filter = LindenRangeFilterBuilder.buildRangeFilter(col, type, clauseEntry.getKey(), clauseEntry.getKey(), true, true);
                    break;
                default:
                    throw new ParseCancellationException("IN predicate doesn't support this type " + type);
            }
            builder.addFilter(filter, clauseEntry.getValue());
        }
        filterProperty.put(ctx, builder.build());
    }
}
Also used : LindenBooleanFilterBuilder(com.xiaomi.linden.thrift.builder.filter.LindenBooleanFilterBuilder) ArrayList(java.util.ArrayList) LindenType(com.xiaomi.linden.thrift.common.LindenType) AbstractMap(java.util.AbstractMap) LindenFilter(com.xiaomi.linden.thrift.common.LindenFilter) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) ParseCancellationException(org.antlr.v4.runtime.misc.ParseCancellationException) LindenBooleanQueryBuilder(com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder) List(java.util.List) ArrayList(java.util.ArrayList) LindenBooleanClause(com.xiaomi.linden.thrift.common.LindenBooleanClause) Map(java.util.Map) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap)

Aggregations

LindenBooleanClause (com.xiaomi.linden.thrift.common.LindenBooleanClause)2 LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)2 AbstractMap (java.util.AbstractMap)2 Map (java.util.Map)2 LindenBooleanFilterBuilder (com.xiaomi.linden.thrift.builder.filter.LindenBooleanFilterBuilder)1 LindenBooleanQueryBuilder (com.xiaomi.linden.thrift.builder.query.LindenBooleanQueryBuilder)1 LindenBooleanQuery (com.xiaomi.linden.thrift.common.LindenBooleanQuery)1 LindenBooleanSubQuery (com.xiaomi.linden.thrift.common.LindenBooleanSubQuery)1 LindenFilter (com.xiaomi.linden.thrift.common.LindenFilter)1 LindenType (com.xiaomi.linden.thrift.common.LindenType)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)1