Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
eed45154
Commit
eed45154
authored
Jul 28, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
d515135b
f2cff67c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
4 deletions
+36
-4
ThemeQo.java
...c/main/java/com/tanpu/community/api/beans/qo/ThemeQo.java
+4
-1
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+7
-1
ESService.java
...main/java/com/tanpu/community/service/base/ESService.java
+3
-2
BizUtils.java
...vice/src/main/java/com/tanpu/community/util/BizUtils.java
+22
-0
No files found.
community-api/src/main/java/com/tanpu/community/api/beans/qo/ThemeQo.java
View file @
eed45154
...
...
@@ -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
;
}
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
eed45154
...
...
@@ -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
;
...
...
community-service/src/main/java/com/tanpu/community/service/base/ESService.java
View file @
eed45154
...
...
@@ -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
();
Match
QueryBuilder
contentQb
=
QueryBuilders
.
match
Query
(
"textContent"
,
keyword
);
Match
QueryBuilder
titleQb
=
QueryBuilders
.
match
Query
(
"title"
,
keyword
);
Match
PhraseQueryBuilder
contentQb
=
QueryBuilders
.
matchPhrase
Query
(
"textContent"
,
keyword
);
Match
PhraseQueryBuilder
titleQb
=
QueryBuilders
.
matchPhrase
Query
(
"title"
,
keyword
);
boolQb
.
should
(
contentQb
);
boolQb
.
should
(
titleQb
);
...
...
community-service/src/main/java/com/tanpu/community/util/BizUtils.java
View file @
eed45154
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
""
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment