lucene搜索关键词错误

问题

遇到的异常信息

bash 复制代码
: Lexical error at line 1, column 38.  Encountered: <EOF> after
at org.apache.lucene.queryparser.classic.QueryParserBase.parse(QueryParserBase.java:114)

解决办法

查询搜索时遇到了特殊字符,需要对字符串进行转义

java 复制代码
public static String escape(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
                    || c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
                    || c == '*' || c == '?' || c == '|' || c == '&' || c == '/') {
                sb.append('\\');
            }
            sb.append(c);
        }
        return sb.toString();
    }
相关推荐
考虑考虑3 天前
Mybatis实现批量插入
java·后端·mybatis
TableRow17 天前
参数化搜索的实现原理:从多维索引到查询优化
elasticsearch·全文检索
敲个大西瓜17 天前
mybatis拦截器插件实现数据库字段加解密
mybatis
sunxunyong17 天前
ranger与solr&ldap&doris集成部署
solr·lucene
武子康17 天前
Java-28 深入浅出 Spring 实现简易Ioc-04 在上节的业务下手动实现AOP
java·后端·mybatis
一条泥憨鱼17 天前
苍穹外卖【day6|微信登录与商品浏览功能】
后端·mybatis·苍穹外卖
vx-Biye_Design17 天前
springboot安阳地区研学旅游服务小程序-计算机毕业设计源码12785
java·vue.js·windows·spring boot·tomcat·maven·mybatis
摇滚侠17 天前
MyBatis+Spring+SpringMVC SSM 整合 179-185
java·spring·mybatis
摇滚侠17 天前
MyBatis+Spring+SpringMVC SSM ContextLoaderListener 177-178
java·spring·mybatis