当前位置:网站首页>Mongo fuzzy query, with special characters that need to be escaped, and then query
Mongo fuzzy query, with special characters that need to be escaped, and then query
2022-06-22 04:35:00 【12 procedural ape】
mongdb Fuzzy query , There are also special symbols in the content to be retrieved , cause Unable to retrieve data , Want to achieve the detection effect , Need to be right Detect special characters in the content to escape , To achieve the retrieval effect
One 、 Escape regular special characters Method
/** * Escape regular special characters ($()*+.[]?\^{},|) * * @param keyword * @return */
public static String escapeExprSpecialWord(String keyword) {
String[] fbsArr = {
"\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|" };
for (String key : fbsArr) {
if (keyword.contains(key)) {
keyword = keyword.replace(key, "\\" + key);
}
}
return keyword;
}
Two 、 application
Criteria criteria = new Criteria();
// Project name
if (!ObjectUtils.isEmpty(mixingStationProductionRequesJson.getFgcmc())) {
// criteria.and("fgcmc").regex(".*?" + mixingStationProductionRequesJson.getFgcmc() + ".*?");
// Project name with (), It can not be detected Use backslashes in parentheses "\" Transference \(
String name=escapeExprSpecialWord(mixingStationProductionRequesJson.getFgcmc());
criteria.and("fgcmc").regex("^.*"+name+".*$");
}
Query query = Query.query(criteria);
List<MixingStationRealDataVo> list=mongoTemplate.find(query,MixingStationRealDataVo.class);
边栏推荐
- Basic concept of graph
- Solid smart contract interview questions
- It is easy to analyze and improve R & D efficiency by understanding these five figures
- 插入排序
- QML control types: swipeview, pageindicator
- 解决Swagger2显示UI界面但是没内容
- 顺序表的基本操作
- 拓扑排序
- Es cannot work, circuitbreakingexception
- How does twitter decentralize? Look at these ten socialfi projects
猜你喜欢

有了这几个刷题网站,还愁跳槽不涨薪?

Insert sort

插入排序

KS004 基于SSH通讯录系统设计与实现

Wisdom, agriculture, rural areas and farmers digital Wang Ning: Tips for beginners on the first five days of trading

Overrides vs overloads of methods

LeetCode 437. Path sum III - binary tree series question 13

线索二叉树

WPF DataContext usage (2)

SQL operation: with expression and its application
随机推荐
Fonctionnement de base du tableau de séquence
Accurate identification of bank card information - smart and fast card binding
What is the value of the FC2 new domain name? How to resolve to a website?
Why does golang not recommend this/self/me/that/_ this
Is the Guoyuan futures account reliable? How can a novice safely open an account?
Go 学习笔记
順序錶的基本操作
[BP regression prediction] optimize BP regression prediction based on MATLAB GA (including comparison before optimization) [including Matlab source code 1901]
Interaction between C language and Lua (practice 2)
cadence allegro 17. X conversion tool for downgrading to 16.6
Internet of things UWB technology scheme, intelligent UWB precise positioning, centimeter level positioning accuracy
kubernetes集群中工作节点Noready故障处理
Insert sort
Odoo Development Manual (I) the second day of contact with odoo
New chief maintenance personnel for QT project
"Defi moral paradox" behind solend farce
Golang為什麼不推薦使用this/self/me/that/_this
Specific concept of interceptor
IDS interview questions collection data structure + penetration avalanche + persistence + memory elimination strategy + database double write + Sentinel
队列的顺序实现