文档库--全文搜索(优先展示正文,正文不匹配则展示拼接内容)

This commit is contained in:
zhn
2022-03-25 21:16:33 +08:00
parent dfb94dae42
commit acc9c296c0
2 changed files with 31 additions and 29 deletions
@@ -1413,7 +1413,6 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
StringBuilder valuesBuilder = new StringBuilder();
StringBuilder sb = new StringBuilder();
List<List<String>> fileTextList = new ArrayList<>();
List<OSSFile> oSSFileAll = new ArrayList<>();
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
@@ -1475,14 +1474,6 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
fieldsBuilder.append(key + ",");
}
}
Map<String,Object> mapFullText = new HashMap<>();
mapFullText.put("id", id);
mapFullText.put("module_type", "文档库");
mapFullText.put("serial_number", map.get("serial_number"));
mapFullText.put("title", map.get("title"));
mapFullText.put("file_text", fileTextList);
mapFullText.put("content", sb.toString());
List<String> fileIdList = oSSFileAll.stream().map(OSSFile::getId).collect(Collectors.toList());
List<OSSFile> fileInfos = iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ","));
List<Map<String,Object>> mapListTemp = new ArrayList<>();
@@ -497,34 +497,45 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
//二次查询
int count = 0;
for (Map.Entry<String, Object> entry : mapSource.entrySet()) {
String key = entry.getKey();
String value = (String) entry.getValue();
//二次搜索的file_text是在一次搜索的基础上
if("file_text".equals(key)){
//判断value中是否包含首次搜索中的字符
boolean flag = judgeContains(value, selectValue);
if(flag){
//截取第一处高亮的前后100个字符
value = getFileText(value, selectValue);
}
}
//判断value中是否包含二次搜索中的字符
boolean flag = judgeContains(value, selectValueTwo);
StringBuilder sb = new StringBuilder();
if (flag) {
//截取第一处高亮的前后100个字符
value = getFileText(value, selectValue);
value = getFileText(value, selectValueTwo);
count++;
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotBlank(value)) {
for (int i = 0; i < value.length(); i++) {
String chStr = String.valueOf(value.charAt(i));
//第一次的搜索条件也需要高亮
String condition = selectValueTwo + selectValue;
if (condition.contains(String.valueOf(chStr))) {
chStr = "<text class='highlight-class'>" + chStr + "</text>";
}
sb.append(String.valueOf(chStr));
}
entry.setValue(sb.toString());
}else{
//第二次搜索的时候file_text中不包含搜索条件的时候将file_text赋值空(此时展示拼接的内容)
if("file_text".equals(entry.getKey())){
entry.setValue("");
}
count++;
//如果内容中不包含第二次搜索条件,则继续高亮第一处
//判断value中是否包含首次搜索中的字符(因为其他的字段有可能包含二次的搜索条件查出来的这条数据,所以还得判断value中是否包含首次搜索中的字符)
boolean flagOne = judgeContains(value, selectValue);
if(flagOne){
//如果包含第一次的搜索条件,先前后截取100字符后再高亮
value = getFileText(value, selectValue);
for (int i = 0; i < value.length(); i++) {
String chStr = String.valueOf(value.charAt(i));
if (selectValueTwo.contains(String.valueOf(chStr))) {
if (selectValue.contains(String.valueOf(chStr))) {
chStr = "<text class='highlight-class'>" + chStr + "</text>";
}
sb.append(String.valueOf(chStr));
}
entry.setValue(sb.toString());
}
entry.setValue(sb.toString());
}
}
if (count > 0) {
@@ -545,15 +556,14 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
//判断value中是否包含搜索中的字符
boolean flag = judgeContains(value, selectValue);
if(flag){
// mapSource.put("file_text_flag","true");
//截取第一处高亮的前后100个字符
value = getFileText(value, selectValue);
}else{
//第一次搜索的时候file_text中不包含搜索条件的时候将file_text赋值空(此时展示拼接的内容)
entry.setValue("");
value = "";
}
}
if("content".equals(key)){
//判断value中是否包含搜索中的字符
boolean flag = judgeContains(value, selectValue);
}
for (int i = 0; i < value.length(); i++) {
String chStr = String.valueOf(value.charAt(i));
if (selectValue.contains(String.valueOf(chStr))) {
@@ -677,6 +687,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|| FieldTypeEnum.TEXT_NUMBER.getValue().equals(e.getFieldShowType()))
.collect(Collectors.toList());
List<String> inputFieldList = inputOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
inputFieldList.add("file_text");//在输入框的类型中添加正文字段
//下拉,树形,日期等字段
List<OnlCgformField> otherOnlCgformFieldList = fieldList.stream()
.filter(e -> FieldTypeEnum.PULL_SINGLE.getValue().equals(e.getFieldShowType())//下拉单选