提交 16b8f6af 作者: 925993793@qq.com

代码调整

上级 207f7049
......@@ -223,7 +223,7 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
List<EventNewPlatVO> pageList = baseMapper.newPlatPageList(subjectCondition, offset, pageSize);
long t1 = System.currentTimeMillis();
count(pageList);
System.out.println("数量统计耗时====" + (System.currentTimeMillis() - t1));
log.info("数量统计总共耗时====" + (System.currentTimeMillis() - t1));
//获取总条数
Integer count = baseMapper.newPlatCount(subjectCondition);
IPage<EventNewPlatVO> pageData = new Page<>(pageNo, pageSize, count);
......@@ -651,10 +651,12 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
//查询每个专题的数量
private Map<String, Integer> subjectInfoCountMap(List<String> subjectIdList, List<Integer> checkStatusList) {
Map<String, Integer> map = new HashMap<>(subjectIdList.size());
SearchRequest searchRequest = new SearchRequest(Constants.SUBJECT_INDEX);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
//默认最大数量是10000,设置为true后,显示准确数量
searchSourceBuilder.trackTotalHits(true);
searchSourceBuilder.size(0);
//创建查询对象
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must(QueryBuilders.termsQuery("subjectId.keyword", subjectIdList));
......@@ -667,28 +669,22 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
//分组
TermsAggregationBuilder aggregationBuilder = AggregationBuilders.terms("group_subjectId").field("subjectId.keyword");
searchSourceBuilder.aggregation(aggregationBuilder);
//不返回文本内容
searchSourceBuilder.fetchSource(false);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = null;
try {
searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
//获取分组桶
Aggregations aggregations = searchResponse.getAggregations();
//获取id分组集合
Terms parsedStringTerms = aggregations.get("group_subjectId");
List<? extends Terms.Bucket> buckets = parsedStringTerms.getBuckets();
for (Terms.Bucket bucket : buckets) {
String subjectId = bucket.getKeyAsString();
long collectCount = bucket.getDocCount();
map.put(subjectId, (int) collectCount);
}
} catch (IOException e) {
e.printStackTrace();
}
//获取分组桶
Aggregations aggregations = searchResponse.getAggregations();
//获取id分组集合
Terms parsedStringTerms = aggregations.get("group_subjectId");
List<? extends Terms.Bucket> buckets = parsedStringTerms.getBuckets();
Map<String, Integer> map = new HashMap<>(subjectIdList.size());
for (Terms.Bucket bucket : buckets) {
String subjectId = bucket.getKeyAsString();
long collectCount = bucket.getDocCount();
map.put(subjectId, (int) collectCount);
}
return map;
}
......@@ -696,14 +692,21 @@ public class EventServiceImpl extends ServiceImpl<EventMapper, Event> implements
if (CollectionUtils.isNotEmpty(pageList)) {
List<String> idList = pageList.stream().map(EventNewPlatVO::getId).collect(Collectors.toList());
Map<String, Integer> infoSourceNumMap = new HashMap<>();
long t1 = System.currentTimeMillis();
Map<String, Integer> keyWordsNumMap = baseMapper.bindKeywordCountList(idList).stream().collect(Collectors.toMap(SubjectPage::getId, SubjectPage::getKeyWordsNum));
long t2 = System.currentTimeMillis();
log.info("关键词数量查询耗时==={}",t2-t1);
Map<String, List<SubjectSourceVO>> collect = subjectBindSourceList(idList).stream().collect(Collectors.groupingBy(SubjectSourceVO::getSubjectId));
long t3 = System.currentTimeMillis();
log.info("信息源数量查询耗时==={}",t3-t2);
for (Map.Entry<String, List<SubjectSourceVO>> entry : collect.entrySet()) {
String subjectId = entry.getKey();
List<SubjectSourceVO> value = entry.getValue();
infoSourceNumMap.put(subjectId, value.size());
}
long t4 = System.currentTimeMillis();
Map<String, Integer> subjectInfoCountMap = subjectInfoCountMap(idList, null);
log.info("资讯数量查询耗时==={}",System.currentTimeMillis()-t4);
for (EventNewPlatVO newPlatVO : pageList) {
int keyWordsNum = null == keyWordsNumMap.get(newPlatVO.getId()) ? 0 : keyWordsNumMap.get(newPlatVO.getId());
int infoSourceNum = null == infoSourceNumMap.get(newPlatVO.getId()) ? 0 : infoSourceNumMap.get(newPlatVO.getId());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论