提交 5cc7774b 作者: obcy

Merge remote-tracking branch 'origin/event_fusion' into event_fusion

# Conflicts:
#	src/main/java/com/zzsn/event/vo/InfoDataSearchCondition.java
......@@ -13,11 +13,11 @@ import com.zzsn.event.enums.LabelTypeEnum;
import com.zzsn.event.es.EsService;
import com.zzsn.event.service.*;
import com.zzsn.event.util.PythonUtil;
import com.zzsn.event.util.tree.Node;
import com.zzsn.event.util.user.UserUtil;
import com.zzsn.event.util.user.UserVo;
import com.zzsn.event.vo.*;
import com.zzsn.event.vo.es.DisplayInfo;
import com.zzsn.event.vo.es.Label;
import com.zzsn.event.vo.es.SpecialInformation;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -564,8 +564,9 @@ public class InformationController {
@PostMapping("/addToFavorites")
public Result<?> addToFavorites(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId();
if (StringUtils.isEmpty(subjectId)) {
return Result.FAIL("专题id不能为空");
List<String> ids = searchCondition.getIds();
if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
}
informationService.addToFavorites(searchCondition);
return Result.OK();
......@@ -581,8 +582,9 @@ public class InformationController {
@PostMapping("/addToPend")
public Result<?> addToPend(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId();
if (StringUtils.isEmpty(subjectId)) {
return Result.FAIL("专题id不能为空");
List<String> ids = searchCondition.getIds();
if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
}
informationService.addToPend(searchCondition);
return Result.OK();
......@@ -598,8 +600,9 @@ public class InformationController {
@PostMapping("/addToRemove")
public Result<?> addToRemove(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId();
if (StringUtils.isEmpty(subjectId)) {
return Result.FAIL("专题id不能为空");
List<String> ids = searchCondition.getIds();
if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
}
informationService.addToRemove(searchCondition);
return Result.OK();
......@@ -622,6 +625,13 @@ public class InformationController {
return Result.OK();
}
//@PostMapping("/searchForReplaceList")
public Result<?> searchForReplaceList(@RequestBody InfoDataSearchCondition searchCondition){
IPage<SpecialInformation> page = informationService.searchForReplaceList(searchCondition);
return Result.OK(page);
}
/**
* 字符串替换
*
......@@ -643,5 +653,49 @@ public class InformationController {
return Result.OK();
}
/**
* 资讯批量打标
*
* @param searchCondition 检索条件
* @author lkg
* @date 2025/4/23
*/
@PostMapping("/markTag")
public Result<?> markTag(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId();
List<String> ids = searchCondition.getIds();
if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
}
List<Label> markTags = searchCondition.getMarkTags();
if (CollectionUtils.isEmpty(markTags)) {
return Result.FAIL("标签不能为空");
}
informationService.markTag(searchCondition);
return Result.OK();
}
/**
* 资讯批量删除标签
*
* @param searchCondition 检索条件
* @author lkg
* @date 2025/4/23
*/
@PostMapping("/removeTag")
public Result<?> removeTag(@RequestBody InfoDataSearchCondition searchCondition) {
String subjectId = searchCondition.getSubjectId();
List<String> ids = searchCondition.getIds();
if (StringUtils.isEmpty(subjectId) && CollectionUtils.isEmpty(ids)) {
return Result.FAIL("专题id和资讯id集合不能同时为空");
}
List<Label> markTags = searchCondition.getMarkTags();
if (CollectionUtils.isEmpty(markTags)) {
return Result.FAIL("标签不能为空");
}
informationService.removeTag(searchCondition);
return Result.OK();
}
}
......@@ -36,6 +36,7 @@ import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.HttpAsyncResponseConsumerFactory;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.query.*;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
......@@ -56,6 +57,8 @@ import org.elasticsearch.search.aggregations.metrics.Cardinality;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.collapse.CollapseBuilder;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.elasticsearch.search.sort.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -842,10 +845,10 @@ public class EsService {
break;
default:
NestedSortBuilder nestedWordSortBuilder = new NestedSortBuilder("sortField");
nestedWordSortBuilder.setFilter(QueryBuilders.termQuery("sortField.fieldType", column));
nestedWordSortBuilder.setFilter(QueryBuilders.termsQuery("sortField.fieldType", Arrays.asList(column.split(","))));
FieldSortBuilder fieldWordSortBuilder = SortBuilders.fieldSort("sortField.fieldLong")
.order(sortOrder)
.sortMode(SortMode.MAX)
.sortMode(SortMode.SUM)
.setNestedSort(nestedWordSortBuilder);
searchSourceBuilder.sort(fieldWordSortBuilder);
break;
......@@ -1236,6 +1239,9 @@ public class EsService {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
String column = searchCondition.getColumn();
String order = searchCondition.getOrder();
if (StringUtils.isEmpty(column)) {
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
} else {
switch (column) {
case "topNum":
searchSourceBuilder.sort("topNum", SortOrder.DESC);
......@@ -1258,6 +1264,7 @@ public class EsService {
searchSourceBuilder.sort("publishDate", SortOrder.DESC);
break;
}
}
String[] fetchFields = searchCondition.getFetchFields();
if (fetchFields != null && fetchFields.length > 0) {
searchSourceBuilder.fetchSource(fetchFields, null);
......@@ -1937,6 +1944,76 @@ public class EsService {
return list;
}
public IPage<SpecialInformation> searchForReplaceList(InfoDataSearchCondition searchCondition) {
List<String> subjectIds = new ArrayList<>();
subjectIds.add(searchCondition.getSubjectId());
String minCreateTime = subjectService.getMinCreateTime(subjectIds);
String[] indexArr = EsIndexUtil.getIndexIntervalYearStr(Constants.SUBJECT_INDEX, minCreateTime);
SearchRequest searchRequest = new SearchRequest(indexArr);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.trackTotalHits(true);
String[] fetchFields = new String[]{"id", "title", "origin", "content"};
searchSourceBuilder.fetchSource(fetchFields, null);
//设置高亮
HighlightBuilder highlightBuilder = new HighlightBuilder();
highlightBuilder.preTags("<font style = 'color:red;'>");
highlightBuilder.postTags("</font>");
List<HighlightBuilder.Field> fields = highlightBuilder.fields();
fields.add(new HighlightBuilder.Field("title").numOfFragments(0));
fields.add(new HighlightBuilder.Field("origin").numOfFragments(0));
fields.add(new HighlightBuilder.Field("content").numOfFragments(0));
searchSourceBuilder.highlighter(highlightBuilder);
//设置分页参数
Integer pageNo = searchCondition.getPageNo();
Integer pageSize = searchCondition.getPageSize();
searchSourceBuilder.from((pageNo - 1) * pageSize);
searchSourceBuilder.size(pageSize);
BoolQueryBuilder boolQuery = buildQuery(searchCondition, subjectIds);
searchSourceBuilder.query(boolQuery);
searchRequest.source(searchSourceBuilder);
IPage<SpecialInformation> pageData = new Page<>();
try {
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
SearchHit[] searchHits = searchResponse.getHits().getHits();
List<SpecialInformation> list = new ArrayList<>();
for (SearchHit hit : searchHits) {
String queryInfo = hit.getSourceAsString();
SpecialInformation info = JSONUtil.toBean(queryInfo, SpecialInformation.class);
Map<String, HighlightField> highlightFields = hit.getHighlightFields();
if (highlightFields.containsKey("title")) {
Text[] titles = highlightFields.get("title").getFragments();
StringBuilder titleHighlight = new StringBuilder();
for (Text title : titles) {
titleHighlight.append(title.string());
}
info.setTitle(titleHighlight.toString());
}
if (highlightFields.containsKey("origin")) {
Text[] origins = highlightFields.get("origin").getFragments();
StringBuilder originHighlight = new StringBuilder();
for (Text origin : origins) {
originHighlight.append(origin.string());
}
info.setOrigin(originHighlight.toString());
}
if (highlightFields.containsKey("content")) {
Text[] contents = highlightFields.get("content").getFragments();
StringBuilder contentHighlight = new StringBuilder();
for (Text content : contents) {
contentHighlight.append(content.string());
}
info.setContent(contentHighlight.toString());
}
list.add(info);
}
pageData = new Page<>(pageNo, pageSize, searchResponse.getHits().getTotalHits().value);
pageData.setRecords(list);
} catch (IOException e) {
e.printStackTrace();
}
return pageData;
}
/**
* term方式聚合分组
*
......@@ -2084,7 +2161,7 @@ public class EsService {
Integer status = searchCondition.getStatus();
if (status != null) {
if (status == 1) {
boolQuery.must(QueryBuilders.termQuery("checkStatus",0));
boolQuery.must(QueryBuilders.termQuery("checkStatus", 0));
boolQuery.must(QueryBuilders.termQuery("isFreeCheck", 1));
boolQuery.mustNot(QueryBuilders.termQuery("deleteFlag", 1));
} else if (status == 2) {
......@@ -2148,6 +2225,19 @@ public class EsService {
if (maxScore != null) {
boolQuery.filter(QueryBuilders.rangeQuery("score").lte(maxScore));
}
//正文长度筛选
Integer minContentLength = searchCondition.getMinContentLength();
if (minContentLength != null) {
NestedQueryBuilder nestedQueryBuilder = QueryBuilders
.nestedQuery("sortField", QueryBuilders.rangeQuery("sortField.fieldLong").gte(minContentLength), ScoreMode.None);
boolQuery.filter(nestedQueryBuilder);
}
Integer maxContentLength = searchCondition.getMaxContentLength();
if (maxContentLength != null) {
NestedQueryBuilder nestedQueryBuilder = QueryBuilders
.nestedQuery("sortField", QueryBuilders.rangeQuery("sortField.fieldLong").lte(maxContentLength), ScoreMode.None);
boolQuery.filter(nestedQueryBuilder);
}
//时间过滤筛选-前端传参
if (StringUtils.isNotBlank(searchCondition.getStartTime())) {
boolQuery.filter(QueryBuilders.rangeQuery("publishDate").gte(EsDateUtil.esFieldDateFormat(searchCondition.getStartTime())));
......
......@@ -308,6 +308,15 @@ public interface InformationService {
void initialData(InfoDataSearchCondition searchCondition);
/**
* 查找替换信息列表
*
* @param searchCondition 资讯检索条件
* @author lkg
* @date 2025/4/24
*/
IPage<SpecialInformation> searchForReplaceList(InfoDataSearchCondition searchCondition);
/**
* 字符串替换
*
* @param searchCondition 资讯检索条件
......@@ -315,4 +324,22 @@ public interface InformationService {
* @date 2025/4/23
*/
void charReplace(InfoDataSearchCondition searchCondition);
/**
* 打标签
*
* @param searchCondition 资讯检索条件
* @author lkg
* @date 2025/4/23
*/
void markTag(InfoDataSearchCondition searchCondition);
/**
* 打标签
*
* @param searchCondition 资讯检索条件
* @author lkg
* @date 2025/4/23
*/
void removeTag(InfoDataSearchCondition searchCondition);
}
......@@ -1240,6 +1240,11 @@ public class InformationServiceImpl implements InformationService {
}
@Override
public IPage<SpecialInformation> searchForReplaceList(InfoDataSearchCondition searchCondition) {
return esService.searchForReplaceList(searchCondition);
}
@Override
public void charReplace(InfoDataSearchCondition searchCondition) {
SearchWordVO searchWordVO = searchCondition.getSearchWordList().get(0);
Integer searchScope = searchWordVO.getSearchScope();
......@@ -1269,6 +1274,52 @@ public class InformationServiceImpl implements InformationService {
esOpUtil.batchReplaceScript(indexArr, buildQuery, modifyFields, oldWord, newWord);
}
@Override
public void markTag(InfoDataSearchCondition searchCondition) {
List<String> subjectIdList = new ArrayList<>();
subjectIdList.add(searchCondition.getSubjectId());
String minCreateTime = subjectService.getMinCreateTime(subjectIdList);
String[] indexArr = EsIndexUtil.getIndexIntervalYearStr(Constants.SUBJECT_INDEX, minCreateTime);
List<String> ids = searchCondition.getIds();
BoolQueryBuilder buildQuery;
if (CollectionUtils.isEmpty(ids)) {
buildQuery = esService.buildQuery(searchCondition, subjectIdList);
} else {
buildQuery = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery("id", ids));
}
Map<String, Object> addParams = new HashMap<>();
for (Label markTag : searchCondition.getMarkTags()) {
Map<String, String> addTag = ObjectUtil.objectToMap(markTag);
addParams.put("labels",addTag);
esOpUtil.batchNestedAddScript(indexArr, buildQuery, addParams,"labels","relationId");
}
}
@Override
public void removeTag(InfoDataSearchCondition searchCondition) {
List<String> subjectIdList = new ArrayList<>();
subjectIdList.add(searchCondition.getSubjectId());
String minCreateTime = subjectService.getMinCreateTime(subjectIdList);
String[] indexArr = EsIndexUtil.getIndexIntervalYearStr(Constants.SUBJECT_INDEX, minCreateTime);
List<String> ids = searchCondition.getIds();
BoolQueryBuilder buildQuery;
if (CollectionUtils.isEmpty(ids)) {
buildQuery = esService.buildQuery(searchCondition, subjectIdList);
} else {
buildQuery = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery("id", ids));
}
List<Label> markTags = searchCondition.getMarkTags();
List<String> tagIds = markTags.stream().map(Label::getRelationId).collect(Collectors.toList());
buildQuery.must(QueryBuilders.nestedQuery("labels",
QueryBuilders.termsQuery("labels.relationId", tagIds),
ScoreMode.None));
for (String tagId : tagIds) {
Map<String, Object> deleteParams = new HashMap<>();
deleteParams.put("relationId", tagId);
esOpUtil.batchNestedDeleteScript(indexArr, buildQuery, deleteParams, "labels");
}
}
private void formatLabel(List<LabelModelVo> labelModelVos, DisplayInfo info) {
if (CollectionUtils.isNotEmpty(labelModelVos)) {
List<Label> list = info.getLabels();
......
......@@ -76,7 +76,7 @@ public class InfoDataSearchCondition {
//爬虫类型
private String crawler;
//组合标签查询(不同类标签之间是与的关系,同一类标签之间是或的关系),示例: "a,b;c,d;e,f"
//组合标签查询(不同类标签之间是与的关系,同一类标签之间是或的关系),示例: "a1,a2;c1,c2"
private String composeSearchLabelIds;
/**----企业类标签筛选----**/
......@@ -120,6 +120,12 @@ public class InfoDataSearchCondition {
//最大得分
private Integer maxScore;
//正文长度-研究中心
//最小长度
private Integer minContentLength;
//最大长度
private Integer maxContentLength;
//es查询字段数组
private String[] fetchFields;
//排除字段数组
......@@ -178,6 +184,10 @@ public class InfoDataSearchCondition {
/*-----字符串替换---start-------------------*/
private String replaceWord;
/*------字符串替换---end-------------------*/
/*-----打标签---start-------------------*/
private List<Label> markTags;
/*------打标签---end-------------------*/
/**
* 本次任务使用的流程id
*/
......
......@@ -44,6 +44,8 @@ public class DisplayInfo {
private String summaryRaw;
//关键词
private String keyWords;
//命中词列表
private List<String> keyWordsList;
//标题
private String title;
private String titleRaw;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论