修改es按照发布时间倒叙排序,发布时间为空放最后

This commit is contained in:
sh
2026-06-02 11:45:59 +08:00
parent 110f514480
commit e5a73e66f9

View File

@@ -26,6 +26,8 @@ import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.dromara.easyes.core.conditions.update.LambdaEsUpdateWrapper; import org.dromara.easyes.core.conditions.update.LambdaEsUpdateWrapper;
import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -575,7 +577,7 @@ public class ESJobSearchImpl implements IESJobSearchService
wrapper.and(x->x.eq(ESJobDocument::getIsPublish,esJobSearch.getIsPublish())); wrapper.and(x->x.eq(ESJobDocument::getIsPublish,esJobSearch.getIsPublish()));
} }
if(Objects.nonNull(esJobSearch.getOrder())){ if(Objects.nonNull(esJobSearch.getOrder())){
wrapper.orderByDesc(ESJobDocument::getPostingDate); wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
if(esJobSearch.getOrder()==1){ if(esJobSearch.getOrder()==1){
wrapper.orderByDesc(ESJobDocument::getIsHot); wrapper.orderByDesc(ESJobDocument::getIsHot);
} }
@@ -584,7 +586,7 @@ public class ESJobSearchImpl implements IESJobSearchService
} }
}else{ }else{
//默认按照发布时间倒叙 //默认按照发布时间倒叙
wrapper.orderByDesc(ESJobDocument::getPostingDate); 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());
@@ -693,7 +695,7 @@ public class ESJobSearchImpl implements IESJobSearchService
wrapper.and(x->x.eq(ESJobDocument::getIsPublish,jobQuery.getIsPublish())); wrapper.and(x->x.eq(ESJobDocument::getIsPublish,jobQuery.getIsPublish()));
} }
if(Objects.nonNull(jobQuery.getOrder())){ if(Objects.nonNull(jobQuery.getOrder())){
wrapper.orderByDesc(ESJobDocument::getPostingDate); wrapper.sort(SortBuilders.fieldSort("postingDate").order(SortOrder.DESC).missing("_last"));
if (jobQuery.getOrder()==1){ if (jobQuery.getOrder()==1){
wrapper.orderByDesc(ESJobDocument::getIsHot); wrapper.orderByDesc(ESJobDocument::getIsHot);
wrapper.orderByDesc(ESJobDocument::getApplyNum); wrapper.orderByDesc(ESJobDocument::getApplyNum);
@@ -701,7 +703,7 @@ public class ESJobSearchImpl implements IESJobSearchService
} }
}else{ }else{
//默认按照发布时间倒叙 //默认按照发布时间倒叙
wrapper.orderByDesc(ESJobDocument::getPostingDate); 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;