Search in sources :

Example 1 with JexlNode

use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.

the class FunctionQueryNodeBuilder method build.

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;
}
Also used : JexlFunctionNode(datawave.query.language.parser.jexl.JexlFunctionNode) FieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode) FunctionQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FunctionQueryNode) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) FunctionQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FunctionQueryNode) JexlNode(datawave.query.language.parser.jexl.JexlNode) JexlQueryFunction(datawave.query.language.functions.jexl.JexlQueryFunction) NotFoundQueryException(datawave.webservice.query.exception.NotFoundQueryException)

Example 2 with JexlNode

use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.

the class RegexpQueryNodeBuilder method build.

public JexlNode build(QueryNode queryNode) throws QueryNodeException {
    JexlNode returnNode = null;
    if (queryNode instanceof RegexpQueryNode) {
        RegexpQueryNode regexpQueryNode = (RegexpQueryNode) queryNode;
        String field = regexpQueryNode.getFieldAsString();
        UnescapedCharSequence ecs = (UnescapedCharSequence) regexpQueryNode.getText();
        if (field == null || field.isEmpty()) {
            returnNode = new JexlSelectorNode(JexlSelectorNode.Type.REGEX, "", ecs.toString());
        } else {
            returnNode = new JexlSelectorNode(JexlSelectorNode.Type.REGEX, field, ecs.toString());
        }
    }
    return returnNode;
}
Also used : JexlSelectorNode(datawave.query.language.parser.jexl.JexlSelectorNode) UnescapedCharSequence(org.apache.lucene.queryparser.flexible.core.util.UnescapedCharSequence) JexlNode(datawave.query.language.parser.jexl.JexlNode) RegexpQueryNode(org.apache.lucene.queryparser.flexible.standard.nodes.RegexpQueryNode)

Example 3 with JexlNode

use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.

the class BooleanQueryNodeBuilder method build.

public JexlNode build(QueryNode queryNode) throws QueryNodeException {
    BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode;
    JexlNode bNode = null;
    List<QueryNode> children = booleanNode.getChildren();
    if (children != null) {
        List<JexlNode> childrenList = new ArrayList<>();
        LinkedList<QueryNode> extraNodeList = new LinkedList<>();
        boolean isNegation = false;
        for (QueryNode child : children) {
            Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
            if (obj != null) {
                JexlNode query = (JexlNode) obj;
                childrenList.add(query);
            }
        }
        bNode = createNode(queryNode, childrenList, isNegation, extraNodeList);
    }
    return bNode;
}
Also used : NotBooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.NotBooleanQueryNode) AndQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.AndQueryNode) BooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode) ModifierQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode) OrQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.OrQueryNode) QueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QueryNode) ArrayList(java.util.ArrayList) JexlNode(datawave.query.language.parser.jexl.JexlNode) NotBooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.NotBooleanQueryNode) BooleanQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode) LinkedList(java.util.LinkedList)

Example 4 with JexlNode

use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.

the class FieldQueryNodeBuilder method build.

public JexlNode build(QueryNode queryNode) throws QueryNodeException {
    JexlNode returnNode = null;
    if (queryNode instanceof QuotedFieldQueryNode) {
        List<String> phraseWordList = new ArrayList<>();
        FieldQueryNode quotedFieldNode = (QuotedFieldQueryNode) queryNode;
        String field = quotedFieldNode.getFieldAsString();
        String selector = quotedFieldNode.getTextAsString();
        // check if spaces were escaped
        FieldQueryNode fieldQueryNode = (QuotedFieldQueryNode) queryNode;
        UnescapedCharSequence origChars = (UnescapedCharSequence) fieldQueryNode.getText();
        int nextWordStart = 0;
        ArrayList<String> words = new ArrayList<>();
        for (int x = 0; x < origChars.length(); x++) {
            if (origChars.charAt(x) == ' ' && !origChars.wasEscaped(x)) {
                words.add(selector.substring(nextWordStart, x));
                nextWordStart = x + 1;
            } else if (x == origChars.length() - 1) {
                // last word in the list
                words.add(selector.substring(nextWordStart));
            }
        }
        replaceEscapeCharsWithSpace(words);
        for (String s : words) {
            String currWord = s.trim();
            if (!currWord.isEmpty()) {
                phraseWordList.add(currWord);
            }
        }
        if (phraseWordList.size() == 1) {
            // if only one term in quotes, just use a SelectorNode
            String firstWord = phraseWordList.get(0);
            if (field == null || field.isEmpty()) {
                returnNode = new JexlSelectorNode(JexlSelectorNode.Type.EXACT, "", firstWord);
            } else {
                returnNode = new JexlSelectorNode(JexlSelectorNode.Type.EXACT, field, firstWord);
            }
        } else {
            // if more than one term in quotes, use an AdjNode
            returnNode = new JexlPhraseNode(field, phraseWordList);
        }
    } else if (queryNode instanceof FuzzyQueryNode) {
        throw new UnsupportedOperationException(queryNode.getClass().getName() + " not implemented");
    } else {
        // queryNode instanceof WildcardQueryNode
        // queryNode instanceof QuotedFieldQueryNode
        // queryNode instanceof FieldQueryNode
        FieldQueryNode fieldNode = (FieldQueryNode) queryNode;
        boolean hasUnescapedWildcard = WildcardFieldedTerm.hasUnescapedWildcard(fieldNode, Sets.newHashSet(' ', '/'));
        String field = fieldNode.getFieldAsString();
        String selector;
        JexlSelectorNode.Type type;
        if (hasUnescapedWildcard) {
            // When we have a regular expression, we want to maintain the original escaped characters in the term
            selector = EscapedNodes.getEscapedTerm(fieldNode, new EscapeQuerySyntaxImpl());
            type = JexlSelectorNode.Type.WILDCARDS;
        } else {
            selector = fieldNode.getTextAsString();
            type = JexlSelectorNode.Type.EXACT;
        }
        if (field == null || field.isEmpty()) {
            returnNode = new JexlSelectorNode(type, "", selector);
        } else {
            returnNode = new JexlSelectorNode(type, field, selector);
        }
    }
    return returnNode;
}
Also used : FuzzyQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode) QuotedFieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode) ArrayList(java.util.ArrayList) JexlPhraseNode(datawave.query.language.parser.jexl.JexlPhraseNode) EscapeQuerySyntaxImpl(datawave.query.language.parser.lucene.EscapeQuerySyntaxImpl) FieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode) QuotedFieldQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.QuotedFieldQueryNode) JexlSelectorNode(datawave.query.language.parser.jexl.JexlSelectorNode) UnescapedCharSequence(org.apache.lucene.queryparser.flexible.core.util.UnescapedCharSequence) JexlNode(datawave.query.language.parser.jexl.JexlNode)

Example 5 with JexlNode

use of datawave.query.language.parser.jexl.JexlNode in project datawave by NationalSecurityAgency.

the class GroupQueryNodeBuilder method build.

public JexlNode build(QueryNode queryNode) throws QueryNodeException {
    GroupQueryNode groupNode = (GroupQueryNode) queryNode;
    JexlNode child = (JexlNode) groupNode.getChild().getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
    return new JexlGroupingNode(Collections.singletonList(child));
}
Also used : JexlNode(datawave.query.language.parser.jexl.JexlNode) GroupQueryNode(org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode) JexlGroupingNode(datawave.query.language.parser.jexl.JexlGroupingNode)

Aggregations

JexlNode (datawave.query.language.parser.jexl.JexlNode)6 JexlSelectorNode (datawave.query.language.parser.jexl.JexlSelectorNode)3 JexlPhraseNode (datawave.query.language.parser.jexl.JexlPhraseNode)2 ArrayList (java.util.ArrayList)2 FieldQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FieldQueryNode)2 QueryNode (org.apache.lucene.queryparser.flexible.core.nodes.QueryNode)2 UnescapedCharSequence (org.apache.lucene.queryparser.flexible.core.util.UnescapedCharSequence)2 JexlQueryFunction (datawave.query.language.functions.jexl.JexlQueryFunction)1 JexlFunctionNode (datawave.query.language.parser.jexl.JexlFunctionNode)1 JexlGroupingNode (datawave.query.language.parser.jexl.JexlGroupingNode)1 JexlWithinNode (datawave.query.language.parser.jexl.JexlWithinNode)1 EscapeQuerySyntaxImpl (datawave.query.language.parser.lucene.EscapeQuerySyntaxImpl)1 NotFoundQueryException (datawave.webservice.query.exception.NotFoundQueryException)1 LinkedList (java.util.LinkedList)1 AndQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.AndQueryNode)1 BooleanQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.BooleanQueryNode)1 FunctionQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FunctionQueryNode)1 FuzzyQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.FuzzyQueryNode)1 GroupQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.GroupQueryNode)1 ModifierQueryNode (org.apache.lucene.queryparser.flexible.core.nodes.ModifierQueryNode)1