use of com.xiaomi.linden.thrift.common.LindenQueryStringQuery in project linden by XiaoMi.
the class QueryStringQueryConstructor method construct.
@Override
protected Query construct(LindenQuery lindenQuery, LindenConfig config) throws IOException {
LindenQueryStringQuery stringQuery = lindenQuery.getQueryString();
QueryParser.Operator op = QueryParser.Operator.OR;
if (stringQuery.isSetOperator() && stringQuery.getOperator() == Operator.AND) {
op = QueryParser.Operator.AND;
}
QueryParser queryParser = new LindenQueryParser(config);
String content = stringQuery.getQuery();
try {
queryParser.setDefaultOperator(op);
Query query = queryParser.parse(content);
// disable coord
if (query instanceof BooleanQuery) {
BooleanQuery bQuery = (BooleanQuery) query;
BooleanQuery booleanQuery = new BooleanQuery(stringQuery.isDisableCoord());
BooleanClause[] clauses = bQuery.getClauses();
for (BooleanClause clause : clauses) {
booleanQuery.add(clause);
}
booleanQuery.setBoost(query.getBoost());
query = booleanQuery;
}
return query;
} catch (ParseException e) {
throw new IOException(Throwables.getStackTraceAsString(e));
}
}
Aggregations