pageWithattr接口判断name参数长度、中文 来分别使用分词或like查询

This commit is contained in:
wangliwen 2022-12-29 09:27:53 +08:00
parent 091186a0e8
commit a087eea1bf
1 changed files with 10 additions and 1 deletions

View File

@ -101,6 +101,8 @@ import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -601,8 +603,15 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
} }
break; break;
} }
Boolean nonChinese = jsonObject.containsKey("nonChinese") ? jsonObject.getBoolean("nonChinese") : Boolean.FALSE; // 不传默认为中文走全文索引 Boolean nonChinese = jsonObject.containsKey("nonChinese") ? jsonObject.getBoolean("nonChinese") : Boolean.FALSE; // 不传默认为中文走全文索引
Pattern isChinese = Pattern.compile("[\u4e00-\u9fa5]"); // 中文
String name = jsonObject.containsKey("name") ? jsonObject.getString("name") : "";
Matcher isChineseMatcher = isChinese.matcher(name);
if (!nonChinese && (isChineseMatcher.matches() && name.length() < 2)) {
nonChinese = Boolean.TRUE;
} else if (name.length() < 2) { // 长度小于分词长度2
nonChinese = Boolean.TRUE;
}
//默认按上架时间降序排列 //默认按上架时间降序排列
String orderField; String orderField;
if (StringUtils.isBlank(jsonObject.getString("orderField"))) { if (StringUtils.isBlank(jsonObject.getString("orderField"))) {