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();
    }
相关推荐
工作log2 小时前
Spring Boot 3.5 + MyBatis Plus + RabbitMQ:打造 AI 驱动的慢 SQL 监控与优化系统
spring boot·mybatis·java-rabbitmq
河阿里2 小时前
MyBatis-Plus:MyBatis的进阶开发
数据库·mybatis
逸Y 仙X2 小时前
文章十六:ElasticSearch 使用enrich策略实现大宽表
java·大数据·数据库·elasticsearch·搜索引擎·全文检索
橙子圆1233 小时前
Mybatis之动态sql
sql·tomcat·mybatis
Elastic 中国社区官方博客4 小时前
通过 Elastic MCP Server 将 Cursor 连接到生产日志
大数据·运维·人工智能·elasticsearch·搜索引擎·全文检索·mcp
risc1234565 小时前
writeBlocks
lucene
byoass6 小时前
企业云盘全文检索技术选型:Elasticsearch、MeiliSearch、Typesense实战对比
大数据·网络·安全·elasticsearch·云计算·全文检索
Elastic 中国社区官方博客18 小时前
使用 Observability Migration Platform 将 Datadog 和 Grafana 的仪表板与告警迁移到 Kibana
大数据·elasticsearch·搜索引擎·信息可视化·全文检索·grafana·datalog
冷小鱼1 天前
MyBatis 与 MyBatis-Plus:从入门到精通的完整指南
java·tomcat·mybatis
香香甜甜的辣椒炒肉1 天前
SpringMVC高级应用和MyBatis-Plus的概念和使用
mybatis