如查询的条件为: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){
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();
}