SOLR-794: revert ClientUtils with Character.isWhitespace(c)

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@702355 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Koji Sekiguchi 2008-10-07 05:51:31 +00:00
parent 32fb80d342
commit dd04d0fc2e
2 changed files with 6 additions and 15 deletions

View File

@ -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
----------------------

View File

@ -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 <code>\</code>.
*/
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);