Example usage for org.apache.lucene.queryparser.flexible.core.nodes GroupQueryNode getChild

List of usage examples for org.apache.lucene.queryparser.flexible.core.nodes GroupQueryNode getChild

Introduction

In this page you can find the example usage for org.apache.lucene.queryparser.flexible.core.nodes GroupQueryNode getChild.

Prototype

public QueryNode getChild() 

Source Link

Usage

From source file:com.sindicetech.siren.qparser.keyword.processors.QueryTypeProcessor.java

License:Open Source License

@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
    // If the current node is a group query node, check the query type and assign it to its children
    if (node instanceof GroupQueryNode) {
        GroupQueryNode groupQueryNode = (GroupQueryNode) node;
        String queryType = null;//from  w  w w .ja  v a 2s.  c o  m

        if (node instanceof NodeGroupQueryNode) {
            queryType = NODE_QUERYTYPE;
        } else if (node instanceof SpanGroupQueryNode) {
            queryType = SPAN_QUERYTYPE;
        } else {
            throw new QueryNodeException(new MessageImpl("Invalid GroupQueryNode received",
                    node.toQueryString(new EscapeQuerySyntaxImpl())));
        }

        // transfer the query type to its child
        groupQueryNode.getChild().setTag(QUERYTYPE_TAG, queryType);
    }
    // in any other cases, if the node is not a leaf node, transfer the query type to its children
    else if (!node.isLeaf()) {
        if (node.getTag(QUERYTYPE_TAG) != null) {
            for (final QueryNode child : node.getChildren()) {
                child.setTag(QUERYTYPE_TAG, node.getTag(QUERYTYPE_TAG));
            }
        }
    }

    return node;
}