提交 55454d43 作者: yanxin

专题检索逻辑优化

上级 4d588d16
...@@ -17,6 +17,7 @@ import com.zzsn.event.entity.SubjectStatisticInfo; ...@@ -17,6 +17,7 @@ import com.zzsn.event.entity.SubjectStatisticInfo;
import com.zzsn.event.service.*; import com.zzsn.event.service.*;
import com.zzsn.event.util.DateUtil; import com.zzsn.event.util.DateUtil;
import com.zzsn.event.util.EsDateUtil; import com.zzsn.event.util.EsDateUtil;
import com.zzsn.event.util.EsIndexUtil;
import com.zzsn.event.util.tree.Node; import com.zzsn.event.util.tree.Node;
import com.zzsn.event.vo.*; import com.zzsn.event.vo.*;
import com.zzsn.event.vo.es.DisplayInfo; import com.zzsn.event.vo.es.DisplayInfo;
...@@ -738,7 +739,9 @@ public class EsService { ...@@ -738,7 +739,9 @@ public class EsService {
* @date 2024/5/6 * @date 2024/5/6
*/ */
public IPage<SpecialInformation> pageListByCondition(InfoDataSearchCondition searchCondition, List<String> subjectIdList) throws IOException { public IPage<SpecialInformation> pageListByCondition(InfoDataSearchCondition searchCondition, List<String> subjectIdList) throws IOException {
SearchRequest searchRequest = new SearchRequest(Constants.SUBJECT_INDEX); Subject byId = subjectService.getById(searchCondition.getSubjectId());
String[] indexs = EsIndexUtil.getIndexIntervalYear(Constants.SUBJECT_INDEX, byId.getCreateTime());
SearchRequest searchRequest = new SearchRequest(indexs);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//默认最大数量是10000,设置为true后,显示准确数量 //默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder.trackTotalHits(true); searchSourceBuilder.trackTotalHits(true);
...@@ -819,7 +822,9 @@ public class EsService { ...@@ -819,7 +822,9 @@ public class EsService {
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
List<String> idList = Arrays.asList(ids.split(",")); List<String> idList = Arrays.asList(ids.split(","));
List<String> beInStorageList = idList.stream().map(uniqueCode -> subjectId + uniqueCode).collect(Collectors.toList()); List<String> beInStorageList = idList.stream().map(uniqueCode -> subjectId + uniqueCode).collect(Collectors.toList());
SearchRequest searchRequest = new SearchRequest(Constants.SUBJECT_INDEX); Subject byId = subjectService.getById(subjectId);
String[] indexs = EsIndexUtil.getIndexIntervalYear(Constants.SUBJECT_INDEX, byId.getCreateTime());
SearchRequest searchRequest = new SearchRequest(indexs);
//创建查询对象 //创建查询对象
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must(QueryBuilders.termsQuery("id", beInStorageList)); boolQuery.must(QueryBuilders.termsQuery("id", beInStorageList));
...@@ -1066,7 +1071,9 @@ public class EsService { ...@@ -1066,7 +1071,9 @@ public class EsService {
//调用判重接口 //调用判重接口
public boolean duplicationByTitleOrSourceAddress(DisplayInfo displayInfo) { public boolean duplicationByTitleOrSourceAddress(DisplayInfo displayInfo) {
SearchRequest searchRequest = new SearchRequest(Constants.SUBJECT_INDEX); Subject byId = subjectService.getById(displayInfo.getSubjectId());
String[] indexs = EsIndexUtil.getIndexIntervalYear(Constants.SUBJECT_INDEX, byId.getCreateTime());
SearchRequest searchRequest = new SearchRequest(indexs);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
BoolQueryBuilder shouldBoolQuery = QueryBuilders.boolQuery(); BoolQueryBuilder shouldBoolQuery = QueryBuilders.boolQuery();
...@@ -1106,7 +1113,9 @@ public class EsService { ...@@ -1106,7 +1113,9 @@ public class EsService {
if (CollectionUtils.isNotEmpty(ids)) { if (CollectionUtils.isNotEmpty(ids)) {
count = ids.size(); count = ids.size();
} else { } else {
SearchRequest searchRequest = new SearchRequest(Constants.SUBJECT_INDEX); Subject byId = subjectService.getById(searchCondition.getSubjectId());
String[] indexs = EsIndexUtil.getIndexIntervalYear(Constants.SUBJECT_INDEX, byId.getCreateTime());
SearchRequest searchRequest = new SearchRequest(indexs);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//默认最大数量是10000,设置为true后,显示准确数量 //默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder.trackTotalHits(true); searchSourceBuilder.trackTotalHits(true);
...@@ -1149,7 +1158,9 @@ public class EsService { ...@@ -1149,7 +1158,9 @@ public class EsService {
* @param searchCondition 查询条件封装 * @param searchCondition 查询条件封装
*/ */
public List<SpecialInformation> informationList(InfoDataSearchCondition searchCondition) { public List<SpecialInformation> informationList(InfoDataSearchCondition searchCondition) {
SearchRequest searchRequest = new SearchRequest(Constants.SUBJECT_INDEX); Subject byId = subjectService.getById(searchCondition.getSubjectId());
String[] indexs = EsIndexUtil.getIndexIntervalYear(Constants.SUBJECT_INDEX, byId.getCreateTime());
SearchRequest searchRequest = new SearchRequest(indexs);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
String column = searchCondition.getColumn(); String column = searchCondition.getColumn();
String order = searchCondition.getOrder(); String order = searchCondition.getOrder();
......
package com.zzsn.event.util; package com.zzsn.event.util;
import cn.hutool.core.date.DateUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -41,6 +43,14 @@ public class EsIndexUtil { ...@@ -41,6 +43,14 @@ public class EsIndexUtil {
return indexs; return indexs;
} }
/**
* 根据索引名称获取带有上年的索引名称 subjectdatabase --> subjectdatabase_2023
* @param index
* @return
*/
public static String getPreIndexYear(String index){
return index + "_" + (LocalDateTime.now().getYear() - 1);
}
/** /**
* 获取两个时间之间的所有年份 * 获取两个时间之间的所有年份
...@@ -78,11 +88,34 @@ public class EsIndexUtil { ...@@ -78,11 +88,34 @@ public class EsIndexUtil {
* 获取两个时间之间的所有年份 * 获取两个时间之间的所有年份
* 并返回数组 * 并返回数组
* @param startDate 搜索范围开始年份 * @param startDate 搜索范围开始年份
* @return
*/
public static String[] getIndexIntervalYear(String index, Date startDate){
if(startDate == null){
return new String[]{index};
}
return getIndexIntervalYearStr(index, DateUtil.formatDate(startDate));
}
/**
* 获取两个时间之间的所有年份
* 并返回数组
* @param startDate 搜索范围开始年份
* @return
*/
public static String[] getIndexIntervalYearStr(String index, String startDate){
return getIndexIntervalYear(index, startDate, null);
}
/**
* 获取两个时间之间的所有年份
* 并返回数组
* @param startDate 搜索范围开始年份
* @param endDate 搜索范围结束年份 * @param endDate 搜索范围结束年份
* @return * @return
*/ */
public static String[] getIndexIntervalYear(String index, String startDate, String endDate){ public static String[] getIndexIntervalYear(String index, String startDate, String endDate){
if(StringUtils.isEmpty(startDate) && StringUtils.isEmpty(endDate)){
return new String[]{index};
}
Integer startYear; Integer startYear;
Integer endYear; Integer endYear;
if (StringUtils.isNotBlank(startDate)) { if (StringUtils.isNotBlank(startDate)) {
...@@ -108,5 +141,4 @@ public class EsIndexUtil { ...@@ -108,5 +141,4 @@ public class EsIndexUtil {
String[] indexs = getIndexIntervalYear(index,startYear,endYear); String[] indexs = getIndexIntervalYear(index,startYear,endYear);
return indexs; return indexs;
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论