I agree one is better... as long as the escape functionality is the same, i don't think it matters - adding the Character.isWhitespace() should make that true.

i say we change it and add a note in CHANGES.txt -- if there are any problems (i can't imagine functional ones) then we can change back.


On Oct 6, 2008, at 11:19 PM, Koji Sekiguchi wrote:

I think keeping one function is good. Why I added the new function is because I just didn't want to change runtime behavior of existing public method...

Ryan McKinley wrote:
how about keeping one function, but adding: Character.whiteSpace( c )?

Do you need the function to also escape whitespace?


On Oct 6, 2008, at 8:36 PM, [EMAIL PROTECTED] wrote:

Author: koji
Date: Mon Oct  6 17:36:49 2008
New Revision: 702314

URL: http://svn.apache.org/viewvc?rev=702314&view=rev
Log:
SOLR-794: added escape() method to ClientUtils.

Modified:
  lucene/solr/trunk/client/java/solrj/CHANGES.txt
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/ solrj/util/ClientUtils.java

Modified: lucene/solr/trunk/client/java/solrj/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/CHANGES.txt?rev=702314&r1=702313&r2=702314&view=diff
= = = = = = = = = = ====================================================================
--- lucene/solr/trunk/client/java/solrj/CHANGES.txt (original)
+++ lucene/solr/trunk/client/java/solrj/CHANGES.txt Mon Oct 6 17:36:49 2008
@@ -18,6 +18,8 @@
New Features
----------------------

+ 1. SOLR-794: added escape() method to ClientUtils. (koji)
+
Optimizations
----------------------


Modified: lucene/solr/trunk/client/java/solrj/src/org/apache/solr/ client/solrj/util/ClientUtils.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/util/ClientUtils.java?rev=702314&r1=702313&r2=702314&view=diff
= = = = = = = = = = ==================================================================== --- lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/ solrj/util/ClientUtils.java (original) +++ lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/ solrj/util/ClientUtils.java Mon Oct 6 17:36:49 2008
@@ -191,15 +191,32 @@
private static final Pattern escapePattern = Pattern.compile( "(\ \W)" );

 /**
- * See: http://lucene.apache.org/java/docs/queryparsersyntax.html#Escaping Special Characters
+   * 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) {
+    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 == '&') {
+        sb.append('\\');
+      }
+      sb.append(c);
+    }
+    return sb.toString();
+  }
+
public static String toQueryString( SolrParams params, boolean xml ) {
   StringBuilder sb = new StringBuilder(128);
   try {






Reply via email to