Search in sources :

Example 1 with LindenQueryStringQuery

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));
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) QueryParser(org.apache.lucene.queryparser.classic.QueryParser) Query(org.apache.lucene.search.Query) LindenQuery(com.xiaomi.linden.thrift.common.LindenQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) LindenQueryStringQuery(com.xiaomi.linden.thrift.common.LindenQueryStringQuery) LindenQueryStringQuery(com.xiaomi.linden.thrift.common.LindenQueryStringQuery) ParseException(org.apache.lucene.queryparser.classic.ParseException) IOException(java.io.IOException)

Aggregations

LindenQuery (com.xiaomi.linden.thrift.common.LindenQuery)1 LindenQueryStringQuery (com.xiaomi.linden.thrift.common.LindenQueryStringQuery)1 IOException (java.io.IOException)1 ParseException (org.apache.lucene.queryparser.classic.ParseException)1 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)1 BooleanClause (org.apache.lucene.search.BooleanClause)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 Query (org.apache.lucene.search.Query)1