solr中特殊字符的處理
阿新 • • 發佈:2019-03-14
turn urn 條件 ash 字符處理 ble nbsp sdn contain StringBuffer sb = new StringBuffer();
String regex = "[+\\-&|!(){}\\[\\]^\"~*?:(\\)\\s]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
while(matcher.find()){
matcher.appendReplacement(sb, "\\\\"+matcher.group());
}
matcher.appendTail(sb);
return sb.toString();
}
---------------------
作者:ldh_lyf
來源:CSDN
原文:https://blog.csdn.net/lyf_ldh/article/details/82775887
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
如查詢的條件為:params.add("fq", "jiucaiyun_brand:Double A" ),這樣是查不出帶有空格的條件,需要把空格轉義
if(brand2.contains(" ")) {
brand2=brand2.replace(" " , "\\ ");
}
params.add("fq", "jiucaiyun_brand:" + brand2);這樣就可以查出匹配的結果。
其他字符處理:+ – && || ! ( ) { } [ ] ^ ” ~ * ? : \和空格
public static String transformSolrMetacharactor(String input){
String regex = "[+\\-&|!(){}\\[\\]^\"~*?:(\\)\\s]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
while(matcher.find()){
matcher.appendReplacement(sb, "\\\\"+matcher.group());
matcher.appendTail(sb);
return sb.toString();
}
---------------------
作者:ldh_lyf
來源:CSDN
原文:https://blog.csdn.net/lyf_ldh/article/details/82775887
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!
solr中特殊字符的處理