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
ab13575d
Commit
ab13575d
authored
Jul 30, 2021
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
关键词full search 增加对多关键词搜索支持
parent
ca40b021
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
16 deletions
+19
-16
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+4
-2
ESService.java
...main/java/com/tanpu/community/service/base/ESService.java
+2
-3
BizUtils.java
...vice/src/main/java/com/tanpu/community/util/BizUtils.java
+13
-11
No files found.
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
ab13575d
...
...
@@ -103,8 +103,10 @@ public class ThemeManager {
Integer
from
=
(
pageNo
-
1
)
*
pageSize
;
ThemeFullSearchResp
resp
=
new
ThemeFullSearchResp
();
String
[]
keywords
=
StringUtils
.
split
(
keyword
,
" "
);
// 按时间倒叙查询
List
<
ESThemeQo
>
esIds
=
esService
.
queryThemeIdByContentAndTitle
(
keyword
,
from
,
pageSize
*
5
);
List
<
ESThemeQo
>
esIds
=
esService
.
queryThemeIdByContentAndTitle
(
keyword
s
,
from
,
pageSize
*
5
);
if
(
esIds
.
isEmpty
())
{
return
resp
;
}
...
...
@@ -123,7 +125,7 @@ public class ThemeManager {
});
// 截取关键词出现的那一部分段落
for
(
ThemeQo
theme
:
resp
.
themes
)
{
theme
.
briefContent4FullSearch
=
BizUtils
.
getThemeContent
(
keyword
,
theme
);
theme
.
briefContent4FullSearch
=
BizUtils
.
getThemeContent
(
keyword
s
,
theme
);
}
excludeIds
.
addAll
(
resp
.
themes
.
stream
().
map
(
ThemeQo:
:
getThemeId
).
collect
(
Collectors
.
toList
()));
...
...
community-service/src/main/java/com/tanpu/community/service/base/ESService.java
View file @
ab13575d
...
...
@@ -42,14 +42,13 @@ public class ESService {
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
();
BoolQueryBuilder
boolQb
=
QueryBuilders
.
boolQuery
();
// 如果关键词带空格,则拆分
String
[]
ks
=
StringUtils
.
split
(
keyword
,
' '
);
for
(
String
k
:
ks
)
{
for
(
String
k
:
keywords
)
{
MatchPhraseQueryBuilder
contentQb
=
QueryBuilders
.
matchPhraseQuery
(
"textContent"
,
k
);
MatchPhraseQueryBuilder
titleQb
=
QueryBuilders
.
matchPhraseQuery
(
"title"
,
k
);
boolQb
.
should
(
contentQb
);
...
...
community-service/src/main/java/com/tanpu/community/util/BizUtils.java
View file @
ab13575d
...
...
@@ -18,19 +18,21 @@ public class BizUtils {
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
)
{
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
);
for
(
String
keyword
:
keywords
)
{
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
);
}
}
}
}
...
...
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