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

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

Introduction

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

Prototype

public List<QueryNode> getChildren();

Source Link

Document

get Children nodes

Usage

From source file:com.sindicetech.siren.qparser.keyword.nodes.TwigQueryNode.java

License:Open Source License

private CharSequence doGetField(final List<QueryNode> children) {
    if (children != null) {
        for (final QueryNode child : children) {
            if (child instanceof FieldableNode) {
                return ((FieldableNode) child).getField();
            } else if (child instanceof TwigQueryNode) {
                return ((TwigQueryNode) child).getField();
            }//from   w  ww.  j a va 2  s  . co  m
            final CharSequence field = this.doGetField(child.getChildren());
            if (field != null) {
                return field;
            }
        }
    }
    return null;
}

From source file:com.sindicetech.siren.qparser.keyword.nodes.TwigQueryNode.java

License:Open Source License

private void doSetField(final List<QueryNode> children, final CharSequence fieldName) {
    if (children != null) {
        for (final QueryNode child : children) {
            this.doSetField(child.getChildren(), fieldName);
            if (child instanceof FieldableNode) {
                ((FieldableNode) child).setField(fieldName);
            } else if (child instanceof TwigQueryNode) {
                ((TwigQueryNode) child).setField(fieldName);
            }// w  w w.  ja va  2 s  .  c  o  m
        }
    }
}

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

License:Open Source License

@Override
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException {
    final QueryConfigHandler conf = this.getQueryConfigHandler();

    // If the current node is a datatype query node, validate the datatype and assign it to its child
    if (node instanceof DatatypeQueryNode) {
        final Map<String, Analyzer> dtAnalyzers = conf.get(KeywordConfigurationKeys.DATATYPES_ANALYZERS);
        final DatatypeQueryNode dt = (DatatypeQueryNode) node;
        String datatype = dt.getDatatype();

        // check if the datatype is correctly registered
        if (dtAnalyzers == null) {
            throw new IllegalArgumentException("KeywordConfigurationKeys.DATAYPES_ANALYZERS "
                    + "should be set on the ExtendedKeywordQueryConfigHandler");
        }/*from www  .ja  v a  2  s .  c om*/
        if (!dtAnalyzers.containsKey(datatype)) {
            throw new IllegalArgumentException("Unknown datatype: [" + datatype + "]");
        }
        if (dtAnalyzers.get(datatype) == null) {
            throw new IllegalArgumentException("Analyzer of datatype [" + datatype + "] cannot be null.");
        }

        // transfer the datatype to its child
        dt.getChild().setTag(DatatypeQueryNode.DATATYPE_TAGID, datatype);
    }
    // If the current node is a twig query node, assign the json:field datatype to the root, and assign the default
    // or the tagged datatype to the child
    else if (node instanceof TwigQueryNode) {
        final TwigQueryNode twig = (TwigQueryNode) node;
        if (twig.getTag(DatatypeQueryNode.DATATYPE_TAGID) == null) {
            twig.getChild().setTag(DatatypeQueryNode.DATATYPE_TAGID, this.getDefaultDatatype(conf));
        } else {
            twig.getChild().setTag(DatatypeQueryNode.DATATYPE_TAGID, this.getDatatype(conf, node));
        }
        twig.getRoot().setTag(DatatypeQueryNode.DATATYPE_TAGID, JSONDatatype.JSON_FIELD);
    }
    // in any other cases, if the node is not a leaf node, transfer the datatype to its children
    else if (!node.isLeaf()) {
        for (final QueryNode child : node.getChildren()) {
            child.setTag(DatatypeQueryNode.DATATYPE_TAGID, this.getDatatype(conf, node));
        }
    }

    return node;
}

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

License:Open Source License

private void readTree(final QueryNode node) throws QueryNodeException {

    if (node instanceof BooleanQueryNode) {
        final List<QueryNode> children = node.getChildren();

        if (children != null && children.size() > 0) {

            for (int i = 0; i < children.size() - 1; i++) {
                this.readTree(children.get(i));
            }//from   w w w  .jav  a  2 s .  com

            this.processNode(node);
            this.readTree(children.get(children.size() - 1));

        } else {
            this.processNode(node);
        }

    } else {
        this.processNode(node);
    }

}

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;//  w w w  .  j  a  va  2s  .c om

        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;
}

From source file:org.sindice.siren.qparser.keyword.builders.DatatypeQueryNodeBuilder.java

License:Apache License

public Query build(final QueryNode queryNode) throws QueryNodeException {
    final DatatypeQueryNode dtNode = (DatatypeQueryNode) queryNode;
    final QueryNode child = dtNode.getChild();

    assert queryNode.getChildren().size() == 1;

    final Query query = (Query) child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
    this.setDatatype(child, dtNode.getDatatype());
    return query;
}

From source file:org.sindice.siren.qparser.keyword.builders.DatatypeQueryNodeBuilder.java

License:Apache License

/**
 * Sets the given datatype on each descendant of the {@link DatatypeQueryNode}
 *//*from  ww  w. j  av  a  2 s .c  o  m*/
private void setDatatype(final QueryNode node, final String datatype) {
    final Query query = (Query) node.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
    if (query instanceof NodePrimitiveQuery) {
        ((NodePrimitiveQuery) query).setDatatype(datatype);
    }
    if (node.isLeaf()) {
        return;
    }
    for (final QueryNode child : node.getChildren()) {
        this.setDatatype(child, datatype);
    }
}