use of datawave.query.language.parser.jexl.JexlSelectorNode 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;
}
use of datawave.query.language.parser.jexl.JexlSelectorNode 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;
}
use of datawave.query.language.parser.jexl.JexlSelectorNode in project datawave by NationalSecurityAgency.
the class SlopQueryNodeBuilder method build.
public JexlNode build(QueryNode queryNode) throws QueryNodeException {
JexlNode returnNode = null;
SlopQueryNode phraseSlopNode = (SlopQueryNode) queryNode;
JexlNode node = (JexlNode) phraseSlopNode.getChild().getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
if (node instanceof JexlPhraseNode) {
JexlPhraseNode phraseNode = (JexlPhraseNode) node;
returnNode = new JexlWithinNode(phraseNode.getField(), phraseNode.getWordList(), phraseSlopNode.getValue());
} else if (node instanceof JexlSelectorNode) {
// if phrase only contained one word, a JexlSelectorNode would be created
// and then a SlopQueryNode / within makes no sense
returnNode = node;
} else {
throw new UnsupportedOperationException(node.getClass().getName() + " found as a child of a SlopQueryNode -- not implemented");
}
return returnNode;
}
Aggregations