文档库--搜索中心中英文切换

This commit is contained in:
zhn
2022-03-31 18:03:16 +08:00
parent b64b8aff1f
commit 8ef42c8be4
4 changed files with 250 additions and 149 deletions
@@ -8,7 +8,9 @@ package com.jero.modules.document.enums;
public enum SearchEnum { public enum SearchEnum {
INDEX_NAME_DOCUMENT("文档库索引名称","documentLibrary"), INDEX_NAME_DOCUMENT("文档库索引名称","documentLibrary"),
TYPE_NAME_DOCUMENT("文档库类型","document"), TYPE_NAME_DOCUMENT("文档库类型","document"),
FULL_TEXT_SEARCH("全部","fulltextsearch"); FULL_TEXT_SEARCH("全部中文","fulltextsearchcn"),
FULL_TEXT_SEARCH_CN("全部中文","fulltextsearchcn"),
FULL_TEXT_SEARCH_EN("全部英文","fulltextsearchen");
@@ -220,9 +220,17 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
try { try {
for (String id : ids) { for (String id : ids) {
jeroElasticsearchTemplate.delete(SearchEnum.INDEX_NAME_DOCUMENT.getValue(), SearchEnum.TYPE_NAME_DOCUMENT.getValue(), id); jeroElasticsearchTemplate.delete(SearchEnum.INDEX_NAME_DOCUMENT.getValue(), SearchEnum.TYPE_NAME_DOCUMENT.getValue(), id);
//删除全部中文的
jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), id); jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), id);
jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), id);
//删除全部英文的
jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), id);
for (String fileId : fileIdList) { for (String fileId : fileIdList) {
//删除全部中文的
jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), id + fileId); jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), id + fileId);
jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), id + fileId);
//删除全部英文的
jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), id + fileId);
} }
} }
@@ -1111,15 +1119,18 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
StringBuilder fieldsBuilder = new StringBuilder(); StringBuilder fieldsBuilder = new StringBuilder();
//数据值 //数据值
StringBuilder valuesBuilder = new StringBuilder(); StringBuilder valuesBuilder = new StringBuilder();
StringBuilder sb = new StringBuilder(); //sbCn sbEn 这两个字段作为es中英文切换
StringBuilder sbCn = new StringBuilder();
StringBuilder sbEn = new StringBuilder();
List<List<String>> fileTextList = new ArrayList<>(); List<List<String>> fileTextList = new ArrayList<>();
List<OSSFile> oSSFileAll = new ArrayList<>(); List<OSSFile> oSSFileAll = new ArrayList<>();
try { try {
for (Map.Entry<String, Object> entry : map.entrySet()) { for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
//es全文新增数据(数据转换) //es全文新增数据(数据转换)
esFullText(cut, fieldList, categoryList, dictItemList, mapList, sb, entry); esFullText(cut, fieldList, categoryList, dictItemList, mapList, sbCn,sbEn, entry);
//处理日期格式 //处理日期格式
if (fieldDateList.contains(key)) { if (fieldDateList.contains(key)) {
@@ -1170,11 +1181,13 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
//多文件es iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ",")); //多文件es iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ","));
List<String> fileIdList = oSSFileAll.stream().map(OSSFile::getId).collect(Collectors.toList()); List<String> fileIdList = oSSFileAll.stream().map(OSSFile::getId).collect(Collectors.toList());
List<OSSFile> fileInfos = iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ",")); List<OSSFile> fileInfos = iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ","));
List<Map<String, Object>> mapListTemp = new ArrayList<>(); List<Map<String, Object>> mapListTempCn = new ArrayList<>();
List<Map<String, Object>> mapListTempEn = new ArrayList<>();
try { try {
if (fileInfos.size() != 0) { if (fileInfos.size() != 0) {
for (OSSFile ossFile : fileInfos) { for (OSSFile ossFile : fileInfos) {
Map<String, Object> stringMap = new HashMap<>(); Map<String, Object> stringMapCn = new HashMap<>();
Map<String, Object> stringMapEn = new HashMap<>();
String fileText = ""; String fileText = "";
if (ossFile.getFileName().endsWith(".doc") if (ossFile.getFileName().endsWith(".doc")
|| ossFile.getFileName().endsWith(".docx") || ossFile.getFileName().endsWith(".docx")
@@ -1207,38 +1220,73 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
// s = ""; // s = "";
// } // }
if(StringUtils.isNotBlank(s)){ if(StringUtils.isNotBlank(s)){
stringMap.put(onlCgformField.getDbFieldName(), s); stringMapCn.put(onlCgformField.getDbFieldName(), s);
stringMapEn.put(onlCgformField.getDbFieldName(), s);
} }
} }
String cutCn = CutEnum.CN.getValue();
String cutEn = CutEnum.EN.getValue();
//封装中文的全文内容(es)
putMapCn(idTemp + ossFile.getId(),
(String) map.get("serial_number"),
"文档库",
sbCn.toString(),
(String) map.get("title"),
fileText,
ossFile.getFileName(),
cutCn,
stringMapCn);
//封装英文的全文内容(es)
putMapCn(idTemp + ossFile.getId(),
(String) map.get("serial_number"),
"document library",
sbEn.toString(),
(String) map.get("title"),
fileText,
ossFile.getFileName(),
cutEn,
stringMapEn);
stringMap.put("id", idTemp + ossFile.getId()); mapListTempCn.add(stringMapCn);
stringMap.put("module_type", "文档库"); mapListTempEn.add(stringMapEn);
stringMap.put("serial_number", map.get("serial_number"));
stringMap.put("title", map.get("title"));
stringMap.put("content", sb.toString());
stringMap.put("file_text", fileText);
stringMap.put("file_name", ossFile.getFileName());
mapListTemp.add(stringMap);
} }
} else { } else {
Map<String, Object> stringMap = new HashMap<>(); Map<String, Object> stringMapCn = new HashMap<>();
Map<String, Object> stringMapEn = new HashMap<>();
for (OnlCgformField onlCgformField : searchFieldList) { for (OnlCgformField onlCgformField : searchFieldList) {
String s = (String) map.get(onlCgformField.getDbFieldName()); String s = (String) map.get(onlCgformField.getDbFieldName());
// if (StringUtils.isBlank(s)) { // if (StringUtils.isBlank(s)) {
// s = ""; // s = "";
// } // }
if(StringUtils.isNotBlank(s)){ if(StringUtils.isNotBlank(s)){
stringMap.put(onlCgformField.getDbFieldName(), s); stringMapCn.put(onlCgformField.getDbFieldName(), s);
stringMapEn.put(onlCgformField.getDbFieldName(), s);
} }
} }
stringMap.put("id", idTemp); String cutCn = CutEnum.CN.getValue();
stringMap.put("module_type", "文档库"); String cutEn = CutEnum.EN.getValue();
stringMap.put("serial_number", map.get("serial_number")); //封装中文的全文内容(es)
stringMap.put("title", map.get("title")); putMapCn(idTemp,
stringMap.put("content", sb.toString()); (String) map.get("serial_number"),
stringMap.put("file_text", ""); "文档库",
stringMap.put("file_name", ""); sbCn.toString(),
mapListTemp.add(stringMap); (String) map.get("title"),
"",
"",
cutCn,
stringMapCn);
//封装英文的全文内容(es)
putMapCn(idTemp,
(String) map.get("serial_number"),
"document library",
sbEn.toString(),
(String) map.get("title"),
"",
"",
cutEn,
stringMapEn);
mapListTempCn.add(stringMapCn);
mapListTempEn.add(stringMapEn);
} }
@@ -1262,13 +1310,13 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
map.put("id", idTemp); map.put("id", idTemp);
map.put("module_type", "文档库"); map.put("module_type", "文档库");
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(map)); JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(map));
// JSONObject jsonObjectAll = JSON.parseObject(JSON.toJSONString(mapFullText)); JSONArray arrayCn = JSONArray.parseArray(JSON.toJSONString(mapListTempCn));
JSONArray array = JSONArray.parseArray(JSON.toJSONString(mapListTemp)); JSONArray arrayEn = JSONArray.parseArray(JSON.toJSONString(mapListTempEn));
try { try {
jeroElasticsearchTemplate.saveOrUpdate(SearchEnum.INDEX_NAME_DOCUMENT.getValue(), SearchEnum.TYPE_NAME_DOCUMENT.getValue(), idTemp, jsonObject); jeroElasticsearchTemplate.saveOrUpdate(SearchEnum.INDEX_NAME_DOCUMENT.getValue(), SearchEnum.TYPE_NAME_DOCUMENT.getValue(), idTemp, jsonObject);
//全部 //全部
jeroElasticsearchTemplate.saveBatch(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), array); jeroElasticsearchTemplate.saveBatch(SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), arrayCn);
jeroElasticsearchTemplate.saveBatch(SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), arrayEn);
} catch (Exception e) { } catch (Exception e) {
log.error("文档库添加es失败"); log.error("文档库添加es失败");
} }
@@ -1313,18 +1361,27 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
return result; return result;
} }
private void esFullText(String cut, List<OnlCgformField> fieldList, List<SysCategory> categoryList, List<SysDictItem> dictItemList, List<Map<String, Object>> mapList, StringBuilder sb, Map.Entry<String, Object> entry) { private void esFullText(String cut, List<OnlCgformField> fieldList,
List<SysCategory> categoryList,
List<SysDictItem> dictItemList,
List<Map<String, Object>> mapList,
StringBuilder sbCn, StringBuilder sbEn,
Map.Entry<String, Object> entry) {
try { try {
List<OnlCgformField> onlCgformFieldList = fieldList.stream().filter(e -> entry.getKey().equals(e.getDbFieldName())).collect(Collectors.toList()); List<OnlCgformField> onlCgformFieldList = fieldList.stream().filter(e -> entry.getKey().equals(e.getDbFieldName())).collect(Collectors.toList());
for (OnlCgformField onlCgformField : fieldList) { for (OnlCgformField onlCgformField : fieldList) {
String fieldNameCn = onlCgformField.getDbFieldTxt();
String fieldNameEn = onlCgformField.getDbFieldEnName();
//输入框 //输入框
if ((FieldTypeEnum.TEXT_STRING.getValue().equals(onlCgformField.getFieldShowType()) if ((FieldTypeEnum.TEXT_STRING.getValue().equals(onlCgformField.getFieldShowType())
|| FieldTypeEnum.TEXT_NUMBER.getValue().equals(onlCgformField.getFieldShowType())) || FieldTypeEnum.TEXT_NUMBER.getValue().equals(onlCgformField.getFieldShowType()))
&& onlCgformField.getDbFieldName().equals(entry.getKey())) { && onlCgformField.getDbFieldName().equals(entry.getKey())) {
if (ObjectUtils.isEmpty(entry.getValue())) { if (ObjectUtils.isEmpty(entry.getValue())) {
sb.append(onlCgformField.getDbFieldTxt() + ":" + "-- "); sbCn.append(fieldNameCn + ":" + "-- ");
sbEn.append(fieldNameEn + ":" + "-- ");
} else { } else {
sb.append(onlCgformField.getDbFieldTxt() + ":" + entry.getValue() + " "); sbCn.append(fieldNameCn + ":" + entry.getValue() + " ");
sbEn.append(fieldNameEn + ":" + entry.getValue() + " ");
} }
} }
//下拉框 //下拉框
@@ -1332,25 +1389,32 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
|| FieldTypeEnum.PULL_MORE.getValue().equals(onlCgformField.getFieldShowType())) || FieldTypeEnum.PULL_MORE.getValue().equals(onlCgformField.getFieldShowType()))
&& onlCgformField.getDbFieldName().equals(entry.getKey())) { && onlCgformField.getDbFieldName().equals(entry.getKey())) {
if (ObjectUtils.isEmpty(entry.getValue())) { if (ObjectUtils.isEmpty(entry.getValue())) {
sb.append(onlCgformField.getDbFieldTxt() + ":" + "-- "); sbCn.append(fieldNameCn + ":" + "-- ");
sbEn.append(fieldNameEn + ":" + "-- ");
} else { } else {
if (onlCgformFieldList.size() != 0 && StringUtils.isNotBlank(onlCgformFieldList.get(0).getDictField())) { if (onlCgformFieldList.size() != 0 && StringUtils.isNotBlank(onlCgformFieldList.get(0).getDictField())) {
List<SysDictItem> dictItems = dictItemList.stream() List<SysDictItem> dictItems = dictItemList.stream()
.filter(e -> StringUtils.isNotBlank(e.getDictCode()) && e.getDictCode().equals(onlCgformFieldList.get(0).getDictField())) .filter(e -> StringUtils.isNotBlank(e.getDictCode()) && e.getDictCode().equals(onlCgformFieldList.get(0).getDictField()))
.collect(Collectors.toList()); .collect(Collectors.toList());
StringBuilder sbText = new StringBuilder(); StringBuilder sbTextCn = new StringBuilder();
StringBuilder sbTextEn = new StringBuilder();
//处理数据字典 //处理数据字典
for (String item : entry.getValue().toString().split(",")) { for (String item : entry.getValue().toString().split(",")) {
if (dictItems.size() != 0) { if (dictItems.size() != 0) {
List<SysDictItem> itemValue = dictItems.stream().filter(e -> item.equals(e.getItemValue())).collect(Collectors.toList()); List<SysDictItem> itemValue = dictItems.stream().filter(e -> item.equals(e.getItemValue())).collect(Collectors.toList());
if (itemValue.size() != 0) { if (itemValue.size() != 0) {
sbText.append(itemValue.get(0).getItemText() + ","); sbTextCn.append(itemValue.get(0).getItemText() + ",");
sbTextEn.append(itemValue.get(0).getEnName() + ",");
} }
} }
} }
if (StringUtils.isNotBlank(sbText)) { if (StringUtils.isNotBlank(sbTextCn)) {
String substring = sbText.substring(0, sbText.length() - 1); String substring = sbTextCn.substring(0, sbTextCn.length() - 1);
sb.append(onlCgformField.getDbFieldTxt() + ":" + substring + " "); sbCn.append(fieldNameCn + ":" + substring + " ");
}
if (StringUtils.isNotBlank(sbTextEn)) {
String substring = sbTextEn.substring(0, sbTextEn.length() - 1);
sbEn.append(fieldNameEn + ":" + substring + " ");
} }
} }
} }
@@ -1359,19 +1423,19 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
if (FieldTypeEnum.TREE.getValue().equals(onlCgformField.getFieldShowType()) if (FieldTypeEnum.TREE.getValue().equals(onlCgformField.getFieldShowType())
&& onlCgformField.getDbFieldName().equals(entry.getKey())) { && onlCgformField.getDbFieldName().equals(entry.getKey())) {
if (ObjectUtils.isEmpty(entry.getValue())) { if (ObjectUtils.isEmpty(entry.getValue())) {
sb.append(onlCgformField.getDbFieldTxt() + ":" + "-- "); sbCn.append(fieldNameCn + ":" + "-- ");
sbEn.append(fieldNameEn + ":" + "-- ");
} else { } else {
StringBuilder sbTree = new StringBuilder(); StringBuilder sbTreeCn = new StringBuilder();
StringBuilder sbTreeEn = new StringBuilder();
List<String> idList = Arrays.asList(entry.getValue().toString().split(",")); List<String> idList = Arrays.asList(entry.getValue().toString().split(","));
List<SysCategory> sysCategoryList = categoryList.stream().filter(e -> idList.contains(e.getId())).collect(Collectors.toList()); List<SysCategory> sysCategoryList = categoryList.stream().filter(e -> idList.contains(e.getId())).collect(Collectors.toList());
List<String> nameList = sysCategoryList.stream().map(SysCategory::getName).collect(Collectors.toList()); List<String> nameList = sysCategoryList.stream().map(SysCategory::getName).collect(Collectors.toList());
List<String> nameEnList = sysCategoryList.stream().map(SysCategory::getEnName).collect(Collectors.toList()); List<String> nameEnList = sysCategoryList.stream().map(SysCategory::getEnName).collect(Collectors.toList());
if (CutEnum.CN.getValue().equals(cut)) { sbTreeCn.append(StringUtils.join(nameList, ","));
sbTree.append(StringUtils.join(nameList, ",")); sbTreeEn.append(StringUtils.join(nameEnList, ","));
} else { sbCn.append(fieldNameCn + ":" + sbTreeCn.toString() + " ");
sbTree.append(StringUtils.join(nameEnList, ",")); sbEn.append(fieldNameEn + ":" + sbTreeEn.toString() + " ");
}
sb.append(onlCgformField.getDbFieldTxt() + ":" + sbTree.toString() + " ");
} }
} }
@@ -1379,16 +1443,19 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
if (FieldTypeEnum.DATE_SINGLE.getValue().equals(onlCgformField.getFieldShowType()) if (FieldTypeEnum.DATE_SINGLE.getValue().equals(onlCgformField.getFieldShowType())
&& onlCgformField.getDbFieldName().equals(entry.getKey())) { && onlCgformField.getDbFieldName().equals(entry.getKey())) {
if (ObjectUtils.isEmpty(entry.getValue())) { if (ObjectUtils.isEmpty(entry.getValue())) {
sb.append(onlCgformField.getDbFieldTxt() + ":" + "-- "); sbCn.append(fieldNameCn + ":" + "-- ");
sbEn.append(fieldNameEn + ":" + "-- ");
} else { } else {
sb.append(onlCgformField.getDbFieldTxt() + ":" + entry.getValue().toString().split(" ")[0] + " "); sbCn.append(fieldNameCn + ":" + entry.getValue().toString().split(" ")[0] + " ");
sbEn.append(fieldNameEn + ":" + entry.getValue().toString().split(" ")[0] + " ");
} }
} }
//标准选择 //标准选择
if (FieldTypeEnum.STANDARD.getValue().equals(onlCgformField.getFieldShowType()) if (FieldTypeEnum.STANDARD.getValue().equals(onlCgformField.getFieldShowType())
&& onlCgformField.getDbFieldName().equals(entry.getKey())) { && onlCgformField.getDbFieldName().equals(entry.getKey())) {
if (ObjectUtils.isEmpty(entry.getValue())) { if (ObjectUtils.isEmpty(entry.getValue())) {
sb.append(onlCgformField.getDbFieldTxt() + ":" + "-- "); sbCn.append(fieldNameCn + ":" + "-- ");
sbEn.append(fieldNameEn + ":" + "-- ");
} else { } else {
StringBuilder standSb = new StringBuilder(); StringBuilder standSb = new StringBuilder();
if ("replaced_standard".equals(entry.getKey())) { if ("replaced_standard".equals(entry.getKey())) {
@@ -1418,7 +1485,8 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
if (StringUtils.isNotBlank(standSb)) { if (StringUtils.isNotBlank(standSb)) {
String substring = standSb.substring(0, standSb.length() - 1); String substring = standSb.substring(0, standSb.length() - 1);
sb.append(onlCgformField.getDbFieldTxt() + ":" + substring + " "); sbCn.append(fieldNameCn + ":" + substring + " ");
sbEn.append(fieldNameEn + ":" + substring + " ");
} }
} }
} }
@@ -1427,11 +1495,13 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
if (FieldTypeEnum.FILE.getValue().equals(onlCgformField.getFieldShowType()) if (FieldTypeEnum.FILE.getValue().equals(onlCgformField.getFieldShowType())
&& onlCgformField.getDbFieldName().equals(entry.getKey())) { && onlCgformField.getDbFieldName().equals(entry.getKey())) {
if (ObjectUtils.isEmpty(entry.getValue())) { if (ObjectUtils.isEmpty(entry.getValue())) {
sb.append(onlCgformField.getDbFieldTxt() + ":" + "-- "); sbCn.append(fieldNameCn + ":" + "-- ");
sbEn.append(fieldNameEn + ":" + "-- ");
} else { } else {
List<OSSFile> fileInfos = iOSSFileService.getFileInfos((String) entry.getValue()); List<OSSFile> fileInfos = iOSSFileService.getFileInfos((String) entry.getValue());
List<String> fileNameList = fileInfos.stream().map(OSSFile::getFileName).collect(Collectors.toList()); List<String> fileNameList = fileInfos.stream().map(OSSFile::getFileName).collect(Collectors.toList());
sb.append(onlCgformField.getDbFieldTxt() + ":" + StringUtils.join(fileNameList, ",") + " "); sbCn.append(fieldNameCn + ":" + StringUtils.join(fileNameList, ",") + " ");
sbEn.append(fieldNameEn + ":" + StringUtils.join(fileNameList, ",") + " ");
} }
} }
} }
@@ -1548,7 +1618,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
StringBuilder fieldsBuilder = new StringBuilder(); StringBuilder fieldsBuilder = new StringBuilder();
//数据值 //数据值
StringBuilder valuesBuilder = new StringBuilder(); StringBuilder valuesBuilder = new StringBuilder();
StringBuilder sb = new StringBuilder();
//调整map中字段的顺序和新增表单中字段顺序一致 //调整map中字段的顺序和新增表单中字段顺序一致
Map<String, Object> mapNew = new LinkedHashMap<>(); Map<String, Object> mapNew = new LinkedHashMap<>();
@@ -1568,11 +1638,13 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
} }
} }
List<OSSFile> oSSFileAll = new ArrayList<>(); List<OSSFile> oSSFileAll = new ArrayList<>();
StringBuilder sbCn = new StringBuilder();
StringBuilder sbEn = new StringBuilder();
for (Map.Entry<String, Object> entry : mapNew.entrySet()) { for (Map.Entry<String, Object> entry : mapNew.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
//es全文新增数据(数据转换) //es全文新增数据(数据转换)
esFullText(cut, fieldList, categoryList, dictItemList, listMap, sb, entry); esFullText(cut, fieldList, categoryList, dictItemList, listMap, sbCn,sbEn, entry);
if (ObjectUtils.isNotEmpty(value)) { if (ObjectUtils.isNotEmpty(value)) {
//处理修改人和修改时间 //处理修改人和修改时间
@@ -1630,11 +1702,13 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
} }
List<String> fileIdList = oSSFileAll.stream().map(OSSFile::getId).collect(Collectors.toList()); List<String> fileIdList = oSSFileAll.stream().map(OSSFile::getId).collect(Collectors.toList());
List<OSSFile> fileInfos = iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ",")); List<OSSFile> fileInfos = iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ","));
List<Map<String, Object>> mapListTemp = new ArrayList<>(); List<Map<String, Object>> mapListTempCn = new ArrayList<>();
List<Map<String, Object>> mapListTempEn = new ArrayList<>();
try { try {
if (fileInfos.size() != 0) { if (fileInfos.size() != 0) {
for (OSSFile ossFile : fileInfos) { for (OSSFile ossFile : fileInfos) {
Map<String, Object> stringMap = new HashMap<>(); Map<String, Object> stringMapCn = new HashMap<>();
Map<String, Object> stringMapEn = new HashMap<>();
String fileText = ""; String fileText = "";
if (ossFile.getFileName().endsWith(".doc") if (ossFile.getFileName().endsWith(".doc")
|| ossFile.getFileName().endsWith(".docx") || ossFile.getFileName().endsWith(".docx")
@@ -1669,21 +1743,40 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
// s = ""; // s = "";
// } // }
if(StringUtils.isNotBlank(s)){ if(StringUtils.isNotBlank(s)){
stringMap.put(onlCgformField.getDbFieldName(), s); stringMapCn.put(onlCgformField.getDbFieldName(), s);
stringMapEn.put(onlCgformField.getDbFieldName(), s);
} }
} }
String cutCn = CutEnum.CN.getValue();
String cutEn = CutEnum.EN.getValue();
stringMap.put("id", (String) map.get("id") + ossFile.getId()); //封装中文的全文内容(es)
stringMap.put("module_type", "文档库"); putMapCn((String) map.get("id") + ossFile.getId(),
stringMap.put("serial_number", map.get("serial_number")); (String) map.get("serial_number"),
stringMap.put("title", map.get("title")); "文档库",
stringMap.put("content", sb.toString()); sbCn.toString(),
stringMap.put("file_text", fileText); (String) map.get("title"),
stringMap.put("file_name", ossFile.getFileName()); fileText,
mapListTemp.add(stringMap); ossFile.getFileName(),
cutCn,
stringMapCn);
//封装英文的全文内容(es)
putMapCn((String) map.get("id") + ossFile.getId(),
(String) map.get("serial_number"),
"document library",
sbEn.toString(),
(String) map.get("title"),
fileText,
ossFile.getFileName(),
cutEn,
stringMapEn);
mapListTempCn.add(stringMapCn);
mapListTempEn.add(stringMapEn);
} }
} else { } else {
Map<String, Object> stringMap = new HashMap<>(); Map<String, Object> stringMapCn = new HashMap<>();
Map<String, Object> stringMapEn = new HashMap<>();
for (OnlCgformField onlCgformField : searchFieldList) { for (OnlCgformField onlCgformField : searchFieldList) {
String s = (String) map.get(onlCgformField.getDbFieldName()); String s = (String) map.get(onlCgformField.getDbFieldName());
if(FieldTypeEnum.DATE_SINGLE.getValue().equals(onlCgformField.getFieldShowType()) && StringUtils.isNotBlank(s)){ if(FieldTypeEnum.DATE_SINGLE.getValue().equals(onlCgformField.getFieldShowType()) && StringUtils.isNotBlank(s)){
@@ -1693,17 +1786,35 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
// s = ""; // s = "";
// } // }
if(StringUtils.isNotBlank(s)){ if(StringUtils.isNotBlank(s)){
stringMap.put(onlCgformField.getDbFieldName(), s); stringMapCn.put(onlCgformField.getDbFieldName(), s);
stringMapEn.put(onlCgformField.getDbFieldName(), s);
} }
} }
stringMap.put("id", (String) map.get("id")); String cutCn = CutEnum.CN.getValue();
stringMap.put("module_type", "文档库"); String cutEn = CutEnum.EN.getValue();
stringMap.put("serial_number", map.get("serial_number")); //封装中文的全文内容(es)
stringMap.put("title", map.get("title")); putMapCn((String) map.get("id"),
stringMap.put("content", sb.toString()); (String) map.get("serial_number"),
stringMap.put("file_text", ""); "文档库",
stringMap.put("file_name", ""); sbCn.toString(),
mapListTemp.add(stringMap); (String) map.get("title"),
"",
"",
cutCn,
stringMapCn);
//封装英文的全文内容(es)
putMapCn((String) map.get("id"),
(String) map.get("serial_number"),
"document library",
sbEn.toString(),
(String) map.get("title"),
"",
"",
cutEn,
stringMapEn);
mapListTempCn.add(stringMapCn);
mapListTempEn.add(stringMapEn);
} }
} catch (Exception e) { } catch (Exception e) {
@@ -1745,20 +1856,24 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
} }
} }
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(objectMapTemp)); JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(objectMapTemp));
JSONArray array = JSONArray.parseArray(JSON.toJSONString(mapListTemp)); JSONArray arrayCn = JSONArray.parseArray(JSON.toJSONString(mapListTempCn));
// JSONObject jsonObjectAll = JSON.parseObject(JSON.toJSONString(mapFullText)); JSONArray arrayEn = JSONArray.parseArray(JSON.toJSONString(mapListTempEn));
//修改es //修改es
try { try {
//删除文档库和全部 //删除文档库和全部
jeroElasticsearchTemplate.delete(SearchEnum.INDEX_NAME_DOCUMENT.getValue(), SearchEnum.TYPE_NAME_DOCUMENT.getValue(), (String) map.get("id")); jeroElasticsearchTemplate.delete(SearchEnum.INDEX_NAME_DOCUMENT.getValue(), SearchEnum.TYPE_NAME_DOCUMENT.getValue(), (String) map.get("id"));
//删除全部 //删除全部中文
for (Map<String, Object> objectMap : mapListTemp) { for (Map<String, Object> objectMap : mapListTempCn) {
jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), (String) objectMap.get("id")); jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), (String) objectMap.get("id"));
}
//删除全部中文
for (Map<String, Object> objectMap : mapListTempEn) {
jeroElasticsearchTemplate.delete(SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), (String) objectMap.get("id"));
} }
jeroElasticsearchTemplate.saveOrUpdate(SearchEnum.INDEX_NAME_DOCUMENT.getValue(), SearchEnum.TYPE_NAME_DOCUMENT.getValue(), (String) map.get("id"), jsonObject); jeroElasticsearchTemplate.saveOrUpdate(SearchEnum.INDEX_NAME_DOCUMENT.getValue(), SearchEnum.TYPE_NAME_DOCUMENT.getValue(), (String) map.get("id"), jsonObject);
//添加全文 //添加全文
jeroElasticsearchTemplate.saveBatch(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), array); jeroElasticsearchTemplate.saveBatch(SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), SearchEnum.FULL_TEXT_SEARCH_CN.getValue(), arrayCn);
// jeroElasticsearchTemplate.saveOrUpdate(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), (String) map.get("id"), jsonObjectAll); jeroElasticsearchTemplate.saveBatch(SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), SearchEnum.FULL_TEXT_SEARCH_EN.getValue(), arrayEn);
} catch (Exception e) { } catch (Exception e) {
log.error("文档库编辑es失败"); log.error("文档库编辑es失败");
} }
@@ -3866,4 +3981,18 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
return null; return null;
} }
private void putMapCn(String id,String serialNumber,String moduleType,
String content,String title,String fileText,
String fileName,String cut,Map<String, Object> stringMap){
stringMap.put("id", id);
stringMap.put("serial_number", serialNumber);
stringMap.put("module_type", moduleType);
stringMap.put("content", content);
stringMap.put("title", title);
stringMap.put("file_text", fileText);
stringMap.put("file_name", fileName);
stringMap.put("cut",cut);
}
} }
@@ -463,10 +463,17 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
@Override @Override
public IPage getFullTextInfoList(SearchVO searchVO) { public IPage getFullTextInfoList(SearchVO searchVO) {
//判断索引是否存在 //判断索引是否存在
boolean flagTemp = jeroElasticsearchTemplate.indexExists(SearchEnum.FULL_TEXT_SEARCH.getValue()); boolean flagTemp = true;
if(CutEnum.CN.getValue().equals(searchVO.getCut())){
flagTemp = jeroElasticsearchTemplate.indexExists(SearchEnum.FULL_TEXT_SEARCH_CN.getValue());
}else{
flagTemp = jeroElasticsearchTemplate.indexExists(SearchEnum.FULL_TEXT_SEARCH_EN.getValue());
}
if (!flagTemp) { if (!flagTemp) {
return new Page(searchVO.getPageNo(), searchVO.getPageSize()); return new Page(searchVO.getPageNo(), searchVO.getPageSize());
} }
String selectValue = searchVO.getSelectValue(); String selectValue = searchVO.getSelectValue();
String selectValueTwo = searchVO.getSelectValueTwo(); String selectValueTwo = searchVO.getSelectValueTwo();
//不查询高亮字段 //不查询高亮字段
@@ -523,7 +530,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
queryMapJsonAll.add(jsonObjectTwo); queryMapJsonAll.add(jsonObjectTwo);
} }
IPage page = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, null); IPage page = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, null,searchVO.getCut());
return page; return page;
@@ -531,7 +538,8 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
} }
@NotNull @NotNull
private IPage getiPage(String selectValue, String selectValueTwo, JSONArray queryMapJson, JSONArray should, Integer pageNo, Integer pageSize, String paragraphFlag) { private IPage getiPage(String selectValue, String selectValueTwo, JSONArray queryMapJson,
JSONArray should, Integer pageNo, Integer pageSize, String paragraphFlag,String cut) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
//基础添加封装 //基础添加封装
if ("paragraphFlag".equals(paragraphFlag)) { if ("paragraphFlag".equals(paragraphFlag)) {
@@ -549,22 +557,16 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
pageSize); pageSize);
// JSONObject queryObject11 = jeroElasticsearchTemplate.buildQuery(null, jsonObject11,highlightMap,null, Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString())); // JSONObject queryObject11 = jeroElasticsearchTemplate.buildQuery(null, jsonObject11,highlightMap,null, Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString()));
//2. 数据查询 //2. 数据查询
JSONObject search = jeroElasticsearchTemplate.search(SearchEnum.FULL_TEXT_SEARCH.getValue(), JSONObject search = new JSONObject();
SearchEnum.FULL_TEXT_SEARCH.getValue(), if(CutEnum.CN.getValue().equals(cut)){
queryObject); search = jeroElasticsearchTemplate.search(SearchEnum.FULL_TEXT_SEARCH_CN.getValue(),
SearchEnum.FULL_TEXT_SEARCH_CN.getValue(),
queryObject);
JSONObject queryObjectAll = jeroElasticsearchTemplate.buildQuery(null, }else{
null, search = jeroElasticsearchTemplate.search(SearchEnum.FULL_TEXT_SEARCH_EN.getValue(),
null, SearchEnum.FULL_TEXT_SEARCH_EN.getValue(),
null, queryObject);
pageNo-1, }
pageSize);
//全部的数据(调试接口用--最后删除即可)
JSONObject searchAll = jeroElasticsearchTemplate.search(SearchEnum.FULL_TEXT_SEARCH.getValue(),
SearchEnum.FULL_TEXT_SEARCH.getValue(),
queryObjectAll);
List<Map<String, Object>> list = (List<Map<String, Object>>) (((Map) search.get("hits")).get("hits")); List<Map<String, Object>> list = (List<Map<String, Object>>) (((Map) search.get("hits")).get("hits"));
@@ -758,7 +760,8 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
@Override @Override
public void deleteAll() { public void deleteAll() {
jeroElasticsearchTemplate.removeIndex(SearchEnum.INDEX_NAME_DOCUMENT.getValue()); jeroElasticsearchTemplate.removeIndex(SearchEnum.INDEX_NAME_DOCUMENT.getValue());
jeroElasticsearchTemplate.removeIndex(SearchEnum.FULL_TEXT_SEARCH.getValue()); jeroElasticsearchTemplate.removeIndex(SearchEnum.FULL_TEXT_SEARCH_CN.getValue());
jeroElasticsearchTemplate.removeIndex(SearchEnum.FULL_TEXT_SEARCH_EN.getValue());
} }
@@ -770,9 +773,16 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
*/ */
@Override @Override
public IPage getParagraphInfoList(Map<String, Object> map) { public IPage getParagraphInfoList(Map<String, Object> map) {
String cut = (String) map.get("cut");
//module_type 代表文档库的段落 //module_type 代表文档库的段落
//判断索引是否存在 //判断索引是否存在
boolean flagTemp = jeroElasticsearchTemplate.indexExists(SearchEnum.FULL_TEXT_SEARCH.getValue()); boolean flagTemp = true;
if(CutEnum.CN.getValue().equals(cut)){
flagTemp = jeroElasticsearchTemplate.indexExists(SearchEnum.FULL_TEXT_SEARCH_CN.getValue());
}else{
flagTemp = jeroElasticsearchTemplate.indexExists(SearchEnum.FULL_TEXT_SEARCH_EN.getValue());
}
if (!flagTemp) { if (!flagTemp) {
return new Page(Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString())); return new Page(Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString()));
} }
@@ -843,7 +853,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
String paragraphFlag = "paragraphFlag"; String paragraphFlag = "paragraphFlag";
IPage iPage = getiPage(selectValue, selectValueTwo, must, should, pageNo, pageSize, paragraphFlag); IPage iPage = getiPage(selectValue, selectValueTwo, must, should, pageNo, pageSize, paragraphFlag,(String) map.get("cut"));
return iPage; return iPage;
} }
@@ -14,19 +14,11 @@ public class SearchVO {
private String ids; private String ids;
//记录从哪个索引表中查数据 //记录从哪个索引表中查数据
private String selectIndex; private String selectIndex;
private String keywords;
private String resultKeyword;
// 条目搜索条件
private String itemsName;
private String itemsNum;
private String parts;
private Integer pageNo; private Integer pageNo;
private Integer pageSize; private Integer pageSize;
private String cut;
public Integer getPageNo() { public Integer getPageNo() {
return pageNo; return pageNo;
} }
@@ -75,43 +67,11 @@ public class SearchVO {
this.selectIndex = selectIndex; this.selectIndex = selectIndex;
} }
public String getKeywords() { public String getCut() {
return keywords; return cut;
} }
public void setKeywords(String keywords) { public void setCut(String cut) {
this.keywords = keywords; this.cut = cut;
}
public String getResultKeyword() {
return resultKeyword;
}
public void setResultKeyword(String resultKeyword) {
this.resultKeyword = resultKeyword;
}
public String getItemsName() {
return itemsName;
}
public void setItemsName(String itemsName) {
this.itemsName = itemsName;
}
public String getItemsNum() {
return itemsNum;
}
public void setItemsNum(String itemsNum) {
this.itemsNum = itemsNum;
}
public String getParts() {
return parts;
}
public void setParts(String parts) {
this.parts = parts;
} }
} }