Example usage for org.apache.lucene.queryparser.flexible.core QueryNodeParseException getMessage

List of usage examples for org.apache.lucene.queryparser.flexible.core QueryNodeParseException getMessage

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.flexible.core QueryNodeParseException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:org.apache.solr.handler.component.AqpQueryTree.java

License:Apache License

@Override
public void prepare(ResponseBuilder rb) throws IOException {
    SolrQueryRequest req = rb.req;//www  . j a v a 2 s.com
    SolrParams params = req.getParams();
    if (!params.getBool(COMPONENT_NAME, true)) {
        return;
    }
    SolrQueryResponse rsp = rb.rsp;

    String defType = params.get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE);

    // get it from the response builder to give a different component a chance
    // to set it.
    String queryString = rb.getQueryString();
    if (queryString == null) {
        // this is the normal way it's set.
        queryString = params.get(CommonParams.Q);
    }

    QParser parser;
    try {
        parser = QParser.getParser(queryString, defType, req);

        if (parser instanceof AqpAdsabsQParser) {
            AqpQueryParser aqpParser = ((AqpAdsabsQParser) parser).getParser();
            SyntaxParser syntaxParser = aqpParser.getSyntaxParser();
            QueryNode queryTree = syntaxParser.parse(queryString, null);
            if (queryTree instanceof AqpANTLRNode) {
                if (params.get(CommonParams.WT, null) == "xml") {
                    //System.err.println(((AqpANTLRNode) queryTree).toJson());
                    rsp.add("qtree", ((AqpANTLRNode) queryTree).toString());
                } else {
                    //System.err.println(((AqpANTLRNode) queryTree).toString());
                    rsp.add("qtree", ((AqpANTLRNode) queryTree).toJson());
                }
            }
        }

    } catch (QueryNodeParseException e) {
        rsp.add("qtreeError", e.getMessage());
    } catch (SyntaxError e) {
        rsp.add("qtreeError", e.getMessage());
    }

}