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);
}
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());
}
}
Aggregations