搜索功能处理

This commit is contained in:
wangchengjun
2022-03-31 03:06:40 +08:00
parent edc853ac86
commit bfa027d5db
@@ -25,6 +25,7 @@ import com.jero.modules.system.entity.SysCategory;
import com.jero.modules.system.entity.SysDictItem;
import com.jero.modules.system.service.impl.SysCategoryServiceImpl;
import com.jero.modules.system.service.impl.SysDictItemServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
@@ -169,7 +170,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> queryMapTemp = new HashMap<>();
queryMapTemp.put("id", s);
queryMap.put("match", queryMapTemp);
queryMap.put("match_phrase", queryMapTemp);
should.add(queryMap);
}
}
@@ -275,7 +276,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> queryMapTemp = new HashMap<>();
queryMapTemp.put(key, s);
queryMap.put("match", queryMapTemp);
queryMap.put("match_phrase", queryMapTemp);
must.add(queryMap);
}
}
@@ -291,7 +292,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> queryMapTemp = new HashMap<>();
queryMapTemp.put(key, s);
queryMap.put("match", queryMapTemp);
queryMap.put("match_phrase", queryMapTemp);
must.add(queryMap);
}
}
@@ -382,7 +383,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
// Map<String, Object> queryMap = new HashMap<>();
// Map<String, Object> queryMapTemp = new HashMap<>();
// queryMapTemp.put(key, s);
// queryMap.put("match", queryMapTemp);
// queryMap.put("match_phrase", queryMapTemp);
// must.add(queryMap);
// }
// }
@@ -399,7 +400,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
// Map<String, Object> queryMap = new HashMap<>();
// Map<String, Object> queryMapTemp = new HashMap<>();
// queryMapTemp.put(key, s);
// queryMap.put("match", queryMapTemp);
// queryMap.put("match_phrase", queryMapTemp);
// must.add(queryMap);
// }
// }
@@ -474,22 +475,29 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
fieldList.add("file_name");
fieldList.add("id");
JSONArray queryMapJson = new JSONArray();
JSONArray queryMapJsonTwo = new JSONArray();
JSONArray queryMapJsonAll = new JSONArray();
if (StringUtils.isNotBlank(selectValue)) {
for (String field : fieldList) {
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
map2.put(field, selectValue);
queryMap.put("match", map2);
queryMap.put("match_phrase", map2);
queryMapJson.add(queryMap);
}
}
if(CollectionUtils.isNotEmpty(queryMapJson)){
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJson);
queryMapJsonAll.add(jsonObject);
}
if (StringUtils.isNotBlank(selectValueTwo)) {
for (String field : fieldList) {
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
map2.put(field, selectValueTwo);
queryMap.put("match", map2);
queryMapJson.add(queryMap);
queryMap.put("match_phrase", map2);
queryMapJsonTwo.add(queryMap);
}
}
//处理二次查询中选择了课表数据进行查询的情况
@@ -498,13 +506,19 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> queryMapTemp = new HashMap<>();
queryMapTemp.put("id", s);
queryMap.put("match", queryMapTemp);
queryMapJson.add(queryMap);
queryMap.put("match_phrase", queryMapTemp);
queryMapJsonTwo.add(queryMap);
}
}
Integer pageNo = searchVO.getPageNo();
Integer pageSize = searchVO.getPageSize();
IPage page = getiPage(selectValue, selectValueTwo, queryMapJson, null, pageNo, pageSize, null);
//封装二次查询
if(CollectionUtils.isNotEmpty(queryMapJsonTwo)){
JSONObject jsonObjectTwo = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJsonTwo);
queryMapJsonAll.add(jsonObjectTwo);
}
IPage page = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, null);
return page;
@@ -518,7 +532,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
if ("paragraphFlag".equals(paragraphFlag)) {
jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJson, null, should);
} else {
jsonObject = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJson);
jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJson, null, null);
}
//全部
//1. 条件,分页
@@ -796,7 +810,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> queryMapTemp = new HashMap<>();
queryMapTemp.put("id", s);
queryMap.put("match", queryMapTemp);
queryMap.put("match_phrase", queryMapTemp);
should.add(queryMap);
}
}