es-降低搜索精度

This commit is contained in:
zhn
2022-06-06 15:48:44 +08:00
parent 6d47ca665f
commit d2c283b2a5
@@ -314,14 +314,30 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
String value = (String) entry.getValue();
if (ObjectUtils.isNotEmpty(value)) {
for (String s : value.split(",")) {
Map<String, Object> map = new HashMap<>();
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> queryMapTemp = new HashMap<>();
queryMapTemp.put(key, s);
queryMap.put("match_phrase", queryMapTemp);
must.add(queryMap);
queryMapTemp.put("query", s);
queryMapTemp.put("minimum_should_match", 2);
queryMap.put(key, queryMapTemp);
map.put("match",queryMap);
must.add(map);
}
}
}
// for (Map.Entry<String, Object> entry : inputMap.entrySet()) {
// String key = entry.getKey();
// String value = (String) entry.getValue();
// if (ObjectUtils.isNotEmpty(value)) {
// for (String s : value.split(",")) {
// Map<String, Object> queryMap = new HashMap<>();
// Map<String, Object> queryMapTemp = new HashMap<>();
// queryMapTemp.put(key, s);
// queryMap.put("match_phrase", queryMapTemp);
// must.add(queryMap);
// }
// }
// }
}
//封装下拉,树形查询条件
if (ObjectUtils.isNotEmpty(otherMap)) {
@@ -338,21 +354,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
}
}
}
// if (ObjectUtils.isNotEmpty(otherMap)) {
// for (Map.Entry<String, Object> entry : otherMap.entrySet()) {
// String key = entry.getKey();
// String value = (String) entry.getValue();
// if (ObjectUtils.isNotEmpty(value)) {
// for (String s : value.split(",")) {
// Map<String, Object> queryMap = new HashMap<>();
// Map<String, Object> queryMapTemp = new HashMap<>();
// queryMapTemp.put(key, s);
// queryMap.put("match_phrase", queryMapTemp);
// must.add(queryMap);
// }
// }
// }
// }
//封装时间类型字段查询(时间范围)
if (ObjectUtils.isNotEmpty(dateMap)) {
for (Map.Entry<String, Object> entry : dateMap.entrySet()) {
@@ -416,33 +417,29 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
//封装首次的条件
if (StringUtils.isNotBlank(selectValue)) {
for (String field : fieldList) {
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
Map<String, Object> map3 = new HashMap<>();
// if("title".equals(field) || "serial_number".equals(field)){
// map3.put("query",selectValue);
// map3.put("slop",1);
// map3.put("boost",10f);
// }else{
// map3.put("query",selectValue);
// map3.put("slop",1);
// }
Map<String, Object> map4 = new HashMap<>();
map3.put("query",selectValue);
map3.put("slop",1);
map3.put("minimum_should_match",2);
// if("serial_number".equals(field)){
// map3.put("fuzziness",1);
// }
map2.put(field, map3);
queryMap.put("match_phrase", map2);
queryMapJson.add(queryMap);
map4.put("match",map2);
queryMapJson.add(map4);
}
}
// if (StringUtils.isNotBlank(selectValue)) {
// for (String field : fieldList) {
// Map<String, Object> queryMap = new HashMap<>();
// Map<String, Object> map2 = new HashMap<>();
// map2.put(field, selectValue);
// Map<String, Object> map3 = new HashMap<>();
// map3.put("query",selectValue);
// map3.put("slop",1);
// map2.put(field, map3);
// queryMap.put("match_phrase", map2);
// queryMapJson.add(queryMap);
// }
// }
}
if(CollectionUtils.isNotEmpty(queryMapJson)){
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJson);
queryMapJsonAll.add(jsonObject);
@@ -454,21 +451,22 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
Map<String, Object> map2 = new HashMap<>();
Map<String, Object> map3 = new HashMap<>();
map3.put("query",selectValueTwo);
map3.put("slop",1);
map3.put("minimum_should_match",2);
map2.put(field, map3);
queryMap.put("match_phrase", map2);
queryMap.put("match", map2);
queryMapJsonTwo.add(queryMap);
}
}
// 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_phrase", map2);
// Map<String, Object> map3 = new HashMap<>();
// map3.put("query",selectValueTwo);
// map3.put("minimum_should_match",2);
// map2.put(field, map3);
// queryMap.put("query", map2);
// queryMapJsonTwo.add(queryMap);
// }
// }
}
if(CollectionUtils.isNotEmpty(queryMapJsonTwo)){
JSONObject jsonObjectTwo = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJsonTwo);
queryMapJsonAll.add(jsonObjectTwo);
@@ -947,26 +945,23 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
Map<String, Object> queryMapTemp = new HashMap<>();
Map<String, Object> queryMap3 = new HashMap<>();
queryMap3.put("query",s);
queryMap3.put("slop",1);
queryMap3.put("minimum_should_match",2);
queryMapTemp.put(key, queryMap3);
queryMap.put("match_phrase", queryMapTemp);
queryMap.put("match", queryMapTemp);
queryMapJson.add(queryMap);
}
}
}
// for (Map.Entry<String, Object> entry : mapOne.entrySet()) {
// String key = entry.getKey();
// String value = (String) entry.getValue();
// if (ObjectUtils.isNotEmpty(value)) {
// for (String s : value.split(",")) {
// Map<String, Object> queryMap = new HashMap<>();
// Map<String, Object> queryMapTemp = new HashMap<>();
// queryMapTemp.put(key, s);
// Map<String, Object> queryMap3 = new HashMap<>();
// queryMap3.put("query",s);
// queryMap3.put("slop",1);
// queryMapTemp.put(key, queryMap3);
// queryMap.put("match_phrase", queryMapTemp);
// queryMapJson.add(queryMap);
// }
// }
// }
}
}
if(CollectionUtils.isNotEmpty(queryMapJsonTemp)){
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJsonTemp, null, null);
queryMapJsonAll.add(jsonObject);
@@ -975,19 +970,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJson, null, null);
queryMapJsonAll.add(jsonObject);
}
//首次查询所有的条件是and的关系
// if(ObjectUtils.isEmpty(mapTwo)){
// if(CollectionUtils.isNotEmpty(queryMapJson)){
// JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJson, null, null);
// queryMapJsonAll.add(jsonObject);
// }
// }else{
// if(CollectionUtils.isNotEmpty(queryMapJson)){
// JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJson);
// queryMapJsonAll.add(jsonObject);
// }
// }
}
String ids = (String) mapTwo.get("ids");
@@ -1003,11 +985,21 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
Map<String, Object> queryMapTemp = new HashMap<>();
Map<String, Object> queryMap3 = new HashMap<>();
queryMap3.put("query",s);
queryMap3.put("slop",1);
queryMap3.put("minimum_should_match",2);
queryMapTemp.put(key, queryMap3);
queryMap.put("match_phrase", queryMapTemp);
queryMap.put("match", queryMapTemp);
queryMapJsonTwo.add(queryMap);
}
// for (String s : value.split(",")) {
// Map<String, Object> queryMap = new HashMap<>();
// Map<String, Object> queryMapTemp = new HashMap<>();
// Map<String, Object> queryMap3 = new HashMap<>();
// queryMap3.put("query",s);
// queryMap3.put("slop",1);
// queryMapTemp.put(key, queryMap3);
// queryMap.put("match_phrase", queryMapTemp);
// queryMapJsonTwo.add(queryMap);
// }
}
}
if(CollectionUtils.isNotEmpty(queryMapJsonTwo)){
@@ -1015,26 +1007,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
queryMapJsonAll.add(jsonObject);
}
}
// if (ObjectUtils.isNotEmpty(mapTwo)) {
// mapTwo.remove("ids");
// for (Map.Entry<String, Object> entry : mapTwo.entrySet()) {
// String key = entry.getKey();
// String value = (String) entry.getValue();
// if (ObjectUtils.isNotEmpty(value)) {
// for (String s : value.split(",")) {
// Map<String, Object> queryMap = new HashMap<>();
// Map<String, Object> queryMapTemp = new HashMap<>();
// queryMapTemp.put(key, s);
// queryMap.put("match_phrase", queryMapTemp);
// queryMapJsonTwo.add(queryMap);
// }
// }
// }
// if(CollectionUtils.isNotEmpty(queryMapJsonTwo)){
// JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJsonTwo, null, null);
// queryMapJsonAll.add(jsonObject);
// }
// }
//ids查询条件
if (StringUtils.isNotBlank(ids)) {