// These characters are part of the query syntax and must be escaped
if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
|| c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
- || c == '|' || c == '&' || c == '/' || (escapeWildcards && (c == '*' || c == '?'))) {
+ || c == '|' || c == '&' || c == '/' || c == ' ' || (escapeWildcards && (c == '*' || c == '?'))) {
sb.append('\\');
sb.append(c);
lastWhitespace = false;
// These characters are part of the query syntax and must be escaped
if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
|| c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
- || c == '|' || c == '&' || c == '/' || (escapeWildcards && (c == '*' || c == '?'))) {
+ || c == '|' || c == '&' || c == '/' || c == ' ' || (escapeWildcards && (c == '*' || c == '?'))) {
return true;
} else if (Character.isWhitespace(c)) {
lastWhitespace = true;
}
private static final String[] RESERVED_WORDS = {
- "AND", "and",
- "OR", "or"
+ "AND", "\\AND",
+ "OR", "\\OR",
+ "NOT", "\\NOT",
};
/**
StringBuilder sb = new StringBuilder();
return escapeTerm(field, term, escapeWildcards, sb).toString();
}
+
+ public static String quoteTerm(String term) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("\"");
+ sb.append(term.replaceAll("(\"|\\\\)", "\\\\$0"));
+ sb.append("\"");
+ return sb.toString();
+ }
// public static void main(String[] args) {
// System.out.println("esc: " + escape("AND01", true, true));