问题描述
我的 Spring Boot 项目中有一个自定义的 jpql 查询,如果某个关键字(可以是多个词,如“我正在搜索”)存在,它会在 blob 文件(HTML 内容)中搜索。它就像一个搜索引擎。但我想忽略区分大小写。所以在网上搜索后,我做了以下查询:
/**
* Custom query to search in results
* @param keyword keyword to search with
* @param startDate to search between
* @param endDate to search between
* @return list of all results
*/
@Query("select r from Requests r where lower(r.document) like lower(concat('%',:keyword,'%')) and (r.timestamp between :startDate and :endDate) ")
List<Requests> searchRequests(
@Param("keyword") String keyword,@Param("startDate") Date startDate,@Param("endDate") Date endDate);
但现在似乎对关键字字符串中的多个词不起作用,单个词起作用。
如果我把它改成:
/**
* Custom query to search in results
* @param keyword keyword to search with
* @param startDate to search between
* @param endDate to search between
* @return list of all results
*/
@Query("select r from Requests r where r.document like %:keyword% and (r.timestamp between :startDate and :endDate) ")
List<Requests> searchRequests(
@Param("keyword") String keyword,@Param("endDate") Date endDate);
它适用于 keyword
字符串中的多个单词,但区分大小写...
我不知道为什么会这样,但可能是因为 r.document 是一个包含 HTML 页面的 blob 文件?但是 is 对 keyword
字符串中的单个单词有效。所以也许它只会降低 keyword
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)