搜索--文件展示顺序

1. 区分标准
2. 同一标准下文件展示顺序(发布稿  增补件  报批稿  征求意见稿 测试程序)
This commit is contained in:
zhn
2022-04-01 19:25:55 +08:00
parent c146d817b1
commit d9cc03e717
3 changed files with 107 additions and 13 deletions
@@ -434,16 +434,16 @@ public class JeroElasticsearchTemplate {
//// json.put("sort", sort);
// return json;
// }
public JSONObject buildQuery(List<String> _source, JSONObject query,Map<String, Object> highlight,String sort, int from, int size) {
public JSONObject buildQuery(List<String> _source, JSONObject query,Map<String, Object> highlight,JSONArray sort, int from, int size) {
JSONObject json = new JSONObject();
if (_source != null) {
json.put("_source", _source);
}
json.put("highlight", highlight);
json.put("query", query);
json.put("sort", sort);
json.put("from", from);
json.put("size", size);
// json.put("sort", sort);
return json;
}
@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import com.jero.common.constant.CommonConstant;
import com.jero.common.constant.WebsocketConst;
import com.jero.common.constant.enums.*;
@@ -1126,9 +1127,10 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
StringBuilder sbEn = new StringBuilder();
List<List<String>> fileTextList = new ArrayList<>();
List<OSSFile> oSSFileAll = new ArrayList<>();
List<Map<String,Object>> maps = new ArrayList<>();
try {
for (Map.Entry<String, Object> entry : map.entrySet()) {
Map<String,Object> stringObjectMap = new HashMap<>();
String key = entry.getKey();
Object value = entry.getValue();
//es全文新增数据(数据转换)
@@ -1152,6 +1154,8 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
}
if (fieldFile.size() != 0 && ObjectUtils.isNotEmpty(value)) {
String valueTemp = UUID.randomUUID().toString().replace("-", "");
stringObjectMap.put(key,valueTemp);
maps.add(stringObjectMap);
// value = valueTemp;
//修改文件表关联信息connect_id
List<OSSFile> oSSFileList = new ArrayList<>();
@@ -1175,18 +1179,24 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
} catch (Exception e) {
e.printStackTrace();
}
//多文件es iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ","));
//多文件es
List<String> fileIdList = oSSFileAll.stream().map(OSSFile::getId).collect(Collectors.toList());
List<OSSFile> fileInfos = iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ","));
//处理文件排序(发布稿 增补件 报批稿 征求意见稿 测试程序)
List<OSSFile> ossFileList = fileSort(fieldFileList, fileInfos, maps);
List<Map<String, Object>> mapListTempCn = new ArrayList<>();
List<Map<String, Object>> mapListTempEn = new ArrayList<>();
try {
String cutCn = CutEnum.CN.getValue();
String cutEn = CutEnum.EN.getValue();
if (fileInfos.size() != 0) {
if (ossFileList.size() != 0) {
Map<String, Object> mapBaseDateCn = new HashMap<>();
Map<String, Object> mapBaseDateEn = new HashMap<>();
for (OSSFile ossFile : fileInfos) {
for (OSSFile ossFile : ossFileList) {
Map<String, Object> stringMapCn = new HashMap<>();
Map<String, Object> stringMapEn = new HashMap<>();
String fileText = "";
@@ -1234,15 +1244,27 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
mapListTempCn.add(stringMapCn);
mapListTempEn.add(stringMapEn);
int a = 1;
int b = 1;
for (Map<String, Object> objectMap : mapListTempCn) {
a++;
objectMap.put("file_sort",idTemp+"_"+a);
}
for (Map<String, Object> objectMap : mapListTempEn) {
b++;
objectMap.put("file_sort",idTemp+"_"+b);
}
}
//基础数据(中文)
putMapCn(idTemp, (String) map.get("serial_number"), "文档库",
sbCn.toString(), (String) map.get("title"), "", "",
cutCn, mapBaseDateCn,SEARCH_FLAG);
mapBaseDateCn.put("file_sort",idTemp+"_"+1);
//基础数据(英文)
putMapCn(idTemp, (String) map.get("serial_number"), "document library",
sbEn.toString(), (String) map.get("title"), "", "",
cutEn, mapBaseDateEn,SEARCH_FLAG);
mapBaseDateEn.put("file_sort",idTemp+"_"+1);
mapListTempCn.add(mapBaseDateCn);
mapListTempEn.add(mapBaseDateEn);
} else {
@@ -1260,15 +1282,15 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
(String) map.get("serial_number"), "文档库", sbCn.toString(),
(String) map.get("title"), "", "",
cutCn, stringMapCn, SEARCH_FLAG);
stringMapCn.put("file_sort",idTemp+"_"+1);
//封装英文的全文内容(es)
putMapCn(idTemp, (String) map.get("serial_number"), "document library", sbEn.toString(),
(String) map.get("title"), "", "",
cutEn, stringMapEn,SEARCH_FLAG);
stringMapEn.put("file_sort",idTemp+"_"+1);
mapListTempCn.add(stringMapCn);
mapListTempEn.add(stringMapEn);
}
} catch (Exception e) {
log.error("文档库新增es错误");
}
@@ -1619,7 +1641,9 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
List<OSSFile> oSSFileAll = new ArrayList<>();
StringBuilder sbCn = new StringBuilder();
StringBuilder sbEn = new StringBuilder();
List<Map<String,Object>> maps = new ArrayList<>();
for (Map.Entry<String, Object> entry : mapNew.entrySet()) {
Map<String,Object> stringObjectMap = new HashMap<>();
String key = entry.getKey();
Object value = entry.getValue();
//es全文新增数据(数据转换)
@@ -1647,6 +1671,8 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
if ((ObjectUtils.isNotEmpty(dataList.get(0).get(key)) && !dataList.get(0).get(key).equals(value))
|| (ObjectUtils.isEmpty(dataList.get(0).get(key)) && ObjectUtils.isNotEmpty(value))) {
String valueTemp = UUID.randomUUID().toString().replace("-", "");
stringObjectMap.put(key,valueTemp);
maps.add(stringObjectMap);
//修改文件表关联信息connect_id
List<OSSFile> oSSFileList = new ArrayList<>();
for (String fileId : value.toString().split(",")) {
@@ -1681,6 +1707,10 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
}
List<String> fileIdList = oSSFileAll.stream().map(OSSFile::getId).collect(Collectors.toList());
List<OSSFile> fileInfos = iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ","));
//处理文件排序(发布稿 增补件 报批稿 征求意见稿 测试程序)
List<OSSFile> ossFileList = fileSort(fieldFileList, fileInfos, maps);
List<Map<String, Object>> mapListTempCn = new ArrayList<>();
List<Map<String, Object>> mapListTempEn = new ArrayList<>();
try {
@@ -1739,15 +1769,28 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
mapListTempCn.add(stringMapCn);
mapListTempEn.add(stringMapEn);
int a = 1;
int b = 1;
for (Map<String, Object> objectMap : mapListTempCn) {
a++;
objectMap.put("file_sort",(String) map.get("id")+"_"+a);
}
for (Map<String, Object> objectMap : mapListTempEn) {
b++;
objectMap.put("file_sort",(String) map.get("id")+"_"+b);
}
}
//基础数据中文(es)
putMapCn((String) map.get("id"), (String) map.get("serial_number"), "文档库",
sbCn.toString(), (String) map.get("title"), "", "",
cutCn, mapBaseDateCn,SEARCH_FLAG);
mapBaseDateCn.put("file_sort",(String) map.get("id")+"_"+1);
//基础数据英文(es)
putMapCn((String) map.get("id"), (String) map.get("serial_number"), "document library",
sbEn.toString(), (String) map.get("title"), "", "",
cutEn, mapBaseDateEn,SEARCH_FLAG);
mapBaseDateEn.put("file_sort",(String) map.get("id")+"_"+1);
mapListTempCn.add(mapBaseDateCn);
mapListTempEn.add(mapBaseDateEn);
} else {
@@ -1769,10 +1812,12 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
putMapCn((String) map.get("id"), (String) map.get("serial_number"), "文档库",
sbCn.toString(), (String) map.get("title"), "", "",
cutCn, stringMapCn,SEARCH_FLAG);
stringMapCn.put("file_sort",(String) map.get("id")+"_"+1);
//封装英文的全文内容(es)
putMapCn((String) map.get("id"), (String) map.get("serial_number"), "document library",
sbEn.toString(), (String) map.get("title"), "", "",
cutEn, stringMapEn,SEARCH_FLAG);
stringMapEn.put("file_sort",(String) map.get("id")+"_"+1);
mapListTempCn.add(stringMapCn);
mapListTempEn.add(stringMapEn);
@@ -4057,4 +4102,31 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
}
/**
*
* @param fieldFileList 文件排序字段
* @param oSSFileAll 所有文件
* @param maps key-->字段 value-->关联文件connect_id
*/
public List<OSSFile> fileSort(List<OnlCgformField> fieldFileList,List<OSSFile> oSSFileAll,List<Map<String,Object>> maps){
List<OSSFile> result = new LinkedList<>();
List<String> fileFeildList = fieldFileList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
for (OnlCgformField onlCgformField : fieldFileList) {
String dbFieldName = onlCgformField.getDbFieldName();
for (Map<String, Object> map : maps) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
String value = (String)entry.getValue();
if(dbFieldName.equals(key)){
List<OSSFile> files = oSSFileAll.stream().filter(e -> value.equals(e.getConnectId())).collect(Collectors.toList());
if(files.size() != 0){
result.addAll(files);
}
}
}
}
}
return result;
}
}
@@ -332,10 +332,12 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
fieldList.add("file_name");
fieldList.add("id");
fieldList.add("flag");
JSONArray queryMapJson = new JSONArray();
JSONArray queryMapJsonTwo = new JSONArray();
JSONArray queryMapJsonThree = new JSONArray();
JSONArray queryMapJsonAll = new JSONArray();
//封装首次的条件
if (StringUtils.isNotBlank(selectValue)) {
for (String field : fieldList) {
@@ -378,15 +380,24 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
JSONObject jsonObjectThree = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJsonThree);
queryMapJsonAll.add(jsonObjectThree);
}
JSONObject sort = new JSONObject();
Map<String,Object> mapSort = new HashMap<>();
Map<String,Object> mapSortTemp = new HashMap<>();
mapSort.put("order","asc");
mapSortTemp.put("file_sort.keyword",mapSort);
sort.putAll(mapSortTemp);
Integer pageNo = searchVO.getPageNo();
Integer pageSize = searchVO.getPageSize();
IPage page = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, null,searchVO.getCut());
IPage page = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, null,searchVO.getCut(),sort);
return page;
}
@NotNull
private IPage getiPage(String selectValue, String selectValueTwo, JSONArray queryMapJson,
JSONArray should, Integer pageNo, Integer pageSize, String paragraphFlag,String cut) {
JSONArray should, Integer pageNo, Integer pageSize, String paragraphFlag,
String cut,JSONObject querySort) {
JSONObject jsonObject = new JSONObject();
//基础添加封装
if ("paragraphFlag".equals(paragraphFlag)) {
@@ -394,12 +405,15 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
} else {
jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJson, null, null);
}
JSONArray jsonArraySort = new JSONArray();
jsonArraySort.add(querySort);
//全部
//1. 条件,分页
JSONObject queryObject = jeroElasticsearchTemplate.buildQuery(null,
jsonObject,
null,
null,
jsonArraySort,
pageNo-1,
pageSize);
//2. 数据查询
@@ -480,7 +494,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
if (StringUtils.isNotBlank(selectValue)) {
for (Map.Entry<String, Object> entry : mapSource.entrySet()) {
String key = entry.getKey();
String value = (String) entry.getValue();
String value = String.valueOf(entry.getValue());
StringBuilder sb = new StringBuilder();
if (StringUtils.isNotBlank(value)) {
//file_text需要单独处理(截取第一处高亮的前后100个字符)
@@ -705,6 +719,14 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
queryMapJsonAll.add(jsonObject);
}
//排序
JSONObject sort = new JSONObject();
Map<String,Object> mapSort = new HashMap<>();
Map<String,Object> mapSortTemp = new HashMap<>();
mapSort.put("order","asc");
mapSortTemp.put("file_sort.keyword",mapSort);
sort.putAll(mapSortTemp);
int pageNo = Integer.parseInt(map.get("pageNo").toString());
int pageSize = Integer.parseInt(map.get("pageSize").toString());
//判断第一次传参和第二次传参 inputFieldList
@@ -728,7 +750,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
String paragraphFlag = "paragraphFlag";
IPage iPage = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, paragraphFlag,(String) map.get("cut"));
IPage iPage = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, paragraphFlag,(String) map.get("cut"),sort);
return iPage;
}