搜索中心-问题知识库查询。
This commit is contained in:
+51
-2
@@ -1156,7 +1156,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
//封装首次的条件
|
||||
if (StringUtils.isNotBlank(selectValue)) {
|
||||
for (String field : fieldList) {
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
/*Map<String, Object> map2 = new HashMap<>();
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
Map<String, Object> 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<String, Object> map21 = new HashMap<>();
|
||||
Map<String, Object> map31 = new HashMap<>();
|
||||
Map<String, Object> 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<String, Object> map22 = new HashMap<>();
|
||||
Map<String, Object> map32 = new HashMap<>();
|
||||
Map<String, Object> 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<String, Object> map23 = new HashMap<>();
|
||||
Map<String, Object> map43 = new HashMap<>();
|
||||
map23.put(field, selectValue);
|
||||
map43.put("match", map23);
|
||||
queryMapJson.add(map43);
|
||||
|
||||
// wildcard模糊查询
|
||||
//情况举例:用户只记得中间那段字
|
||||
Map<String, Object> map24 = new HashMap<>();
|
||||
Map<String, Object> map44 = new HashMap<>();
|
||||
map24.put(field, "*" + selectValue + "*");
|
||||
map44.put("wildcard",map24);
|
||||
queryMapJson.add(map44);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user