solr 对于 关键字的特殊处理

public static String transformMetachar(String input){
     StringBuffer sb = new StringBuffer();
    try{
        String regex = "[+\\-&|!(){}\\[\\]^\"~*?:(\\)\\s]";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(input);
        while(matcher.find()){
            matcher.appendReplacement(sb, "\\\\"+matcher.group());
        }
        matcher.appendTail(sb);
    catch(Exception e){
        //TODO
    }
     return sb.toString();
}

posted on 2017-07-21 17:34  zhouzhou0615  阅读(493)  评论(0编辑  收藏  举报

导航