标题检索变更

This commit is contained in:
梁琦涛
2023-12-04 19:47:17 +08:00
parent 0bff140b40
commit f9bcb2b6d5
@@ -119,6 +119,8 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
public static final String SPAN_CLASS = "<span class='highlight-Es-class'>";
public static final String SPAN = "</span>";
public static final String BLANK_SPACE = "\\s+";
@Override
@@ -143,7 +145,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
@NotNull
private QueryWrapper<LawsHomeNormalSearchDTO> getQueryWrapperNormal(LawsHomeNormalSearchDTO lawsHomeNormalSearchDTO) {
QueryWrapper<LawsHomeNormalSearchDTO> queryWrapper = new QueryWrapper<>();
String[] searchContent = lawsHomeNormalSearchDTO.getSearchContent().split(" ");
String[] searchContent = lawsHomeNormalSearchDTO.getSearchContent().split(BLANK_SPACE);
queryWrapper.and(s->{
for (int i = 0; i < searchContent.length; i++) {
s.gt("instr(standard_name,'" + searchContent[i] + "')", 0);
@@ -163,19 +165,13 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getGradeClassification()),"instr(concat(',',grade_classification,','),concat(',','" + lawsHomeNormalSearchDTO.getGradeClassification() + str,0);
StringBuilder order = new StringBuilder();
for (int i = 0; i < searchContent.length; i++) {
if(i == 0){
order.append("(");
}
order.append("length(REPLACE(standard_name,'").append(searchContent[i]).append("',''))");
order.append("(length(standard_name) - length(REPLACE(standard_name,'").append(searchContent[i]).append("','')))");
if(i != searchContent.length - 1){
order.append(" + ");
}
if(i == searchContent.length - 1){
order.append(")");
}
}
queryWrapper.orderByAsc(order + "/length(standard_name)");
queryWrapper.orderByDesc(order.toString());
queryWrapper.orderByAsc("standard_type_order");
queryWrapper.orderByAsc("standard_state_order");
queryWrapper.orderByDesc(IMPLEMENTATION_DATE);
@@ -254,7 +250,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
Optional<LawsNewsFeed> op = listLawsNewsFeed.stream().filter(o-> Objects.equals(o.getId(),p.getId())).findFirst();
if(op.isPresent()){
LawsNewsFeed obj = op.get();
String[] text = searchContent.split(" ");
String[] text = searchContent.split(BLANK_SPACE);
String content = obj.getDynamicHeading();
for (int i = 0; i < text.length; i++) {
String searchContentSpan = SPAN_CLASS + text[i] + SPAN;
@@ -274,13 +270,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
Optional<LawsEnterpriseStandard> op = listLawsEnterpriseStandard.stream().filter(o-> Objects.equals(o.getId(),p.getId())).findFirst();
if(op.isPresent()){
LawsEnterpriseStandard obj = op.get();
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);
}
String content = getString(searchContent, obj.getStandardNumber(), obj.getStandardName());
p.setTitle(content);
p.setReleaseDate(obj.getReleaseDate());
// 生成正文
@@ -290,18 +280,24 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
}
}
@NotNull
private String getString(String searchContent, String standardNumber, String standardName) {
String[] text = searchContent.split(BLANK_SPACE);
String content = standardNumber + " " + standardName;
for (int i = 0; i < text.length; i++) {
String searchContentSpan = SPAN_CLASS + text[i] + SPAN;
content = content.replace(text[i], searchContentSpan);
}
return content;
}
private void addLawsOverseasStandard(String searchContent, List<LawsOverseasStandard> listLawsOverseasStandard, List<LawsTag> listLawsTag, LawsHomeNormalSearchVO p) {
if(!CollectionUtils.isEmpty(listLawsOverseasStandard)){
Optional<LawsOverseasStandard> op = listLawsOverseasStandard.stream().filter(o-> Objects.equals(o.getId(),p.getId())).findFirst();
if(op.isPresent()){
LawsOverseasStandard obj = op.get();
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);
}
String content = getString(searchContent, obj.getStandardNumber(), obj.getStandardName());
p.setTitle(content);
p.setReleaseDate(obj.getReleaseDate());
// 生成正文
@@ -316,13 +312,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
Optional<LawsDomesticStandard> op = listLawsDomesticStandard.stream().filter(o-> Objects.equals(o.getId(),p.getId())).findFirst();
if(op.isPresent()){
LawsDomesticStandard obj = op.get();
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);
}
String content = getString(searchContent, obj.getStandardNumber(), obj.getStandardName());
p.setTitle(content);
p.setReleaseDate(obj.getReleaseDate());
// 生成正文
@@ -471,7 +461,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
public LawsHomeNormalSearchStatisticsVO getNormalSearchTitleCount(LawsHomeNormalSearchDTO lawsHomeNormalSearchDTO) {
String searchContent = checkSearchContent(lawsHomeNormalSearchDTO);
QueryWrapper<LawsHomeNormalSearchDTO> queryWrapper = new QueryWrapper<>();
String[] text = searchContent.split(" ");
String[] text = searchContent.split(BLANK_SPACE);
queryWrapper.and(s->{
for (int i = 0; i < text.length; i++) {
s.gt("instr(concat_ws(' ',standard_number,standard_name),'" + text[i] + "')", 0);