搜索中心-全部
This commit is contained in:
+116
-79
@@ -50,6 +50,8 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -658,90 +660,125 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
}
|
||||
|
||||
private void getQueryMapJsonFullText(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("serial_number".equals(field)){
|
||||
map31.put("boost",10);
|
||||
}else if("title".equals(field)){
|
||||
map31.put("boost",8);
|
||||
}else if("file_text".equals(field)){
|
||||
map31.put("boost",0.01);
|
||||
}else if("content".equals(field)){
|
||||
map31.put("boost",0.01);
|
||||
}else if("file_name".equals(field)){
|
||||
map31.put("boost",5);
|
||||
}
|
||||
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("serial_number".equals(field)){
|
||||
map32.put("boost",10);
|
||||
}else if("title".equals(field)){
|
||||
map32.put("boost",8);
|
||||
}else if("file_text".equals(field)){
|
||||
map32.put("boost",0.01);
|
||||
}else if("content".equals(field)){
|
||||
map32.put("boost",0.01);
|
||||
}else if("file_name".equals(field)){
|
||||
map32.put("boost",5);
|
||||
}
|
||||
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> map33 = new HashMap<>();
|
||||
Map<String, Object> map43 = new HashMap<>();
|
||||
if("serial_number".equals(field)){
|
||||
map33.put("boost",10);
|
||||
}else if("title".equals(field)){
|
||||
map33.put("boost",8);
|
||||
}else if("file_text".equals(field)){
|
||||
map33.put("boost",0.01);
|
||||
}else if("content".equals(field)){
|
||||
map33.put("boost",0.01);
|
||||
}else if("file_name".equals(field)){
|
||||
map33.put("boost",5);
|
||||
}
|
||||
map33.put("query", selectValue);
|
||||
map23.put(field, map33);
|
||||
map43.put("match", map23);
|
||||
queryMapJson.add(map43);
|
||||
//依据正则拆分示例:你好Hello123世界World456可拆分为:你好、Hello、123、世界、World、456
|
||||
|
||||
// wildcard模糊查询
|
||||
//情况举例:用户只记得中间那段字
|
||||
Map<String, Object> map24 = new HashMap<>();
|
||||
Map<String, Object> map44 = new HashMap<>();
|
||||
Map<String, Object> map55 = new HashMap<>();
|
||||
map55.put("value","*" + selectValue + "*");
|
||||
if("serial_number".equals(field)){
|
||||
map55.put("boost",10);
|
||||
}else if("title".equals(field)){
|
||||
map55.put("boost",8);
|
||||
}else if("file_text".equals(field)){
|
||||
map55.put("boost",0.01);
|
||||
}else if("content".equals(field)){
|
||||
map55.put("boost",0.01);
|
||||
}else if("file_name".equals(field)){
|
||||
map55.put("boost",5);
|
||||
}
|
||||
String regex = "([\\u4e00-\\u9fa5]+|[a-zA-Z]+|\\d+)";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(selectValue);
|
||||
|
||||
map24.put(field, map55);
|
||||
map44.put("wildcard",map24);
|
||||
queryMapJson.add(map44);
|
||||
List<String> list = new ArrayList<>();
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group();
|
||||
list.add(group);
|
||||
}
|
||||
for (String s : list) {
|
||||
Map<String, Object> map33 = new HashMap<>();
|
||||
if("serial_number".equals(field)){
|
||||
map33.put("boost",10);
|
||||
}else if("title".equals(field)){
|
||||
map33.put("boost",8);
|
||||
}else if("file_text".equals(field)){
|
||||
map33.put("boost",0.01);
|
||||
}else if("content".equals(field)){
|
||||
map33.put("boost",0.01);
|
||||
}else if("file_name".equals(field)){
|
||||
map33.put("boost",5);
|
||||
}
|
||||
map33.put("query",s);
|
||||
Map<String,Object> map1 = new HashMap<>();
|
||||
map1.put(field,map33);
|
||||
Map<String,Object> map2 = new HashMap<>();
|
||||
map2.put("match",map1);
|
||||
queryMapJson.add(map2);
|
||||
}
|
||||
}
|
||||
// private void getQueryMapJsonFullText(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("serial_number".equals(field)){
|
||||
// map31.put("boost",10);
|
||||
// }else if("title".equals(field)){
|
||||
// map31.put("boost",8);
|
||||
// }else if("file_text".equals(field)){
|
||||
// map31.put("boost",0.01);
|
||||
// }else if("content".equals(field)){
|
||||
// map31.put("boost",0.01);
|
||||
// }else if("file_name".equals(field)){
|
||||
// map31.put("boost",5);
|
||||
// }
|
||||
// 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("serial_number".equals(field)){
|
||||
// map32.put("boost",10);
|
||||
// }else if("title".equals(field)){
|
||||
// map32.put("boost",8);
|
||||
// }else if("file_text".equals(field)){
|
||||
// map32.put("boost",0.01);
|
||||
// }else if("content".equals(field)){
|
||||
// map32.put("boost",0.01);
|
||||
// }else if("file_name".equals(field)){
|
||||
// map32.put("boost",5);
|
||||
// }
|
||||
// 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> map33 = new HashMap<>();
|
||||
// Map<String, Object> map43 = new HashMap<>();
|
||||
// if("serial_number".equals(field)){
|
||||
// map33.put("boost",10);
|
||||
// }else if("title".equals(field)){
|
||||
// map33.put("boost",8);
|
||||
// }else if("file_text".equals(field)){
|
||||
// map33.put("boost",0.01);
|
||||
// }else if("content".equals(field)){
|
||||
// map33.put("boost",0.01);
|
||||
// }else if("file_name".equals(field)){
|
||||
// map33.put("boost",5);
|
||||
// }
|
||||
// map33.put("query", selectValue);
|
||||
// map23.put(field, map33);
|
||||
// map43.put("match", map23);
|
||||
// queryMapJson.add(map43);
|
||||
//
|
||||
// // wildcard模糊查询
|
||||
// //情况举例:用户只记得中间那段字
|
||||
// Map<String, Object> map24 = new HashMap<>();
|
||||
// Map<String, Object> map44 = new HashMap<>();
|
||||
// Map<String, Object> map55 = new HashMap<>();
|
||||
// map55.put("value","*" + selectValue + "*");
|
||||
// if("serial_number".equals(field)){
|
||||
// map55.put("boost",10);
|
||||
// }else if("title".equals(field)){
|
||||
// map55.put("boost",8);
|
||||
// }else if("file_text".equals(field)){
|
||||
// map55.put("boost",0.01);
|
||||
// }else if("content".equals(field)){
|
||||
// map55.put("boost",0.01);
|
||||
// }else if("file_name".equals(field)){
|
||||
// map55.put("boost",5);
|
||||
// }
|
||||
//
|
||||
// map24.put(field, map55);
|
||||
// map44.put("wildcard",map24);
|
||||
// queryMapJson.add(map44);
|
||||
// }
|
||||
|
||||
@NotNull
|
||||
private IPage getiPage(String selectValue, String selectValueTwo, JSONArray queryMapJson,Map<String,Object> highlightMap,
|
||||
|
||||
Reference in New Issue
Block a user