文档库--首次搜索展示前后100字符

This commit is contained in:
zhn
2022-03-25 23:20:36 +08:00
parent 84ad1f61fc
commit 14d4aa8758
@@ -449,12 +449,8 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
if(!flagTemp){
return new Page(searchVO.getPage(), searchVO.getPageSize());
}
String selectValue = searchVO.getSelectValue();
String selectValueTwo = searchVO.getSelectValueTwo();
//测试数据
// selectValue = "看看";
// selectValueTwo = "喔喔";
//不查询高亮字段
//1. 需要查询的字段
List<String> fieldList = new ArrayList<>();
@@ -465,7 +461,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
fieldList.add("content");
fieldList.add("file_name");
fieldList.add("id");
JSONArray queryMapJson = new JSONArray();
if(StringUtils.isNotBlank(selectValue)){
for (String field : fieldList) {
@@ -611,6 +606,13 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
value = "";
}
}
if("content".equals(key)){
boolean flag = judgeContains(value, selectValue);
if(flag){
//截取第一处高亮的前后100个字符
value = getFileText(value, selectValue);
}
}
for (int i = 0; i < value.length(); i++) {
String chStr = String.valueOf(value.charAt(i));
if (selectValue.contains(String.valueOf(chStr))) {