use of com.xiaomi.linden.thrift.builder.filter.LindenBooleanFilterBuilder in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitSearch_expr.
@Override
public void exitSearch_expr(BQLParser.Search_exprContext ctx) {
if (inQueryWhere) {
List<LindenQuery> lindenQueries = new ArrayList<>();
for (BQLParser.Term_exprContext f : ctx.term_expr()) {
LindenQuery query = queryProperty.get(f);
if (query == null) {
continue;
}
lindenQueries.add(query);
}
if (lindenQueries.size() == 0) {
return;
}
if (lindenQueries.size() == 1) {
queryProperty.put(ctx, lindenQueries.get(0));
return;
}
boolean disableCoord = ctx.disable_coord == null ? false : (boolean) valProperty.get(ctx.disable_coord);
LindenBooleanQueryBuilder booleanQueryBuilder = new LindenBooleanQueryBuilder();
booleanQueryBuilder.setDisableCoord(disableCoord);
if (ctx.boost_by != null && ctx.boost_by.numeric_value().PLACEHOLDER() == null) {
booleanQueryBuilder.setBoost(Double.valueOf(ctx.boost_by.numeric_value().getText()));
}
for (int i = 0; i < lindenQueries.size(); ++i) {
// term_op indicates first clause is must
if (ctx.term_op != null && i == 0) {
booleanQueryBuilder.addQuery(lindenQueries.get(i), LindenBooleanClause.MUST);
} else {
booleanQueryBuilder.addQuery(lindenQueries.get(i), LindenBooleanClause.SHOULD);
}
}
LindenQuery lindenQuery = booleanQueryBuilder.build();
queryProperty.put(ctx, lindenQuery);
} else {
List<LindenFilter> lindenFilters = new ArrayList<>();
for (BQLParser.Term_exprContext f : ctx.term_expr()) {
LindenFilter filter = filterProperty.get(f);
if (filter == null) {
continue;
}
lindenFilters.add(filter);
}
if (lindenFilters.size() == 0) {
return;
}
if (lindenFilters.size() == 1) {
filterProperty.put(ctx, lindenFilters.get(0));
return;
}
LindenBooleanFilterBuilder booleanFilterBuilder = new LindenBooleanFilterBuilder();
for (int i = 0; i < lindenFilters.size(); ++i) {
// term_op indicates first clause is must
if (ctx.term_op != null && i == 0) {
booleanFilterBuilder.addFilter(lindenFilters.get(i), LindenBooleanClause.MUST);
} else {
booleanFilterBuilder.addFilter(lindenFilters.get(i), LindenBooleanClause.SHOULD);
}
}
LindenFilter lindenFilter = booleanFilterBuilder.build();
filterProperty.put(ctx, lindenFilter);
}
}
use of com.xiaomi.linden.thrift.builder.filter.LindenBooleanFilterBuilder in project linden by XiaoMi.
the class BQLCompilerAnalyzer method exitTerm_expr.
@Override
public void exitTerm_expr(BQLParser.Term_exprContext ctx) {
if (inQueryWhere) {
List<LindenQuery> lindenQueries = new ArrayList<>();
for (BQLParser.Factor_exprContext f : ctx.factor_expr()) {
LindenQuery query = queryProperty.get(f);
if (query == null) {
continue;
}
lindenQueries.add(query);
}
if (lindenQueries.size() == 0) {
return;
}
if (lindenQueries.size() == 1) {
queryProperty.put(ctx, lindenQueries.get(0));
return;
}
boolean disableCoord = ctx.disable_coord == null ? false : (boolean) valProperty.get(ctx.disable_coord);
LindenBooleanQueryBuilder booleanQueryBuilder = new LindenBooleanQueryBuilder();
booleanQueryBuilder.setDisableCoord(disableCoord);
if (ctx.boost_by != null && ctx.boost_by.numeric_value().PLACEHOLDER() == null) {
booleanQueryBuilder.setBoost(Double.valueOf(ctx.boost_by.numeric_value().getText()));
}
for (int i = 0; i < lindenQueries.size(); ++i) {
booleanQueryBuilder.addQuery(lindenQueries.get(i), LindenBooleanClause.MUST);
}
LindenQuery lindenQuery = booleanQueryBuilder.build();
queryProperty.put(ctx, lindenQuery);
} else {
List<LindenFilter> lindenFilters = new ArrayList<>();
for (BQLParser.Factor_exprContext f : ctx.factor_expr()) {
LindenFilter filter = filterProperty.get(f);
if (filter == null) {
continue;
}
lindenFilters.add(filter);
}
if (lindenFilters.size() == 0) {
return;
}
if (lindenFilters.size() == 1) {
filterProperty.put(ctx, lindenFilters.get(0));
return;
}
LindenBooleanFilterBuilder booleanFilterBuilder = new LindenBooleanFilterBuilder();
for (int i = 0; i < lindenFilters.size(); ++i) {
booleanFilterBuilder.addFilter(lindenFilters.get(i), LindenBooleanClause.MUST);
}
LindenFilter lindenFilter = booleanFilterBuilder.build();
filterProperty.put(ctx, lindenFilter);
}
}
Aggregations