From cf916b894e581da89b1f5236e556c7c7e89d860b Mon Sep 17 00:00:00 2001 From: wangzhijiang <12345678> Date: Fri, 26 Aug 2022 16:13:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=B8=AD=E5=BF=83-=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E7=9F=A5=E8=AF=86=E5=BA=93=E6=9F=A5=E8=AF=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DocumentSearchServiceImpl.java | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) 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 284ad5277..bea48a7e2 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 @@ -1156,7 +1156,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { //封装首次的条件 if (StringUtils.isNotBlank(selectValue)) { for (String field : fieldList) { - Map map2 = new HashMap<>(); + /*Map map2 = new HashMap<>(); Map map3 = new HashMap<>(); Map map4 = new HashMap<>(); if("title".equals(field)){ @@ -1177,7 +1177,9 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { map2.put(field, map3); map4.put("match",map2); } - queryMapInputJson.add(map4); + queryMapInputJson.add(map4);*/ + + getQueryMapJson(queryMapInputJson, selectValue, field); //高亮 if(!"flag".equals(field)){ @@ -1444,6 +1446,53 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { mapHighlight.put(key, mapTemp); } + private void getQueryMapJson(JSONArray queryMapJson, String selectValue, String field) { + // 前缀匹配 缺点是前缀一定不能断开 + //情况举例:用户只记得前面那段字 + Map map21 = new HashMap<>(); + Map map31 = new HashMap<>(); + Map map41 = new HashMap<>(); + if("title".equals(field)){ + map31.put("boost",1); + }else if("content".equals(field)){ + map31.put("boost",0.01); + } + map31.put("value", selectValue); + map21.put(field + ".keyword", map31); + map41.put("prefix", map21); + queryMapJson.add(map41); + + // match_phrase_prefix 词组匹配查询,允许最后词组与文中的任意分词前缀匹配 + Map map22 = new HashMap<>(); + Map map32 = new HashMap<>(); + Map map42 = new HashMap<>(); + if("title".equals(field)){ + map32.put("boost",1); + }else if("content".equals(field)){ + map32.put("boost",0.01); + } + map32.put("query", selectValue); + map22.put(field, map32); + map42.put("match_phrase_prefix", map22); + queryMapJson.add(map42); + + // match分词匹配查询 + // 情况举例:用户可能他知道开头的前缀几个字,知道中间的几个字 + Map map23 = new HashMap<>(); + Map map43 = new HashMap<>(); + map23.put(field, selectValue); + map43.put("match", map23); + queryMapJson.add(map43); + + // wildcard模糊查询 + //情况举例:用户只记得中间那段字 + Map map24 = new HashMap<>(); + Map map44 = new HashMap<>(); + map24.put(field, "*" + selectValue + "*"); + map44.put("wildcard",map24); + queryMapJson.add(map44); + } + }