Commit d326f0fe authored by 刘基明's avatar 刘基明

Merge remote-tracking branch 'origin/dev' into dev

parents b845c3f0 ab13575d
...@@ -103,8 +103,10 @@ public class ThemeManager { ...@@ -103,8 +103,10 @@ public class ThemeManager {
Integer from = (pageNo - 1) * pageSize; Integer from = (pageNo - 1) * pageSize;
ThemeFullSearchResp resp = new ThemeFullSearchResp(); ThemeFullSearchResp resp = new ThemeFullSearchResp();
String[] keywords = StringUtils.split(keyword, " ");
// 按时间倒叙查询 // 按时间倒叙查询
List<ESThemeQo> esIds = esService.queryThemeIdByContentAndTitle(keyword, from, pageSize * 5); List<ESThemeQo> esIds = esService.queryThemeIdByContentAndTitle(keywords, from, pageSize * 5);
if (esIds.isEmpty()) { if (esIds.isEmpty()) {
return resp; return resp;
} }
...@@ -123,7 +125,7 @@ public class ThemeManager { ...@@ -123,7 +125,7 @@ public class ThemeManager {
}); });
// 截取关键词出现的那一部分段落 // 截取关键词出现的那一部分段落
for (ThemeQo theme : resp.themes) { for (ThemeQo theme : resp.themes) {
theme.briefContent4FullSearch = BizUtils.getThemeContent(keyword, theme); theme.briefContent4FullSearch = BizUtils.getThemeContent(keywords, theme);
} }
excludeIds.addAll(resp.themes.stream().map(ThemeQo::getThemeId).collect(Collectors.toList())); excludeIds.addAll(resp.themes.stream().map(ThemeQo::getThemeId).collect(Collectors.toList()));
......
...@@ -42,14 +42,13 @@ public class ESService { ...@@ -42,14 +42,13 @@ public class ESService {
helper.insert(String.valueOf(qo.themeType), qo.themeId, JSON.toJSONString(qo)); helper.insert(String.valueOf(qo.themeType), qo.themeId, JSON.toJSONString(qo));
} }
public List<ESThemeQo> queryThemeIdByContentAndTitle(String keyword, int from, int size) { public List<ESThemeQo> queryThemeIdByContentAndTitle(String[] keywords, int from, int size) {
SearchSourceBuilder search = new SearchSourceBuilder(); SearchSourceBuilder search = new SearchSourceBuilder();
BoolQueryBuilder boolQb = QueryBuilders.boolQuery(); BoolQueryBuilder boolQb = QueryBuilders.boolQuery();
// 如果关键词带空格,则拆分 // 如果关键词带空格,则拆分
String[] ks = StringUtils.split(keyword, ' '); for (String k : keywords) {
for (String k : ks) {
MatchPhraseQueryBuilder contentQb = QueryBuilders.matchPhraseQuery("textContent", k); MatchPhraseQueryBuilder contentQb = QueryBuilders.matchPhraseQuery("textContent", k);
MatchPhraseQueryBuilder titleQb = QueryBuilders.matchPhraseQuery("title", k); MatchPhraseQueryBuilder titleQb = QueryBuilders.matchPhraseQuery("title", k);
boolQb.should(contentQb); boolQb.should(contentQb);
......
...@@ -18,9 +18,10 @@ public class BizUtils { ...@@ -18,9 +18,10 @@ public class BizUtils {
return list.subList(start, realEnd); return list.subList(start, realEnd);
} }
public static String getThemeContent(String keyword, ThemeQo theme) { public static String getThemeContent(String[] keywords, ThemeQo theme) {
for (ThemeContentQo paragraph : theme.content) { for (ThemeContentQo paragraph : theme.content) {
if (paragraph.getType().equals(RelTypeEnum.TEXT.type)) { if (paragraph.getType().equals(RelTypeEnum.TEXT.type)) {
for (String keyword : keywords) {
int idx = paragraph.getValue().indexOf(keyword); int idx = paragraph.getValue().indexOf(keyword);
if (idx == -1) { if (idx == -1) {
...@@ -34,6 +35,7 @@ public class BizUtils { ...@@ -34,6 +35,7 @@ public class BizUtils {
} }
} }
} }
}
return ""; return "";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment