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

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

parents d515135b f2cff67c
......@@ -23,7 +23,6 @@ public class ThemeQo implements Serializable {
@ApiModelProperty(value = "主题ID")
public String themeId;
@ApiModelProperty(value = "被转发的主题")
public String formerThemeId;
......@@ -116,4 +115,8 @@ public class ThemeQo implements Serializable {
@ApiModelProperty("工作室简介")
private String workshopIntroduction;//工作室简介
// 搜索页用
// 使用关键词搜索时,在列表页展示的简要内容,内容带关键字.
public String briefContent4FullSearch;
}
......@@ -94,7 +94,6 @@ public class ThemeManager {
ThemeFullSearchResp resp = new ThemeFullSearchResp();
// 按时间倒叙查询
// todo redis
List<ESThemeQo> esIds = esService.queryThemeIdByContentAndTitle(keyword, from, pageSize * 5);
if (esIds.isEmpty()) {
return resp;
......@@ -105,7 +104,14 @@ public class ThemeManager {
return !excludeIds.contains(tId);
}).limit(pageSize).collect(Collectors.toList());
List<ThemeQo> themes = ConvertUtil.themeEntitiesToDTOs(themeService.queryByThemeIds(filterEsIds));
resp.themes = convertEntityToQo(themeService.queryByThemeIds(filterEsIds), userId);
// 截取关键词出现的那一部分段落
for (ThemeQo theme : resp.themes) {
theme.briefContent4FullSearch = BizUtils.getThemeContent(keyword, theme);
}
resp.excludeIds.addAll(filterEsIds);
return resp;
......
......@@ -9,6 +9,7 @@ import com.tanpu.community.dao.entity.community.ThemeEntity;
import com.tanpu.community.model.ESWrapper;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchPhraseQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
......@@ -44,8 +45,8 @@ public class ESService {
SearchSourceBuilder search = new SearchSourceBuilder();
BoolQueryBuilder boolQb = QueryBuilders.boolQuery();
MatchQueryBuilder contentQb = QueryBuilders.matchQuery("textContent", keyword);
MatchQueryBuilder titleQb = QueryBuilders.matchQuery("title", keyword);
MatchPhraseQueryBuilder contentQb = QueryBuilders.matchPhraseQuery("textContent", keyword);
MatchPhraseQueryBuilder titleQb = QueryBuilders.matchPhraseQuery("title", keyword);
boolQb.should(contentQb);
boolQb.should(titleQb);
......
package com.tanpu.community.util;
import com.alibaba.fastjson.JSON;
import com.tanpu.community.api.beans.qo.ThemeContentQo;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.enums.RelTypeEnum;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
......@@ -15,4 +18,23 @@ public class BizUtils {
int realEnd = Math.min(start + size, list.size());
return list.subList(start, realEnd);
}
public static String getThemeContent(String keyword, ThemeQo theme) {
for (ThemeContentQo paragraph : theme.content) {
if (paragraph.getType().equals(RelTypeEnum.TEXT.type)) {
int idx = paragraph.getValue().indexOf(keyword);
if (idx == -1) {
continue;
} else if (idx < 30) {
// 如果关键词在段落偏头部的部分,则全部返回给前端,前端自由展示
return paragraph.getValue();
} else {
// 否则,保留关键词 向前20个字符
return paragraph.getValue().substring(idx - 20);
}
}
}
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