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
d326f0fe
Commit
d326f0fe
authored
Jul 30, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev' into dev
parents
b845c3f0
ab13575d
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 @
d326f0fe
...
@@ -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
(
keyword
s
,
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
(
keyword
s
,
theme
);
}
}
excludeIds
.
addAll
(
resp
.
themes
.
stream
().
map
(
ThemeQo:
:
getThemeId
).
collect
(
Collectors
.
toList
()));
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 @
d326f0fe
...
@@ -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
);
...
...
community-service/src/main/java/com/tanpu/community/util/BizUtils.java
View file @
d326f0fe
...
@@ -18,19 +18,21 @@ public class BizUtils {
...
@@ -18,19 +18,21 @@ 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
))
{
int
idx
=
paragraph
.
getValue
().
indexOf
(
keyword
);
for
(
String
keyword
:
keywords
)
{
int
idx
=
paragraph
.
getValue
().
indexOf
(
keyword
);
if
(
idx
==
-
1
)
{
continue
;
if
(
idx
==
-
1
)
{
}
else
if
(
idx
<
30
)
{
continue
;
// 如果关键词在段落偏头部的部分,则全部返回给前端,前端自由展示
}
else
if
(
idx
<
30
)
{
return
paragraph
.
getValue
();
// 如果关键词在段落偏头部的部分,则全部返回给前端,前端自由展示
}
else
{
return
paragraph
.
getValue
();
// 否则,保留关键词 向前20个字符
}
else
{
return
"..."
+
paragraph
.
getValue
().
substring
(
idx
-
20
);
// 否则,保留关键词 向前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