List of usage examples for org.apache.lucene.queryparser.flexible.core.nodes QueryNode isLeaf
public boolean isLeaf();
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 ww w . j a v a 2 s .c o m 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.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;// www . ja va 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; }
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} */// ww w.j av a 2 s . com 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); } }