文档库--搜索

This commit is contained in:
zhn
2022-03-22 11:53:03 +08:00
parent 4ad5c53f06
commit 7b12ed59fe
@@ -240,8 +240,8 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
//// Map<String, Object> map2 = new HashMap<>();
//// map2.put("content",selectValue);
// Map<String,Object> map3 = new HashMap<>();
// map3.put("pre_tags","<span class='highlight-class'>");
// map3.put("post_tags","</span>");
// map3.put("pre_tags","<text class='highlight-class'>");
// map3.put("post_tags","</text>");
// for (String s : listTemp) {
// Map<String, Object> map4 = new HashMap<>();
// Map<String, Object> queryMap = new HashMap<>();
@@ -269,8 +269,8 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
// //封装高亮查询条件
// Map<String, Object> map1 = new HashMap<>();
// Map<String,Object> map3 = new HashMap<>();
// map3.put("pre_tags","<span class='highlight-class'>");
// map3.put("post_tags","</span>");
// map3.put("pre_tags","<text class='highlight-class'>");
// map3.put("post_tags","</text>");
// map1.put("content", map3);
// highlightMap.put("fields", map1);
//
@@ -368,7 +368,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
for (int i = 0; i < value.length(); i++) {
String chStr = String.valueOf(value.charAt(i));
if (selectValueTwo.contains(String.valueOf(chStr))) {
chStr = "<span class='highlight-class'>" + chStr + "</span>";
chStr = "<text class='highlight-class'>" + chStr + "</text>";
}
sb.append(String.valueOf(chStr));
}
@@ -380,7 +380,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
mapListTwo.add(mapSource);
}
} else {
//首次查询
//首次查询(没有输入查询条件)
mapList.add(mapSource);
//目前只能处理单字段高亮(多字段高亮问题解决后可以用此方法)
@@ -395,34 +395,35 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
// }
// }
//-----------------------------------------------------------------------------
//处理高亮module_type,title,serial_number,file_text
for (Map.Entry<String, Object> entry : mapSource.entrySet()) {
String key = entry.getKey();
String value = null;
try {
//文件内容为字符串格式
value = (String) entry.getValue();
} catch (Exception e) {
//文件内容为集合格式
listNew.add(stringObjectMap);
e.printStackTrace();
}
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotBlank(value)) {
for (int i = 0; i < value.length(); i++) {
String chStr = String.valueOf(value.charAt(i));
if (selectValue.contains(String.valueOf(chStr))) {
chStr = "<span class='highlight-class'>" + chStr + "</span>";
int c = 0;
//处理高亮module_type,title,serial_number,file_text(输入查询条件后,处理高亮字段)
if(StringUtils.isNotBlank(selectValue)){
for (Map.Entry<String, Object> entry : mapSource.entrySet()) {
String key = entry.getKey();
String value = null;
try {
//文件内容为字符串格式
value = (String) entry.getValue();
} catch (Exception e) {
//文件内容为集合格式
listNew.add(stringObjectMap);
e.printStackTrace();
}
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotBlank(value)) {
for (int i = 0; i < value.length(); i++) {
String chStr = String.valueOf(value.charAt(i));
if (selectValue.contains(String.valueOf(chStr))) {
chStr = "<text class='highlight-class'>" + chStr + "</text>";
}
sb.append(String.valueOf(chStr));
}
sb.append(String.valueOf(chStr));
}
if(ObjectUtils.isNotEmpty(sb)){
entry.setValue(sb.toString());
}
}
if(ObjectUtils.isNotEmpty(sb)){
entry.setValue(sb.toString());
}
}
}
}
@@ -432,14 +433,14 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
List<Map<String, Object>> result = new ArrayList<>();
List<String> idList = new ArrayList<>();
for (Map<String, Object> map : listNew) {
idList.add((String) map.get("_id"));
// idList.add((String) map.get("_id"));
Map<String, Object> mapSource = (Map<String, Object>) map.get("_source");
String moduleType = (String) mapSource.get("module_type");
String serialNumber = (String) mapSource.get("serial_number");
String title = (String) mapSource.get("title");
String content = (String) mapSource.get("content");
String id = (String) mapSource.get("id");
int count = 0;
// int count = 0;
if(StringUtils.isNotBlank(selectValueTwo)){
//二次查询
for (Map.Entry<String, Object> entry : mapSource.entrySet()) {
@@ -447,6 +448,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
if("file_text".equals(key)){
for (List<String> valueList : (List<List<String>>) entry.getValue()) {
for (String s : valueList) {
int count = 0;
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotBlank(s)) {
//判断value中是否包含二次搜索中的字符
@@ -455,7 +457,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
for (int i = 0; i < s.length(); i++) {
String chStr = String.valueOf(s.charAt(i));
if (selectValue.contains(String.valueOf(chStr))) {
chStr = "<span class='highlight-class'>" + chStr + "</span>";
chStr = "<text class='highlight-class'>" + chStr + "</text>";
count ++;
}
sb.append(String.valueOf(chStr));
@@ -471,6 +473,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
mapTemp.put("content",content);
mapTemp.put("file_text",sb.toString());
result.add(mapTemp);
idList.add(id);
}
}
}
@@ -483,12 +486,13 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
if("file_text".equals(key)){
for (List<String> valueList : (List<List<String>>) entry.getValue()) {
for (String s : valueList) {
int count = 0;
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotBlank(s)) {
for (int i = 0; i < s.length(); i++) {
String chStr = String.valueOf(s.charAt(i));
if (selectValue.contains(String.valueOf(chStr))) {
chStr = "<span class='highlight-class'>" + chStr + "</span>";
chStr = "<text class='highlight-class'>" + chStr + "</text>";
count ++;
}
sb.append(String.valueOf(chStr));
@@ -503,6 +507,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
mapTemp.put("content",content);
mapTemp.put("file_text",sb.toString());
result.add(mapTemp);
idList.add(id);
}
}
}