搜索功能bug修复

This commit is contained in:
冯辉
2026-06-28 16:34:00 +08:00
parent cacade02ff
commit ea8e307dc4
4 changed files with 1424 additions and 148 deletions

View File

@@ -9,7 +9,9 @@ import com.ruoyi.cms.domain.Job;
import com.ruoyi.cms.domain.query.ESJobSearch;
import com.ruoyi.cms.mapper.es.EsJobDocumentMapper;
import com.ruoyi.cms.mapper.JobMapper;
import com.ruoyi.cms.mapper.JobTitleMapper;
import com.ruoyi.cms.service.IESJobSearchService;
import com.ruoyi.common.core.domain.entity.JobTitle;
import com.ruoyi.cms.util.ListUtil;
import com.ruoyi.cms.util.StringUtil;
import com.ruoyi.common.core.domain.entity.Company;
@@ -68,6 +70,8 @@ public class ESJobSearchImpl implements IESJobSearchService
@Autowired
private BussinessDictDataServiceImpl bussinessDictDataServicel;
@Autowired
private JobTitleMapper jobTitleMapper;
Logger logger = LoggerFactory.getLogger(JobServiceImpl.class);
/**
* 项目启动时,初始化索引及数据
@@ -181,6 +185,7 @@ public class ESJobSearchImpl implements IESJobSearchService
for (Job job : jobList) {
ESJobDocument esJobDocument = new ESJobDocument();
BeanUtils.copyBeanProp(esJobDocument, job);
esJobDocument.setJobCategory(resolveJobCategoryLabel(job.getJobCategory()));
//类型转换导致赋值问题,重新赋值
esJobDocument.setScale(org.apache.commons.lang3.StringUtils.isNotEmpty(job.getScale()) ? Integer.parseInt(job.getScale()) : 0);
CompanyVo vo=job.getCompanyVo();
@@ -260,14 +265,13 @@ public class ESJobSearchImpl implements IESJobSearchService
List<ESJobDocument> esJobDocuments = esJobDocumentMapper.selectList(wrapper);
if (!isCompanyUser &&esJobDocuments.size() < esJobSearch.getPageSize()) {
// 定义要逐步放宽的搜索条件字段
// 定义要逐步放宽的搜索条件字段(不放松核心文本搜索条件)
List<Runnable> relaxConditions = new ArrayList<>();
relaxConditions.add(() -> newSearch.setArea(null));
relaxConditions.add(() -> newSearch.setExperience(null));
relaxConditions.add(() -> newSearch.setMaxSalary(null));
relaxConditions.add(() -> newSearch.setMinSalary(null));
relaxConditions.add(() -> newSearch.setEducation(null));
relaxConditions.add(()-> newSearch.setJobTitle(null));
// 保存所有查询到的文档
List<ESJobDocument> allDocuments = new ArrayList<>(esJobDocuments);
@@ -513,7 +517,10 @@ public class ESJobSearchImpl implements IESJobSearchService
String[] words = titleStr.split(",");
for (String w : words) {
if (!first) sub.or();
// 同时匹配岗位名称和岗位分类jobCategory 已存储为标签文字)
sub.match(ESJobDocument::getJobTitle, w, 5.0f);
sub.or();
sub.match(ESJobDocument::getJobCategory, w, 5.0f);
first = false;
}
}
@@ -858,6 +865,7 @@ public class ESJobSearchImpl implements IESJobSearchService
}
BeanUtils.copyBeanProp(esJobDocument, job);
esJobDocument.setJobCategory(resolveJobCategoryLabel(job.getJobCategory()));
esJobDocument.setAppJobUrl("https://www.xjksly.cn/app#/packageA/pages/post/post?jobId="+ Base64.getEncoder().encodeToString(String.valueOf(job.getJobId()).getBytes()));
if(!StringUtil.isEmptyOrNull(job.getScale())){
esJobDocument.setScale(Integer.valueOf(job.getScale()));
@@ -1001,15 +1009,13 @@ public class ESJobSearchImpl implements IESJobSearchService
List<ESJobDocument> esJobDocuments = esJobDocumentMapper.selectList(wrapper);
if (esJobDocuments.size() < esJobSearch.getPageSize()) {
// 定义要逐步放宽的搜索条件字段
// 定义要逐步放宽的搜索条件字段(不放松核心文本搜索条件)
List<Runnable> relaxConditions = new ArrayList<>();
relaxConditions.add(() -> newSearch.setArea(null));
relaxConditions.add(() -> newSearch.setExperience(null));
relaxConditions.add(() -> newSearch.setMaxSalary(null));
relaxConditions.add(() -> newSearch.setMinSalary(null));
relaxConditions.add(() -> newSearch.setEducation(null));
relaxConditions.add(()-> newSearch.setJobCategory(null));
relaxConditions.add(()-> newSearch.setJobTitle(null));
// 保存所有查询到的文档
List<ESJobDocument> allDocuments = new ArrayList<>(esJobDocuments);
@@ -1048,4 +1054,24 @@ public class ESJobSearchImpl implements IESJobSearchService
return esJobDocuments;
}
/**
* 将 jobCategory 从数字ID解析为标签文字如 "45" → "销售顾问"
* 如果已经是文字标签或解析失败,返回原值
*/
private String resolveJobCategoryLabel(String jobCategory) {
if (StringUtils.isEmpty(jobCategory)) {
return jobCategory;
}
try {
Long categoryId = Long.parseLong(jobCategory);
JobTitle jobTitle = jobTitleMapper.selectById(categoryId);
if (jobTitle != null && StringUtils.isNotEmpty(jobTitle.getJobName())) {
return jobTitle.getJobName();
}
} catch (NumberFormatException e) {
// 已经是文字标签,直接返回原值
}
return jobCategory;
}
}