Return-Path: X-Original-To: apmail-lucene-dev-archive@www.apache.org Delivered-To: apmail-lucene-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 95758FB56 for ; Wed, 1 May 2013 18:54:17 +0000 (UTC) Received: (qmail 42118 invoked by uid 500); 1 May 2013 18:54:16 -0000 Delivered-To: apmail-lucene-dev-archive@lucene.apache.org Received: (qmail 42062 invoked by uid 500); 1 May 2013 18:54:16 -0000 Mailing-List: contact dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list dev@lucene.apache.org Received: (qmail 42053 invoked by uid 99); 1 May 2013 18:54:16 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 May 2013 18:54:16 +0000 Date: Wed, 1 May 2013 18:54:16 +0000 (UTC) From: "Shawn Heisey (JIRA)" To: dev@lucene.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Closed] (SOLR-4780) It would be helpful to have a function in SolrQuery to perform special character escaping as needed for q strings MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/SOLR-4780?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Shawn Heisey closed SOLR-4780. ------------------------------ Resolution: Invalid SolrJ already includes this functionality: http://lucene.apache.org/solr/4_2_0/solr-solrj/org/apache/solr/client/solrj/util/ClientUtils.html#escapeQueryChars%28java.lang.String%29 You would need to be careful that you only escape the "query" part of something that uses the field:query syntax, rather than the entire query string. If you escape the whole thing, the colon will become part of the query text. > It would be helpful to have a function in SolrQuery to perform special character escaping as needed for q strings > ----------------------------------------------------------------------------------------------------------------- > > Key: SOLR-4780 > URL: https://issues.apache.org/jira/browse/SOLR-4780 > Project: Solr > Issue Type: New Feature > Affects Versions: 4.0 > Reporter: Benson Margulies > > Here's some code I found in a blog, IP uncertain, to explain the idea: > {noformat} > public static String escapeQueryCulprits(String s) > { > StringBuilder sb = new StringBuilder(); > 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 == ';' > ) > { > sb.append('\\'); > } > if(Character.isWhitespace(c)) > { > sb.append(" \\ "); > } > sb.append(c); > } > return sb.toString(); > } > {noformat} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org For additional commands, e-mail: dev-help@lucene.apache.org