修改搜索中心排序问题

This commit is contained in:
zhangjun
2022-09-26 17:39:33 +08:00
parent a08b8cdc41
commit fd887d10fd
5 changed files with 100 additions and 0 deletions
@@ -153,6 +153,10 @@ public class WebMvcConfig implements WebMvcConfigurer {
addInterceptor.excludePathPatterns("/api/sysLog/sys-log/exportSysLogExcelVOExcelData");
addInterceptor.excludePathPatterns("/api/search/resetSearchCenter/resetALLSearchCenterForExits");
//// //测试接口使用
// addInterceptor.excludePathPatterns("/api/**");
@@ -124,6 +124,8 @@ public interface ElasticsearchService {
List<Map<String,Object>> searchAll(String index,String search);
List<Map<String,Object>> searchAllForExists(String index,String search);
/**
* 使用分词查询
*
@@ -310,6 +310,37 @@ public class ElasticsearchServiceImpl implements ElasticsearchService {
}
/**
* 使用索引查询所有
*/
@Override
public List<Map<String, Object>> searchAllForExists(String index,String search) {
List<Map<String, Object>> sourceList = new ArrayList<Map<String, Object>>();
//1、指定es集群 cluster.name 是固定的key值,my-application是ES集群的名称
// Settings settings = Settings.builder().put("cluster.name", "my-application").build();
BoolQueryBuilder boolQueryMustNot = QueryBuilders.boolQuery();
QueryBuilder qBuilder = boolQueryMustNot.mustNot(QueryBuilders.existsQuery("titleBig"));
SearchResponse sResponse = client.prepareSearch(index)
.setQuery(qBuilder).setTrackTotalHits(true)
.get();
SearchHits hits = sResponse.getHits();
if(hits.getTotalHits().value > 0){
// QueryBuilder queryBuilder1 = QueryBuilders.multiMatchQuery("");
// if(StringUtils.isNotBlank(search) && "fulltextserch".equals(index)){
// queryBuilder1 = QueryBuilders.multiMatchQuery(search,
// "sortTitle","numberTitle","yearOrder","nameTitle","title","textContent","issue_time"
// ).minimumShouldMatch("100%").field("sortTitle",1005f).field("numberTitle",1004f).field("yearOrder",1003f).field("nameTitle",1002f).field("title",1000f).field("textContent",100f).field("issue_time",10f);
// }
SearchResponse scrollResp = search(index,qBuilder, 1,(int) hits.getTotalHits().value);
for (SearchHit hit : scrollResp.getHits()) {
sourceList.add(hit.getSourceAsMap());
}
}
return sourceList;
}
public SearchResponse search(String index, QueryBuilder query,int page, int size) {
updateIndex(index, page,size);
@@ -61,6 +61,17 @@ public class ResetSearchCenterController extends BaseController<Map<String, Obje
}
@ApiOperation(value = "|SearchCenter|重新创建ALL标准数据索引")
@PostMapping(value="/resetALLSearchCenterForExits")
public ResponseMessage resetALLSearchCenterForExits(@RequestBody SearchCenter searchCenter) throws Exception{
ResponseMessage x = verifySearchCenter(searchCenter);
if (x != null){
return x;
}
return resetSearchCenterService.resetALLSearchCenterForExits(searchCenter);
}
@ApiOperation(value = "|SearchCenter|手动重新创建(---7天内---)ALL标准数据索引(凌晨有自动程序会跑)")
@PostMapping(value="/manualResetALLSearchCenter")
public ResponseMessage manualResetALLSearchCenter(@RequestBody SearchCenter searchCenter) throws Exception{
@@ -260,6 +260,30 @@ public class ResetSearchCenterService {
return Result.success(res);
}
@Async
public ResponseMessage resetALLSearchCenterForExits(SearchCenter searchCenter) throws Exception{
// Boolean getFulltextserchIndex = elasticsearchService.isIndexExist("fulltextserch");
SearchCenter standSearch = new SearchCenter();
standSearch.setExecType(searchCenter.getExecType());
if(StringUtils.isNotBlank(searchCenter.getSearch())){
standSearch.setSearch(searchCenter.getSearch());
}
if(searchCenter.getIdList() != null && !searchCenter.getIdList().isEmpty()){
standSearch.setIdList(searchCenter.getIdList());
}
SarStandardsInfoEOPage page = new SarStandardsInfoEOPage();
ResponseMessage stand = resetfulltextForExists(page,standSearch);
List<String> r = new ArrayList<>();
if(stand.isOk() && StringUtils.isNotBlank(stand.getData().toString())){
r.add(stand.getData().toString());
}
String res = String.join(", ", r);
logger.info(res);
return Result.success(res);
}
@Async
public ResponseMessage syncResetALLSearchCenter(SearchCenter searchCenter) throws Exception{
Boolean getFulltextserchIndex = elasticsearchService.isIndexExist("fulltextserch");
@@ -622,6 +646,34 @@ public class ResetSearchCenterService {
}
//重建国内外标准
@Async
public ResponseMessage resetfulltextForExists(SarStandardsInfoEOPage page,SearchCenter searchCenter) throws Exception{
int countUpdateSuccess = 0;
int countAddSuccess = 0;
Boolean getStandIndex = elasticsearchService.isIndexExist("stand");
if(!getStandIndex){
logger.info("ES 不存在索引:stand");
return Result.error("ES 不存在索引:stand");
}
String search = getSearch(searchCenter);
String result = "error";
List<Map<String, Object>> searchListData = elasticsearchService.searchAllForExists("fulltextserch",search);
for (Map<String, Object> map : searchListData) {
String title = String.valueOf(map.get("title"));
if (!"".equals(title) && !"null".equals(title)) {
map.put("titleBig",title.toUpperCase());
}
result = elasticsearchService.updateDataByIdForMap(map, "fulltextserch", "fulltextserch", String.valueOf(map.get("id")));
}
return Result.success(result);
}
//重建国内外标准
@Async
public ResponseMessage resetStandSearchCenterId(SarStandardsInfoEOPage page,SearchCenter searchCenter) throws Exception{