Search in sources :

Example 1 with ServerHeadNode

use of datawave.query.language.tree.ServerHeadNode in project datawave by NationalSecurityAgency.

the class JexlControlledQueryParser method parse.

@Override
public QueryNode parse(String query) throws ParseException {
    checkIfQueryAllowed(query);
    StringBuilder sb = new StringBuilder();
    if (!includedValues.isEmpty()) {
        sb.append("(");
    }
    boolean addedFirstInclude = false;
    for (Map.Entry<String, Set<String>> entry : includedValues.entrySet()) {
        String field = entry.getKey();
        for (String value : entry.getValue()) {
            if (addedFirstInclude) {
                sb.append(" || ");
            }
            addedFirstInclude = true;
            sb.append("filter:includeRegex(").append(field).append(", '").append(value).append("')");
        }
    }
    if (!includedValues.isEmpty()) {
        sb.append(")");
    }
    if (!excludedValues.isEmpty()) {
        if (!includedValues.isEmpty()) {
            sb.append(" && ");
        }
        sb.append("(");
    }
    boolean addedFirstExclude = false;
    for (Map.Entry<String, Set<String>> entry : excludedValues.entrySet()) {
        String field = entry.getKey();
        for (String value : entry.getValue()) {
            if (addedFirstExclude) {
                sb.append(" && ");
            }
            addedFirstExclude = true;
            sb.append("not(filter:includeRegex(").append(field).append(", '").append(value).append("'))");
        }
    }
    if (!excludedValues.isEmpty()) {
        sb.append(")");
    }
    if (sb.length() > 0) {
        query = "(" + query + ")" + " && (" + sb + ")";
    }
    QueryNode node = new ServerHeadNode();
    node.setOriginalQuery(query);
    return node;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) QueryNode(datawave.query.language.tree.QueryNode) ServerHeadNode(datawave.query.language.tree.ServerHeadNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ServerHeadNode

use of datawave.query.language.tree.ServerHeadNode in project datawave by NationalSecurityAgency.

the class LuceneToJexlQueryParser method parse.

@Override
public QueryNode parse(String query) throws ParseException {
    JexlNode parsedQuery = convertToJexlNode(query);
    QueryNode node = new ServerHeadNode();
    node.setOriginalQuery(parsedQuery.toString());
    return node;
}
Also used : QueryNode(datawave.query.language.tree.QueryNode) ServerHeadNode(datawave.query.language.tree.ServerHeadNode)

Aggregations

QueryNode (datawave.query.language.tree.QueryNode)2 ServerHeadNode (datawave.query.language.tree.ServerHeadNode)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1