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();
    }
相关推荐
それども4 小时前
Mybatis xml 执行提示 NoSuchPropertyException
xml·mybatis
qq_366086226 小时前
MyBatis 动态 SQL 高频性能优化方案
sql·性能优化·mybatis
aygh6 小时前
互联网大厂Java面试场景:技术问答实录
mybatis·springboot·多线程·hashmap·java面试·arraylist·技术总结
独断万古他化6 小时前
【Java 实战项目】多用户网页版聊天室:项目总览与用户 & 好友管理模块实现
java·spring boot·后端·websocket·mybatis
tsyjjOvO7 小时前
SpringBoot 整合 MyBatis
java·spring boot·mybatis
Elastic 中国社区官方博客7 小时前
Elasticsearch BBQ:一场教科书式的向量搜索 “弯道超车”
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
StackNoOverflow8 小时前
Spring Boot 整合 MyBatis + 自动配置原理详解
spring boot·后端·mybatis
bearpping8 小时前
idea、mybatis报错Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required
tomcat·intellij-idea·mybatis
weixin_704266059 小时前
Spring Boot (整合 Mybatis + 自动配置原理)
spring boot·笔记·mybatis
小旭952710 小时前
SpringBoot 整合 MyBatis 与自动配置原理详解
java·spring boot·后端·spring·intellij-idea·mybatis