diff --git a/laws-modules/src/main/java/com/jero/modules/laws/home/service/impl/LawsHomeSearchServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/home/service/impl/LawsHomeSearchServiceImpl.java index daaf83bf..2eb2d275 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/home/service/impl/LawsHomeSearchServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/home/service/impl/LawsHomeSearchServiceImpl.java @@ -116,6 +116,9 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { public static final String YYYY_MM_DD = "yyyy-MM-dd"; public static final String IMPLEMENTATION_DATE = "implementation_date"; + public static final String SPAN_CLASS = ""; + public static final String SPAN = ""; + @Override @@ -140,7 +143,15 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { @NotNull private QueryWrapper getQueryWrapperNormal(LawsHomeNormalSearchDTO lawsHomeNormalSearchDTO) { QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.gt("instr(standard_name,'" + lawsHomeNormalSearchDTO.getSearchContent() + "')", 0); + String[] searchContent = lawsHomeNormalSearchDTO.getSearchContent().split(" "); + queryWrapper.and(s->{ + for (int i = 0; i < searchContent.length; i++) { + s.gt("instr(standard_name,'" + searchContent[i] + "')", 0); + if(i != searchContent.length - 1){ + s.or(); + } + } + }); queryWrapper.eq(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getResourceType()),RESOURCE_TYPE,lawsHomeNormalSearchDTO.getResourceType()); String str = "',','))"; queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardClass()),"instr(concat(',',standard_class,','),concat(',','" + lawsHomeNormalSearchDTO.getStandardClass() + str,0); @@ -162,8 +173,6 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { if(CollectionUtils.isEmpty(pageList.getRecords())) { return; } - - String searchContentSpan = "" + searchContent + ""; List list = pageList.getRecords(); List lawsDomesticStandardIds = new ArrayList<>(); List lawsOverseasStandardIds = new ArrayList<>(); @@ -194,16 +203,16 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { list.parallelStream().forEach(p->{ switch (p.getResourceType()){ case LawsHomeSearchCommon.LAWS_DOMESTIC_STANDARD: - addLawsDomesticStandard(searchContent, searchContentSpan, listLawsDomesticStandard, listLawsTag, p); + addLawsDomesticStandard(searchContent, listLawsDomesticStandard, listLawsTag, p); break; case LawsHomeSearchCommon.LAWS_OVERSEAS_STANDARD: - addLawsOverseasStandard(searchContent, searchContentSpan, listLawsOverseasStandard, listLawsTag, p); + addLawsOverseasStandard(searchContent, listLawsOverseasStandard, listLawsTag, p); break; case LawsHomeSearchCommon.LAWS_ENTERPRISE_STANDARD: - addLawsEnterpriseStandard(searchContent, searchContentSpan, listLawsEnterpriseStandard, listLawsTag, p); + addLawsEnterpriseStandard(searchContent, listLawsEnterpriseStandard, listLawsTag, p); break; default: - addLawsNewsFeed(searchContent, searchContentSpan, listLawsNewsFeed, p); + addLawsNewsFeed(searchContent, listLawsNewsFeed, p); break; } }); @@ -226,12 +235,19 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { return listSysDict; } - private void addLawsNewsFeed(String searchContent, String searchContentSpan, List listLawsNewsFeed, LawsHomeNormalSearchVO p) { + private void addLawsNewsFeed(String searchContent, List listLawsNewsFeed, LawsHomeNormalSearchVO p) { if(!CollectionUtils.isEmpty(listLawsNewsFeed)){ Optional op = listLawsNewsFeed.stream().filter(o-> Objects.equals(o.getId(),p.getId())).findFirst(); if(op.isPresent()){ LawsNewsFeed obj = op.get(); - p.setTitle(obj.getDynamicHeading().replace(searchContent,searchContentSpan)); + String[] text = searchContent.split(" "); + String content = obj.getDynamicHeading(); + for (int i = 0; i < text.length; i++) { + String searchContentSpan = SPAN_CLASS + text[i] + SPAN; + content = content.replace(text[i],searchContentSpan); + + } + p.setTitle(content); p.setReleaseDate(obj.getReleaseTime()); // 生成正文 p.setContent(obj.getDynamicDetails()); @@ -239,12 +255,19 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { } } - private void addLawsEnterpriseStandard(String searchContent, String searchContentSpan, List listLawsEnterpriseStandard, List listLawsTag, LawsHomeNormalSearchVO p) { + private void addLawsEnterpriseStandard(String searchContent, List listLawsEnterpriseStandard, List listLawsTag, LawsHomeNormalSearchVO p) { if(!CollectionUtils.isEmpty(listLawsEnterpriseStandard)){ Optional op = listLawsEnterpriseStandard.stream().filter(o-> Objects.equals(o.getId(),p.getId())).findFirst(); if(op.isPresent()){ LawsEnterpriseStandard obj = op.get(); - p.setTitle((obj.getStandardNumber() + " " + obj.getStandardName()).replace(searchContent,searchContentSpan)); + String[] text = searchContent.split(" "); + String content = obj.getStandardNumber() + " " + obj.getStandardName(); + for (int i = 0; i < text.length; i++) { + String searchContentSpan = SPAN_CLASS + text[i] + SPAN; + content = content.replace(text[i],searchContentSpan); + + } + p.setTitle(content); p.setReleaseDate(obj.getReleaseDate()); // 生成正文 JSONObject json = JSON.parseObject(JSON.toJSONStringWithDateFormat(obj,YYYY_MM_DD)); @@ -253,12 +276,19 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { } } - private void addLawsOverseasStandard(String searchContent, String searchContentSpan, List listLawsOverseasStandard, List listLawsTag, LawsHomeNormalSearchVO p) { + private void addLawsOverseasStandard(String searchContent, List listLawsOverseasStandard, List listLawsTag, LawsHomeNormalSearchVO p) { if(!CollectionUtils.isEmpty(listLawsOverseasStandard)){ Optional op = listLawsOverseasStandard.stream().filter(o-> Objects.equals(o.getId(),p.getId())).findFirst(); if(op.isPresent()){ LawsOverseasStandard obj = op.get(); - p.setTitle((obj.getStandardNumber() + " " + obj.getStandardName()).replace(searchContent,searchContentSpan)); + String[] text = searchContent.split(" "); + String content = obj.getStandardNumber() + " " + obj.getStandardName(); + for (int i = 0; i < text.length; i++) { + String searchContentSpan = SPAN_CLASS + text[i] + SPAN; + content = content.replace(text[i],searchContentSpan); + + } + p.setTitle(content); p.setReleaseDate(obj.getReleaseDate()); // 生成正文 JSONObject json = JSON.parseObject(JSON.toJSONStringWithDateFormat(obj,YYYY_MM_DD)); @@ -267,12 +297,19 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { } } - private void addLawsDomesticStandard(String searchContent, String searchContentSpan, List listLawsDomesticStandard, List listLawsTag, LawsHomeNormalSearchVO p) { + private void addLawsDomesticStandard(String searchContent, List listLawsDomesticStandard, List listLawsTag, LawsHomeNormalSearchVO p) { if(!CollectionUtils.isEmpty(listLawsDomesticStandard)){ Optional op = listLawsDomesticStandard.stream().filter(o-> Objects.equals(o.getId(),p.getId())).findFirst(); if(op.isPresent()){ LawsDomesticStandard obj = op.get(); - p.setTitle((obj.getStandardNumber() + " " + obj.getStandardName()).replace(searchContent,searchContentSpan)); + String[] text = searchContent.split(" "); + String content = obj.getStandardNumber() + " " + obj.getStandardName(); + for (int i = 0; i < text.length; i++) { + String searchContentSpan = SPAN_CLASS + text[i] + SPAN; + content = content.replace(text[i],searchContentSpan); + + } + p.setTitle(content); p.setReleaseDate(obj.getReleaseDate()); // 生成正文 JSONObject json = JSON.parseObject(JSON.toJSONStringWithDateFormat(obj,YYYY_MM_DD)); @@ -420,7 +457,15 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { public LawsHomeNormalSearchStatisticsVO getNormalSearchTitleCount(LawsHomeNormalSearchDTO lawsHomeNormalSearchDTO) { String searchContent = checkSearchContent(lawsHomeNormalSearchDTO); QueryWrapper queryWrapper = new QueryWrapper<>(); - queryWrapper.gt("instr(concat_ws(' ',standard_number,standard_name),'" + searchContent + "')", 0); + String[] text = searchContent.split(" "); + queryWrapper.and(s->{ + for (int i = 0; i < text.length; i++) { + s.gt("instr(concat_ws(' ',standard_number,standard_name),'" + text[i] + "')", 0); + if(i != text.length - 1){ + s.or(); + } + } + }); queryWrapper.eq("del_flag",0); String str = "',','))"; queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardClass()),"instr(concat(',',standard_class,','),concat(',','" + lawsHomeNormalSearchDTO.getStandardClass() + str,0); @@ -741,9 +786,9 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService { private void highlight(Map mapHighlight, String key) { Map mapTemp = new HashMap<>(); List list = new ArrayList<>(); - list.add(""); + list.add(SPAN_CLASS); List list1 = new ArrayList<>(); - list1.add(""); + list1.add(SPAN); mapTemp.put("pre_tags", list); mapTemp.put("post_tags", list1); //高亮字段内容长度,去除html样式标签,统计字数,设置为200