Lucene 特殊字符的问题

SolrQuerySyntax

http://wiki.apache.org/solr/SolrQuerySyntax

solr的处理方式:

https://svn.apache.org/repos/asf/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/util/ClientUtils.java

  /**
   * See: {@link org.apache.lucene.queryparser.classic queryparser syntax} 
   * for more information on Escaping Special Characters
   */
  public static String escapeQueryChars(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 == ';' || c == '/'
        || Character.isWhitespace(c)) {
        sb.append('\');
      }
      sb.append(c);
    }
    return sb.toString();
  }
原文地址:https://www.cnblogs.com/huangfox/p/4191670.html