Example usage for org.apache.lucene.queryparser.flexible.core.nodes QueryNode containsTag

List of usage examples for org.apache.lucene.queryparser.flexible.core.nodes QueryNode containsTag

Introduction

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

Prototype

public boolean containsTag(String tagName);

Source Link

Document

verify if a node contains a tag

Usage

From source file:com.sindicetech.siren.qparser.tree.builders.TwigQueryNodeBuilder.java

License:Open Source License

/**
 * Process the child and descendant queries
 *//*  w w w .  j  a v  a 2s .  co  m*/
protected final void processChildren(final List<QueryNode> children, final TwigQuery query) {
    for (final QueryNode child : children) {
        final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
        final NodeQuery nodeQuery = (NodeQuery) obj;

        // Append child queries
        if (child instanceof ChildQueryNode) {
            query.addChild(nodeQuery, this.getModifierValue(child));
        }
        // Append descendant queries
        else if (child instanceof DescendantQueryNode) {
            // A descendant node must always have a level constraint
            if (!child.containsTag(LevelPropertyParser.LEVEL_PROPERTY)) {
                throw new IllegalArgumentException(
                        "Invalid DescendantQueryNode received: no level constraint defined");
            }
            // set level constraint
            final int nodeLevel = (Integer) child.getTag(LevelPropertyParser.LEVEL_PROPERTY);
            // add descendant query
            query.addDescendant(nodeLevel, nodeQuery, this.getModifierValue(child));
        } else {
            throw new IllegalArgumentException(
                    "Invalid QueryNode received: " + child.getClass().getSimpleName());
        }
    }
}