修改排序问题

This commit is contained in:
sh
2026-06-04 13:26:58 +08:00
parent d8c6a32e74
commit 1bcbaa54e0

View File

@@ -576,17 +576,29 @@ public class ESJobSearchImpl implements IESJobSearchService
if(Objects.nonNull(esJobSearch.getIsPublish())){ if(Objects.nonNull(esJobSearch.getIsPublish())){
wrapper.and(x->x.eq(ESJobDocument::getIsPublish,esJobSearch.getIsPublish())); wrapper.and(x->x.eq(ESJobDocument::getIsPublish,esJobSearch.getIsPublish()));
} }
// 全局固定:权重优先(必须写在最前面)
wrapper.trackScores();
wrapper.sortByScore(SortOrder.DESC);
//0推荐 1最热 2最新发布 3最大薪资
if(Objects.nonNull(esJobSearch.getOrder())){ if(Objects.nonNull(esJobSearch.getOrder())){
wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last")); switch (esJobSearch.getOrder()) {
if(esJobSearch.getOrder()==1){ case 0: // 推荐:权重 → 最新发布
wrapper.orderByDesc(ESJobDocument::getIsHot); wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
break;
case 1: // 最热:权重 → 热度
wrapper.orderByDesc(ESJobDocument::getIsHot);
wrapper.orderByDesc(ESJobDocument::getApplyNum);
wrapper.orderByDesc(ESJobDocument::getView);
break;
case 2: // 最新发布:权重 → 最新发布
wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
break;
case 3: // 最大薪资:权重 → 最高薪资
wrapper.orderByDesc(ESJobDocument::getMaxSalary);
break;
default: // 默认:权重 → 最新发布
wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
} }
if(esJobSearch.getOrder()==3){
wrapper.orderByDesc(ESJobDocument::getMaxSalary);
}
}else{
//默认按照发布时间倒叙
wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
} }
//企业用户排除es去除jobIds //企业用户排除es去除jobIds
boolean isCompanyUser = StringUtil.IS_COMPANY_USER.equals(esJobSearch.getUserType()); boolean isCompanyUser = StringUtil.IS_COMPANY_USER.equals(esJobSearch.getUserType());
@@ -694,16 +706,29 @@ public class ESJobSearchImpl implements IESJobSearchService
if(Objects.nonNull(jobQuery.getIsPublish())){ if(Objects.nonNull(jobQuery.getIsPublish())){
wrapper.and(x->x.eq(ESJobDocument::getIsPublish,jobQuery.getIsPublish())); wrapper.and(x->x.eq(ESJobDocument::getIsPublish,jobQuery.getIsPublish()));
} }
// 全局固定:权重优先(必须写在最前面)
wrapper.trackScores();
wrapper.sortByScore(SortOrder.DESC);
//0推荐 1最热 2最新发布 3最大薪资
if(Objects.nonNull(jobQuery.getOrder())){ if(Objects.nonNull(jobQuery.getOrder())){
wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last")); switch (jobQuery.getOrder()) {
if (jobQuery.getOrder()==1){ case 0: // 推荐:权重 → 最新发布
wrapper.orderByDesc(ESJobDocument::getIsHot); wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
wrapper.orderByDesc(ESJobDocument::getApplyNum); break;
wrapper.orderByDesc(ESJobDocument::getView); case 1: // 最热:权重 → 热度
wrapper.orderByDesc(ESJobDocument::getIsHot);
wrapper.orderByDesc(ESJobDocument::getApplyNum);
wrapper.orderByDesc(ESJobDocument::getView);
break;
case 2: // 最新发布:权重 → 最新发布
wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
break;
case 3: // 最大薪资:权重 → 最高薪资
wrapper.orderByDesc(ESJobDocument::getMaxSalary);
break;
default: // 默认:权重 → 最新发布
wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
} }
}else{
//默认按照发布时间倒叙
wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
} }
EsPageInfo<ESJobDocument> esJobDocumentEsPageInfo = esJobDocumentMapper.pageQuery(wrapper, pageNum, pageSize); EsPageInfo<ESJobDocument> esJobDocumentEsPageInfo = esJobDocumentMapper.pageQuery(wrapper, pageNum, pageSize);
return esJobDocumentEsPageInfo; return esJobDocumentEsPageInfo;