class LuceneToJexlControlledQueryParser extends LuceneToJexlQueryParser implements ControlledQueryParser {

    @Override
    public QueryNode parse(String query) throws ParseException {
        
        StringBuilder sb = new StringBuilder();
        boolean addedFirstInclude = false;
        for (Map.Entry<String,Set<String>> entry : includedValues.entrySet()) {
            String field = entry.getKey();
            for (String value : entry.getValue()) {
                if (addedFirstInclude == true) {
                    sb.append(" OR ");
                }
                addedFirstInclude = true;
                sb.append("#INCLUDE(").append(field).append(", ").append(value).append(")");
            }
        }
        
        if (!includedValues.isEmpty() && !excludedValues.isEmpty()) {
            sb.append(" AND ");
        }
        
        boolean addedFirstExclude = false;
        for (Map.Entry<String,Set<String>> entry : excludedValues.entrySet()) {
            String field = entry.getKey();
            for (String value : entry.getValue()) {
                if (addedFirstExclude == true) {
                    sb.append(" AND ");
                }
                addedFirstExclude = true;
                sb.append("#EXCLUDE(").append(field).append(", ").append(value).append(")");
            }
        }
        
        if (sb.length() > 0) {
            query = "(" + query + ")" + " AND (" + sb + ")";
        }
        
        return super.parse(query);
    }

    public  LuceneToJexlControlledQueryParser();

}