private void processNode(QueryNode node) { if (node instanceof AndQueryNode || node instanceof OrQueryNode) { if (!this.latestNodeVerified && !this.queryNodeList.isEmpty()) { this.queryNodeList.add(applyModifier(this.queryNodeList .remove(this.queryNodeList.size() - 1), node)); this.latestNodeVerified = true; } } else if (!(node instanceof BooleanQueryNode)) { this.queryNodeList.add(applyModifier(node, node.getParent())); this.latestNodeVerified = false; } }
private void processNode(QueryNode node) { if (node instanceof AndQueryNode || node instanceof OrQueryNode) { if (!this.latestNodeVerified && !this.queryNodeList.isEmpty()) { this.queryNodeList.add(applyModifier(this.queryNodeList .remove(this.queryNodeList.size() - 1), node)); this.latestNodeVerified = true; } } else if (!(node instanceof BooleanQueryNode)) { this.queryNodeList.add(applyModifier(node, node.getParent())); this.latestNodeVerified = false; } }
@Override protected QueryNode postProcessNode(final QueryNode node) throws QueryNodeException { if (node.getParent() == null) { // node is root, we processed the tree if (hasUnaryReqOperator) { // we found a req modifier in the tree final QueryConfigHandler conf = this.getQueryConfigHandler(); if (!conf.has(ConfigurationKeys.DEFAULT_OPERATOR)) { throw new IllegalArgumentException( "ConfigurationKeys.DEFAULT_OPERATOR should be set on the QueryConfigHandler"); } conf.set(ConfigurationKeys.DEFAULT_OPERATOR, Operator.OR); } } return node; }
public datawave.query.language.tree.QueryNode build(QueryNode queryNode) throws QueryNodeException { datawave.query.language.tree.QueryNode returnNode = null; int depth = 0; QueryNode parent = queryNode; while ((parent = parent.getParent()) != null) { depth++; } if (queryNode instanceof FunctionQueryNode) { FunctionQueryNode functionQueryNode = (FunctionQueryNode) queryNode; String functionName = functionQueryNode.getFunction(); List<String> parameterList = functionQueryNode.getParameterList(); LuceneQueryFunction referenceFunction = allowedFunctionMap.get(functionName.toUpperCase()); if (referenceFunction == null) { NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.FUNCTION_NOT_FOUND, MessageFormat.format("{0}", functionName)); throw new IllegalArgumentException(qe); } LuceneQueryFunction function = (LuceneQueryFunction) referenceFunction.duplicate(); returnNode = new FunctionNode(function, parameterList, depth, queryNode.getParent()); } return returnNode; }
public JexlNode build(QueryNode queryNode) { JexlNode returnNode = null; int depth = 0; QueryNode parent = queryNode; while ((parent = parent.getParent()) != null) { depth++; } if (queryNode instanceof FunctionQueryNode) { FunctionQueryNode functionQueryNode = (FunctionQueryNode) queryNode; String functionName = functionQueryNode.getFunction(); List<String> parameterList = functionQueryNode.getParameterList(); JexlQueryFunction referenceFunction = allowedFunctionMap.get(functionName.toUpperCase()); if (referenceFunction == null) { NotFoundQueryException qe = new NotFoundQueryException(DatawaveErrorCode.FUNCTION_NOT_FOUND, MessageFormat.format("{0}", functionName)); throw new IllegalArgumentException(qe); } // if more than one term in quotes, use an AdjNode JexlQueryFunction function = (JexlQueryFunction) referenceFunction.duplicate(); returnNode = new JexlFunctionNode(function, parameterList, depth, queryNode.getParent()); } return returnNode; }
@Override protected QueryNode postProcessNode(final QueryNode node) throws QueryNodeException { if (node.getParent() == null) { // node is root, we processed the tree if (hasUnaryReqOperator) { // we found a req modifier in the tree final QueryConfigHandler conf = this.getQueryConfigHandler(); if (!conf.has(ConfigurationKeys.DEFAULT_OPERATOR)) { throw new IllegalArgumentException( "ConfigurationKeys.DEFAULT_OPERATOR should be set on the QueryConfigHandler"); } conf.set(ConfigurationKeys.DEFAULT_OPERATOR, Operator.OR); } } return node; }
@Override protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { if (node instanceof FieldableNode && (node.getParent() == null || !(node.getParent() instanceof FieldableNode))) { FieldableNode fieldNode = (FieldableNode) node; QueryConfigHandler config = getQueryConfigHandler(); if (config != null) { CharSequence field = fieldNode.getField(); FieldConfig fieldConfig = config.getFieldConfig(StringUtils.toString(field)); if (fieldConfig != null) { Float boost = fieldConfig.get(ConfigurationKeys.BOOST); if (boost != null) { return new BoostQueryNode(node, boost); } } } } return node; }
@Override protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { if (node instanceof FieldableNode && (node.getParent() == null || !(node.getParent() instanceof FieldableNode))) { FieldableNode fieldNode = (FieldableNode) node; QueryConfigHandler config = getQueryConfigHandler(); if (config != null) { CharSequence field = fieldNode.getField(); FieldConfig fieldConfig = config.getFieldConfig(StringUtils.toString(field)); if (fieldConfig != null) { Float boost = fieldConfig.get(ConfigurationKeys.BOOST); if (boost != null) { return new BoostQueryNode(node, boost); } } } } return node; }
@Override protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { Locale locale = getQueryConfigHandler().get(ConfigurationKeys.LOCALE); if (locale == null) { locale = Locale.getDefault(); } if (node instanceof WildcardQueryNode || node instanceof FuzzyQueryNode || (node instanceof FieldQueryNode && node.getParent() instanceof RangeQueryNode) || node instanceof RegexpQueryNode) { TextableQueryNode txtNode = (TextableQueryNode) node; CharSequence text = txtNode.getText(); txtNode.setText(text != null ? UnescapedCharSequence.toLowerCase(text, locale) : null); } return node; }
@Override protected QueryNode postProcessNode(QueryNode node) throws QueryNodeException { Locale locale = getQueryConfigHandler().get(ConfigurationKeys.LOCALE); if (locale == null) { locale = Locale.getDefault(); } if (node instanceof WildcardQueryNode || node instanceof FuzzyQueryNode || (node instanceof FieldQueryNode && node.getParent() instanceof RangeQueryNode) || node instanceof RegexpQueryNode) { TextableQueryNode txtNode = (TextableQueryNode) node; CharSequence text = txtNode.getText(); txtNode.setText(text != null ? UnescapedCharSequence.toLowerCase(text, locale) : null); } return node; }
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException { QueryNode parent = node.getParent(); if (node instanceof BooleanQueryNode) { if (parent instanceof BooleanQueryNode) { node.setTag(TAG_REMOVE, Boolean.TRUE); // no precedence } else { node.setTag(TAG_BOOLEAN_ROOT, Boolean.TRUE); } } else if (parent instanceof BooleanQueryNode) { if ((parent instanceof AndQueryNode) || (usingAnd && isDefaultBooleanQueryNode(parent))) { tagModifierButDoNotOverride(node, ModifierQueryNode.Modifier.MOD_REQ); } } return node; }
protected QueryNode preProcessNode(QueryNode node) throws QueryNodeException { QueryNode parent = node.getParent(); if (node instanceof BooleanQueryNode) { if (parent instanceof BooleanQueryNode) { node.setTag(TAG_REMOVE, Boolean.TRUE); // no precedence } else { node.setTag(TAG_BOOLEAN_ROOT, Boolean.TRUE); } } else if (parent instanceof BooleanQueryNode) { if ((parent instanceof AndQueryNode) || (usingAnd && isDefaultBooleanQueryNode(parent))) { tagModifierButDoNotOverride(node, ModifierQueryNode.Modifier.MOD_REQ); } } return node; }
@Override protected QueryNode postProcessNode(final QueryNode node) throws QueryNodeException { if (node instanceof FieldQueryNode && !(node.getParent() instanceof RangeQueryNode)) { final FieldQueryNode fieldNode = (FieldQueryNode) node; final Map<String, Analyzer> dts = this.getQueryConfigHandler().get(KeywordConfigurationKeys.DATATYPES_ANALYZERS); final Analyzer analyzer = dts.get(node.getTag(DatatypeQueryNode.DATATYPE_TAGID)); if (analyzer instanceof NumericAnalyzer) { final NumericAnalyzer na = (NumericAnalyzer) analyzer; final char[] text = fieldNode.getTextAsString().toCharArray(); final ReusableCharArrayReader textReader = new ReusableCharArrayReader(text); final Number number; try { number = na.getNumericParser().parse(textReader); } catch (final Exception e) { throw new QueryNodeParseException(new MessageImpl(QueryParserMessages.COULD_NOT_PARSE_NUMBER, text), e); } final CharSequence field = fieldNode.getField(); final NodeNumericQueryNode lowerNode = new NodeNumericQueryNode(field, number); final NodeNumericQueryNode upperNode = new NodeNumericQueryNode(field, number); return new NodeNumericRangeQueryNode(lowerNode, upperNode, true, true, na); } } return node; }
@Test public void testTwigQueryNodeParent() throws Exception { final TwigQueryNode twig = new TwigQueryNode(new WildcardNodeQueryNode(), new WildcardNodeQueryNode()); final FieldQueryNode term = new FieldQueryNode("field", "term", 0, 4); assertTrue(term.getParent() == null); assertEquals(twig, twig.getRoot().getParent()); assertEquals(twig, twig.getChild().getParent()); twig.setRoot(term); twig.setChild(term); assertEquals(twig, twig.getRoot().getParent()); assertEquals(twig, twig.getChild().getParent()); }
@Test public void testTwigQueryNodeParent() throws Exception { final TwigQueryNode twig = new TwigQueryNode(new WildcardNodeQueryNode(), new WildcardNodeQueryNode()); final FieldQueryNode term = new FieldQueryNode("field", "term", 0, 4); assertTrue(term.getParent() == null); assertEquals(twig, twig.getRoot().getParent()); assertEquals(twig, twig.getChild().getParent()); twig.setRoot(term); twig.setChild(term); assertEquals(twig, twig.getRoot().getParent()); assertEquals(twig, twig.getChild().getParent()); }
if (node.getParent() instanceof AndQueryNode) {
throws QueryNodeException { if (node instanceof FieldQueryNode && !(node.getParent() instanceof RangeQueryNode)) { final FieldQueryNode fieldNode = (FieldQueryNode) node;
if (node.getParent() instanceof AndQueryNode) {