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();
    }
相关推荐
Minyy118 小时前
使用注解方式整合ssm时,启动tomcat扫描不到resource下面的xxxmapper.xml问题,解决方法
java·spring boot·spring·apache·mybatis
A阳俊yi14 小时前
整合SSM——(SpringMVC+Spring+Mybatis)
java·spring·mybatis
岁岁岁平安16 小时前
基于SpringBoot3实现MyBatis-Plus(SSMP)整合快速入门CURD(增删改查)
java·spring boot·spring·java-ee·mvc·mybatis·mybatis-plus
人生不过一瞬间19 小时前
Unity webgl 获取图片或视频数据
unity·lucene·webgl
字节王德发1 天前
MyBatis如何配置数据库连接并实现交互?
数据库·mybatis·交互
bing_1581 天前
Spring Boot 微服务中集成 MyBatis-Plus 与集成原生 MyBatis 有哪些配置上的不同?
spring boot·微服务·mybatis
江沉晚呤时1 天前
从零开始学习 Lucene.Net:.NET Core 中的全文搜索与索引管理
开发语言·c#·.net·mybatis·.netcore·lucene
程序员阿鹏1 天前
前端vue+后端ssm项目
java·开发语言·spring·tomcat·maven·mybatis·hibernate
Yharim3 天前
mybatis中一对一、多对多关联查询怎么实现
后端·mybatis
Thomas_YXQ4 天前
Unity3D 测试驱动开发(TDD)框架设计
java·开发语言·驱动开发·全文检索·unity3d·lucene·tdd