lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benson Margulies (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SOLR-4780) It would be helpful to have a function in SolrQuery to perform special character escaping as needed for q strings
Date Wed, 01 May 2013 19:48:16 GMT

    [ https://issues.apache.org/jira/browse/SOLR-4780?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13646869#comment-13646869
] 

Benson Margulies commented on SOLR-4780:
----------------------------------------

Serves me right for not checking latest version. On the other hand, the wiki is down ... :-)
                
> 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


Mime
View raw message