修复编号查询无法截断数字的问题
This commit is contained in:
+23
-2
@@ -380,7 +380,7 @@ public class JeroElasticsearchTemplate {
|
||||
|
||||
log.info("url:" + url + " ,search: " + queryObject.toJSONString());
|
||||
JSONObject res = RestUtil.post(url, queryObject);
|
||||
log.info("url:" + url + " ,return res: \n" + res.toJSONString());
|
||||
// log.info("url:" + url + " ,return res: \n" + res.toJSONString());
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
@@ -393,7 +393,7 @@ public class JeroElasticsearchTemplate {
|
||||
|
||||
log.info("url:" + url + " ,search: " + queryObject.toJSONString());
|
||||
JSONObject res = RestUtil.post(url,variables, queryObject);
|
||||
log.info("url:" + url + " ,return res: \n" + res.toJSONString());
|
||||
// log.info("url:" + url + " ,return res: \n" + res.toJSONString());
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -447,6 +447,27 @@ public class JeroElasticsearchTemplate {
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 无排序
|
||||
* @param _source
|
||||
* @param query
|
||||
* @param highlight
|
||||
* @param from
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
public JSONObject buildQuery(List<String> _source, JSONObject query,Map<String, Object> highlight, int from, int size) {
|
||||
JSONObject json = new JSONObject();
|
||||
if (_source != null) {
|
||||
json.put("_source", _source);
|
||||
}
|
||||
json.put("highlight", highlight);
|
||||
json.put("query", query);
|
||||
json.put("from", from * size);
|
||||
json.put("size", size);
|
||||
return json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return { "bool" : { "must": must, "must_not": mustNot, "should": should } }
|
||||
*/
|
||||
|
||||
+56
-33
@@ -317,10 +317,17 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
Map<String, Object> queryMap = new HashMap<>();
|
||||
Map<String, Object> queryMapTemp = new HashMap<>();
|
||||
queryMapTemp.put("query", s);
|
||||
queryMapTemp.put("minimum_should_match", 2);
|
||||
queryMap.put(key, queryMapTemp);
|
||||
map.put("match",queryMap);
|
||||
|
||||
if (key.equals("serial_number")){
|
||||
queryMap.put(key, "*" + s + "*");
|
||||
map.put("wildcard", queryMap);
|
||||
} else {
|
||||
queryMapTemp.put("query", s);
|
||||
queryMapTemp.put("minimum_should_match", 2);
|
||||
queryMap.put(key, queryMapTemp);
|
||||
map.put("match",queryMap);
|
||||
}
|
||||
|
||||
must.add(map);
|
||||
}
|
||||
}
|
||||
@@ -435,13 +442,20 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
Map<String, Object> map4 = new HashMap<>();
|
||||
map3.put("query",selectValue);
|
||||
map3.put("minimum_should_match",2);
|
||||
// if("serial_number".equals(field)){
|
||||
// map3.put("fuzziness",1);
|
||||
// }
|
||||
map2.put(field, map3);
|
||||
map4.put("match",map2);
|
||||
// 特殊处理编号字段
|
||||
if (field.equals("serial_number")){
|
||||
// map2放最内层
|
||||
map2.put(field, "*" + selectValue + "*");
|
||||
|
||||
// map4放query
|
||||
map4.put("wildcard",map2);
|
||||
} else {
|
||||
map3.put("query",selectValue);
|
||||
map3.put("minimum_should_match",2);
|
||||
|
||||
map2.put(field, map3);
|
||||
map4.put("match",map2);
|
||||
}
|
||||
queryMapJson.add(map4);
|
||||
}
|
||||
// for (String field : fieldList) {
|
||||
@@ -465,10 +479,20 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
Map<String, Object> queryMap = new HashMap<>();
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
map3.put("query",selectValueTwo);
|
||||
map3.put("minimum_should_match",2);
|
||||
map2.put(field, map3);
|
||||
queryMap.put("match", map2);
|
||||
|
||||
//特殊处理编号字段
|
||||
if (field.equals("serial_number")){
|
||||
// map2放最内层
|
||||
map2.put(field, "*" + selectValueTwo + "*");
|
||||
// map4放query
|
||||
queryMap.put("wildcard",map2);
|
||||
} else {
|
||||
map3.put("query",selectValueTwo);
|
||||
map3.put("minimum_should_match",2);
|
||||
map2.put(field, map3);
|
||||
queryMap.put("match", map2);
|
||||
}
|
||||
|
||||
queryMapJsonTwo.add(queryMap);
|
||||
}
|
||||
// for (String field : fieldList) {
|
||||
@@ -501,23 +525,23 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
queryMapJsonAll.add(jsonObjectThree);
|
||||
}
|
||||
|
||||
JSONObject sort = new JSONObject();
|
||||
Map<String,Object> mapSort = new HashMap<>();
|
||||
Map<String,Object> mapSortTemp = new HashMap<>();
|
||||
mapSort.put("order","asc");
|
||||
mapSortTemp.put("file_sort.keyword",mapSort);
|
||||
sort.putAll(mapSortTemp);
|
||||
// JSONObject sort = new JSONObject();
|
||||
// Map<String,Object> mapSort = new HashMap<>();
|
||||
// Map<String,Object> mapSortTemp = new HashMap<>();
|
||||
// mapSort.put("order","asc");
|
||||
// mapSortTemp.put("file_sort.keyword",mapSort);
|
||||
// sort.putAll(mapSortTemp);
|
||||
|
||||
Integer pageNo = searchVO.getPageNo();
|
||||
Integer pageSize = searchVO.getPageSize();
|
||||
IPage page = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, null,searchVO.getCut(),sort);
|
||||
IPage page = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, null,searchVO.getCut());
|
||||
return page;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private IPage getiPage(String selectValue, String selectValueTwo, JSONArray queryMapJson,
|
||||
JSONArray should, Integer pageNo, Integer pageSize, String paragraphFlag,
|
||||
String cut,JSONObject querySort) {
|
||||
String cut) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
//基础添加封装
|
||||
if ("paragraphFlag".equals(paragraphFlag)) {
|
||||
@@ -525,14 +549,13 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
} else {
|
||||
jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJson, null, null);
|
||||
}
|
||||
JSONArray jsonArraySort = new JSONArray();
|
||||
jsonArraySort.add(querySort);
|
||||
// JSONArray jsonArraySort = new JSONArray();
|
||||
// jsonArraySort.add(querySort);
|
||||
|
||||
//1. 条件,分页
|
||||
JSONObject queryObject = jeroElasticsearchTemplate.buildQuery(null,
|
||||
jsonObject,
|
||||
null,
|
||||
jsonArraySort,
|
||||
pageNo-1,
|
||||
pageSize);
|
||||
//2. 数据查询
|
||||
@@ -1039,12 +1062,12 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
}
|
||||
|
||||
//排序
|
||||
JSONObject sort = new JSONObject();
|
||||
Map<String,Object> mapSort = new HashMap<>();
|
||||
Map<String,Object> mapSortTemp = new HashMap<>();
|
||||
mapSort.put("order","asc");
|
||||
mapSortTemp.put("file_sort.keyword",mapSort);
|
||||
sort.putAll(mapSortTemp);
|
||||
// JSONObject sort = new JSONObject();
|
||||
// Map<String,Object> mapSort = new HashMap<>();
|
||||
// Map<String,Object> mapSortTemp = new HashMap<>();
|
||||
// mapSort.put("order","asc");
|
||||
// mapSortTemp.put("file_sort.keyword",mapSort);
|
||||
// sort.putAll(mapSortTemp);
|
||||
|
||||
int pageNo = Integer.parseInt(map.get("pageNo").toString());
|
||||
int pageSize = Integer.parseInt(map.get("pageSize").toString());
|
||||
@@ -1069,7 +1092,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
String paragraphFlag = "paragraphFlag";
|
||||
|
||||
|
||||
IPage iPage = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, paragraphFlag,(String) map.get("cut"),sort);
|
||||
IPage iPage = getiPage(selectValue, selectValueTwo, queryMapJsonAll, null, pageNo, pageSize, paragraphFlag,(String) map.get("cut"));
|
||||
return iPage;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user