diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/searchcenter/service/impl/DocumentSearchServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/searchcenter/service/impl/DocumentSearchServiceImpl.java index 6fb0cdc1c..c56ac269b 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/searchcenter/service/impl/DocumentSearchServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/searchcenter/service/impl/DocumentSearchServiceImpl.java @@ -389,11 +389,23 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { for (String field : fieldList) { Map queryMap = new HashMap<>(); Map map2 = new HashMap<>(); - map2.put(field, selectValue); + Map map3 = new HashMap<>(); + map3.put("query",selectValue); + map3.put("slop",1); + map2.put(field, map3); queryMap.put("match_phrase", map2); queryMapJson.add(queryMap); } } +// if (StringUtils.isNotBlank(selectValue)) { +// for (String field : fieldList) { +// Map queryMap = new HashMap<>(); +// Map map2 = new HashMap<>(); +// map2.put(field, selectValue); +// queryMap.put("match_phrase", map2); +// queryMapJson.add(queryMap); +// } +// } if(CollectionUtils.isNotEmpty(queryMapJson)){ JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJson); queryMapJsonAll.add(jsonObject); @@ -403,11 +415,23 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { for (String field : fieldList) { Map queryMap = new HashMap<>(); Map map2 = new HashMap<>(); - map2.put(field, selectValueTwo); + Map map3 = new HashMap<>(); + map3.put("query",selectValueTwo); + map3.put("slop",1); + map2.put(field, map3); queryMap.put("match_phrase", map2); queryMapJsonTwo.add(queryMap); } } +// if (StringUtils.isNotBlank(selectValueTwo)) { +// for (String field : fieldList) { +// Map queryMap = new HashMap<>(); +// Map map2 = new HashMap<>(); +// map2.put(field, selectValueTwo); +// queryMap.put("match_phrase", map2); +// queryMapJsonTwo.add(queryMap); +// } +// } if(CollectionUtils.isNotEmpty(queryMapJsonTwo)){ JSONObject jsonObjectTwo = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJsonTwo); queryMapJsonAll.add(jsonObjectTwo); @@ -533,25 +557,36 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { //file_text需要单独处理(截取第一处高亮的前后100个字符) if ("file_text".equals(key)) { //判断value中是否包含搜索中的字符 - if(value.contains(selectValue)){ - //截取第一处高亮的前后100个字符 - value = subFileText(value, selectValue); - }else{ - //第一次搜索的时候file_text中不包含搜索条件的时候将file_text赋值空(此时展示拼接的内容) - entry.setValue(""); - value = ""; + for (String s : selectValue.split(" ")) { + if(value.contains(s)){ + //截取第一处高亮的前后100个字符 + value = subFileText(value, s); + break; + }else{ + //第一次搜索的时候file_text中不包含搜索条件的时候将file_text赋值空(此时展示拼接的内容) + entry.setValue(""); + value = ""; + } } } if ("content".equals(key)) { - if(value.contains(selectValue)){ - value = subFileText(value, selectValue); + for (String s : selectValue.split(" ")) { + if(value.contains(s)){ + value = subFileText(value, s); + break; + } } } - String replacement = "" + selectValue + ""; - valueHighlight = value.replaceAll(selectValue, replacement); + for (String s : selectValue.split(" ")) { + String replacement = "" + s + ""; + value = value.replaceAll(s, replacement); + } + +// String replacement = "" + selectValue + ""; +// valueHighlight = value.replaceAll(selectValue, replacement); } - if (ObjectUtils.isNotEmpty(valueHighlight)) { - entry.setValue(valueHighlight); + if (ObjectUtils.isNotEmpty(value)) { + entry.setValue(value); } } } @@ -732,10 +767,10 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { }else if(i <100 && (fileTextInfo.length() - i) >= 100){ start = fileTextInfo.substring(0, i); end = fileTextInfo.substring(i, i+100); - }else if(i > 100 && (fileTextInfo.length() - i) >= 100){ + }else if(i >= 100 && (fileTextInfo.length() - i) >= 100){ start = fileTextInfo.substring(i-100, i); end = fileTextInfo.substring(i, i+100); - }else if(i > 100 && (fileTextInfo.length() - i) < 100){ + }else if(i >= 100 && (fileTextInfo.length() - i) < 100){ start = fileTextInfo.substring(i-100, i); end = fileTextInfo.substring(i, fileTextInfo.length()); } @@ -873,12 +908,28 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { for (String s : value.split(",")) { Map queryMap = new HashMap<>(); Map queryMapTemp = new HashMap<>(); - queryMapTemp.put(key, s); + Map queryMap3 = new HashMap<>(); + queryMap3.put("query",s); + queryMap3.put("slop",1); + queryMapTemp.put(key, queryMap3); queryMap.put("match_phrase", queryMapTemp); queryMapJson.add(queryMap); } } } +// for (Map.Entry entry : mapOne.entrySet()) { +// String key = entry.getKey(); +// String value = (String) entry.getValue(); +// if (ObjectUtils.isNotEmpty(value)) { +// for (String s : value.split(",")) { +// Map queryMap = new HashMap<>(); +// Map queryMapTemp = new HashMap<>(); +// queryMapTemp.put(key, s); +// queryMap.put("match_phrase", queryMapTemp); +// queryMapJson.add(queryMap); +// } +// } +// } if(CollectionUtils.isNotEmpty(queryMapJsonTemp)){ JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJsonTemp, null, null); queryMapJsonAll.add(jsonObject); @@ -913,7 +964,10 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { for (String s : value.split(",")) { Map queryMap = new HashMap<>(); Map queryMapTemp = new HashMap<>(); - queryMapTemp.put(key, s); + Map queryMap3 = new HashMap<>(); + queryMap3.put("query",s); + queryMap3.put("slop",1); + queryMapTemp.put(key, queryMap3); queryMap.put("match_phrase", queryMapTemp); queryMapJsonTwo.add(queryMap); } @@ -924,6 +978,26 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { queryMapJsonAll.add(jsonObject); } } +// if (ObjectUtils.isNotEmpty(mapTwo)) { +// mapTwo.remove("ids"); +// for (Map.Entry entry : mapTwo.entrySet()) { +// String key = entry.getKey(); +// String value = (String) entry.getValue(); +// if (ObjectUtils.isNotEmpty(value)) { +// for (String s : value.split(",")) { +// Map queryMap = new HashMap<>(); +// Map 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)) {