diff --git a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java index 71d3ec0..14626c3 100644 --- a/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java +++ b/ruoyi-bussiness/src/main/java/com/ruoyi/cms/service/impl/ESJobSearchImpl.java @@ -576,17 +576,29 @@ public class ESJobSearchImpl implements IESJobSearchService if(Objects.nonNull(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())){ - wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last")); - if(esJobSearch.getOrder()==1){ - wrapper.orderByDesc(ESJobDocument::getIsHot); + switch (esJobSearch.getOrder()) { + case 0: // 推荐:权重 → 最新发布 + 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 boolean isCompanyUser = StringUtil.IS_COMPANY_USER.equals(esJobSearch.getUserType()); @@ -694,16 +706,29 @@ public class ESJobSearchImpl implements IESJobSearchService if(Objects.nonNull(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())){ - wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last")); - if (jobQuery.getOrder()==1){ - wrapper.orderByDesc(ESJobDocument::getIsHot); - wrapper.orderByDesc(ESJobDocument::getApplyNum); - wrapper.orderByDesc(ESJobDocument::getView); + switch (jobQuery.getOrder()) { + case 0: // 推荐:权重 → 最新发布 + 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")); } - }else{ - //默认按照发布时间倒叙 - wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last")); } EsPageInfo esJobDocumentEsPageInfo = esJobDocumentMapper.pageQuery(wrapper, pageNum, pageSize); return esJobDocumentEsPageInfo;