diff --git a/client/java/solrj/CHANGES.txt b/client/java/solrj/CHANGES.txt index ddcfb64166d..5c8213fb169 100644 --- a/client/java/solrj/CHANGES.txt +++ b/client/java/solrj/CHANGES.txt @@ -18,8 +18,6 @@ Detailed Change List New Features ---------------------- - 1. SOLR-794: added escape() method to ClientUtils. (koji) - Optimizations ---------------------- @@ -34,6 +32,9 @@ Bug Fixes SolrQuery#getHighlightRequireFieldMatch() (Kohei Taketa, Lars Kotthoff via koji) + 3. SOLR-794: ClientUtils.escapeQueryChars escapes chars a bit aggressive + (ryan, koji) + Documentation ---------------------- diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/util/ClientUtils.java b/client/java/solrj/src/org/apache/solr/client/solrj/util/ClientUtils.java index 187ead85664..8087c115ecd 100644 --- a/client/java/solrj/src/org/apache/solr/client/solrj/util/ClientUtils.java +++ b/client/java/solrj/src/org/apache/solr/client/solrj/util/ClientUtils.java @@ -187,29 +187,19 @@ public class ClientUtils return (DateFormat) proto.clone(); } } - - private static final Pattern escapePattern = Pattern.compile( "(\\W)" ); - - /** - * Non-word characters are escaped by a preceding \. - */ - public static String escapeQueryChars( String input ) - { - Matcher matcher = escapePattern.matcher( input ); - return matcher.replaceAll( "\\\\$1" ); - } /** * See: http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping Special Characters */ - public static String escape(String s) { + public static String escapeQueryChars(String s) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); // 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 == '|' || c == '&') { + || c == '*' || c == '?' || c == '|' || c == '&' + || Character.isWhitespace(c)) { sb.append('\\'); } sb.append(c);