es搜索
This commit is contained in:
+93
-19
@@ -389,11 +389,23 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
for (String field : fieldList) {
|
||||
Map<String, Object> queryMap = new HashMap<>();
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
map2.put(field, selectValue);
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
map3.put("query",selectValue);
|
||||
map3.put("slop",1);
|
||||
map2.put(field, map3);
|
||||
queryMap.put("match_phrase", map2);
|
||||
queryMapJson.add(queryMap);
|
||||
}
|
||||
}
|
||||
// if (StringUtils.isNotBlank(selectValue)) {
|
||||
// for (String field : fieldList) {
|
||||
// Map<String, Object> queryMap = new HashMap<>();
|
||||
// Map<String, Object> map2 = new HashMap<>();
|
||||
// map2.put(field, selectValue);
|
||||
// queryMap.put("match_phrase", map2);
|
||||
// queryMapJson.add(queryMap);
|
||||
// }
|
||||
// }
|
||||
if(CollectionUtils.isNotEmpty(queryMapJson)){
|
||||
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJson);
|
||||
queryMapJsonAll.add(jsonObject);
|
||||
@@ -403,11 +415,23 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
for (String field : fieldList) {
|
||||
Map<String, Object> queryMap = new HashMap<>();
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
map2.put(field, selectValueTwo);
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
map3.put("query",selectValueTwo);
|
||||
map3.put("slop",1);
|
||||
map2.put(field, map3);
|
||||
queryMap.put("match_phrase", map2);
|
||||
queryMapJsonTwo.add(queryMap);
|
||||
}
|
||||
}
|
||||
// if (StringUtils.isNotBlank(selectValueTwo)) {
|
||||
// for (String field : fieldList) {
|
||||
// Map<String, Object> queryMap = new HashMap<>();
|
||||
// Map<String, Object> map2 = new HashMap<>();
|
||||
// map2.put(field, selectValueTwo);
|
||||
// queryMap.put("match_phrase", map2);
|
||||
// queryMapJsonTwo.add(queryMap);
|
||||
// }
|
||||
// }
|
||||
if(CollectionUtils.isNotEmpty(queryMapJsonTwo)){
|
||||
JSONObject jsonObjectTwo = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJsonTwo);
|
||||
queryMapJsonAll.add(jsonObjectTwo);
|
||||
@@ -533,25 +557,36 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
//file_text需要单独处理(截取第一处高亮的前后100个字符)
|
||||
if ("file_text".equals(key)) {
|
||||
//判断value中是否包含搜索中的字符
|
||||
if(value.contains(selectValue)){
|
||||
//截取第一处高亮的前后100个字符
|
||||
value = subFileText(value, selectValue);
|
||||
}else{
|
||||
//第一次搜索的时候file_text中不包含搜索条件的时候将file_text赋值空(此时展示拼接的内容)
|
||||
entry.setValue("");
|
||||
value = "";
|
||||
for (String s : selectValue.split(" ")) {
|
||||
if(value.contains(s)){
|
||||
//截取第一处高亮的前后100个字符
|
||||
value = subFileText(value, s);
|
||||
break;
|
||||
}else{
|
||||
//第一次搜索的时候file_text中不包含搜索条件的时候将file_text赋值空(此时展示拼接的内容)
|
||||
entry.setValue("");
|
||||
value = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
if ("content".equals(key)) {
|
||||
if(value.contains(selectValue)){
|
||||
value = subFileText(value, selectValue);
|
||||
for (String s : selectValue.split(" ")) {
|
||||
if(value.contains(s)){
|
||||
value = subFileText(value, s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
String replacement = "<text class='highlight-class'>" + selectValue + "</text>";
|
||||
valueHighlight = value.replaceAll(selectValue, replacement);
|
||||
for (String s : selectValue.split(" ")) {
|
||||
String replacement = "<text class='highlight-class'>" + s + "</text>";
|
||||
value = value.replaceAll(s, replacement);
|
||||
}
|
||||
|
||||
// String replacement = "<text class='highlight-class'>" + selectValue + "</text>";
|
||||
// valueHighlight = value.replaceAll(selectValue, replacement);
|
||||
}
|
||||
if (ObjectUtils.isNotEmpty(valueHighlight)) {
|
||||
entry.setValue(valueHighlight);
|
||||
if (ObjectUtils.isNotEmpty(value)) {
|
||||
entry.setValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -732,10 +767,10 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
}else if(i <100 && (fileTextInfo.length() - i) >= 100){
|
||||
start = fileTextInfo.substring(0, i);
|
||||
end = fileTextInfo.substring(i, i+100);
|
||||
}else if(i > 100 && (fileTextInfo.length() - i) >= 100){
|
||||
}else if(i >= 100 && (fileTextInfo.length() - i) >= 100){
|
||||
start = fileTextInfo.substring(i-100, i);
|
||||
end = fileTextInfo.substring(i, i+100);
|
||||
}else if(i > 100 && (fileTextInfo.length() - i) < 100){
|
||||
}else if(i >= 100 && (fileTextInfo.length() - i) < 100){
|
||||
start = fileTextInfo.substring(i-100, i);
|
||||
end = fileTextInfo.substring(i, fileTextInfo.length());
|
||||
}
|
||||
@@ -873,12 +908,28 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
for (String s : value.split(",")) {
|
||||
Map<String, Object> queryMap = new HashMap<>();
|
||||
Map<String, Object> queryMapTemp = new HashMap<>();
|
||||
queryMapTemp.put(key, s);
|
||||
Map<String, Object> queryMap3 = new HashMap<>();
|
||||
queryMap3.put("query",s);
|
||||
queryMap3.put("slop",1);
|
||||
queryMapTemp.put(key, queryMap3);
|
||||
queryMap.put("match_phrase", queryMapTemp);
|
||||
queryMapJson.add(queryMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (Map.Entry<String, Object> entry : mapOne.entrySet()) {
|
||||
// String key = entry.getKey();
|
||||
// String value = (String) entry.getValue();
|
||||
// if (ObjectUtils.isNotEmpty(value)) {
|
||||
// for (String s : value.split(",")) {
|
||||
// Map<String, Object> queryMap = new HashMap<>();
|
||||
// Map<String, Object> queryMapTemp = new HashMap<>();
|
||||
// queryMapTemp.put(key, s);
|
||||
// queryMap.put("match_phrase", queryMapTemp);
|
||||
// queryMapJson.add(queryMap);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
if(CollectionUtils.isNotEmpty(queryMapJsonTemp)){
|
||||
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJsonTemp, null, null);
|
||||
queryMapJsonAll.add(jsonObject);
|
||||
@@ -913,7 +964,10 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
for (String s : value.split(",")) {
|
||||
Map<String, Object> queryMap = new HashMap<>();
|
||||
Map<String, Object> queryMapTemp = new HashMap<>();
|
||||
queryMapTemp.put(key, s);
|
||||
Map<String, Object> queryMap3 = new HashMap<>();
|
||||
queryMap3.put("query",s);
|
||||
queryMap3.put("slop",1);
|
||||
queryMapTemp.put(key, queryMap3);
|
||||
queryMap.put("match_phrase", queryMapTemp);
|
||||
queryMapJsonTwo.add(queryMap);
|
||||
}
|
||||
@@ -924,6 +978,26 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
queryMapJsonAll.add(jsonObject);
|
||||
}
|
||||
}
|
||||
// if (ObjectUtils.isNotEmpty(mapTwo)) {
|
||||
// mapTwo.remove("ids");
|
||||
// for (Map.Entry<String, Object> entry : mapTwo.entrySet()) {
|
||||
// String key = entry.getKey();
|
||||
// String value = (String) entry.getValue();
|
||||
// if (ObjectUtils.isNotEmpty(value)) {
|
||||
// for (String s : value.split(",")) {
|
||||
// Map<String, Object> queryMap = new HashMap<>();
|
||||
// Map<String, Object> queryMapTemp = new HashMap<>();
|
||||
// queryMapTemp.put(key, s);
|
||||
// queryMap.put("match_phrase", queryMapTemp);
|
||||
// queryMapJsonTwo.add(queryMap);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if(CollectionUtils.isNotEmpty(queryMapJsonTwo)){
|
||||
// JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(queryMapJsonTwo, null, null);
|
||||
// queryMapJsonAll.add(jsonObject);
|
||||
// }
|
||||
// }
|
||||
|
||||
//ids查询条件
|
||||
if (StringUtils.isNotBlank(ids)) {
|
||||
|
||||
Reference in New Issue
Block a user