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