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
b821c2f1
Commit
b821c2f1
authored
Jul 27, 2021
by
张辰
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改es.index
parent
27fdb913
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
15 deletions
+15
-15
RecommendService.java
...in/java/com/tanpu/community/service/RecommendService.java
+0
-1
ReportLogService.java
...in/java/com/tanpu/community/service/ReportLogService.java
+0
-2
ESHelper.java
.../main/java/com/tanpu/community/service/base/ESHelper.java
+11
-8
ESService.java
...main/java/com/tanpu/community/service/base/ESService.java
+3
-4
application-dev.yml
community-service/src/main/resources/application-dev.yml
+1
-0
No files found.
community-service/src/main/java/com/tanpu/community/service/RecommendService.java
View file @
b821c2f1
...
...
@@ -106,7 +106,6 @@ public class RecommendService {
}
}
//HTTP查询python推荐主题
public
List
<
String
>
refreshPythonRecommendList
(
String
userId
)
{
if
(!
"true"
.
equals
(
enablePython
))
{
...
...
community-service/src/main/java/com/tanpu/community/service/ReportLogService.java
View file @
b821c2f1
...
...
@@ -25,7 +25,5 @@ public class ReportLogService {
.
reportTime
(
LocalDateTime
.
now
())
.
build
();
reportLogMapper
.
insert
(
entity
);
}
}
community-service/src/main/java/com/tanpu/community/service/base/ESHelper.java
View file @
b821c2f1
...
...
@@ -22,6 +22,7 @@ import org.elasticsearch.rest.RestStatus;
import
org.elasticsearch.search.SearchHit
;
import
org.elasticsearch.search.builder.SearchSourceBuilder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.elasticsearch.client.*
;
...
...
@@ -35,14 +36,16 @@ import java.util.Map;
@Service
public
class
ESHelper
{
@Value
(
"${es.index}"
)
private
String
esIndex
;
@Autowired
private
RestHighLevelClient
client
;
public
void
insert
(
String
index
,
String
type
,
String
id
,
String
json
)
{
public
void
insert
(
String
type
,
String
id
,
String
json
)
{
try
{
IndexRequest
req
=
new
IndexRequest
(
i
ndex
);
IndexRequest
req
=
new
IndexRequest
(
esI
ndex
);
if
(
StringUtils
.
isNotBlank
(
id
))
{
req
.
id
(
type
+
"_"
+
id
);
}
...
...
@@ -55,9 +58,9 @@ public class ESHelper {
}
}
public
void
insert
(
String
index
,
String
type
,
String
id
,
Map
<
String
,
Object
>
data
)
{
public
void
insert
(
String
type
,
String
id
,
Map
<
String
,
Object
>
data
)
{
try
{
IndexRequest
req
=
new
IndexRequest
(
i
ndex
);
IndexRequest
req
=
new
IndexRequest
(
esI
ndex
);
if
(
StringUtils
.
isNotBlank
(
id
))
{
req
.
id
(
type
+
"_"
+
id
);
}
...
...
@@ -70,9 +73,9 @@ public class ESHelper {
}
}
public
SearchHit
[]
selectLike
(
S
tring
index
,
S
earchSourceBuilder
builder
)
{
public
SearchHit
[]
selectLike
(
SearchSourceBuilder
builder
)
{
try
{
SearchRequest
req
=
new
SearchRequest
(
i
ndex
);
SearchRequest
req
=
new
SearchRequest
(
esI
ndex
);
req
.
source
(
builder
);
SearchResponse
resp
=
client
.
search
(
req
,
RequestOptions
.
DEFAULT
);
validStatus
(
resp
.
status
(),
RestStatus
.
OK
);
...
...
@@ -149,7 +152,7 @@ public class ESHelper {
search
.
query
(
boolQb
).
from
(
0
).
size
(
50
);
SearchHit
[]
hits
=
helper
.
selectLike
(
"theme"
,
search
);
SearchHit
[]
hits
=
helper
.
selectLike
(
search
);
System
.
out
.
println
(
hits
.
length
);
for
(
SearchHit
hit
:
hits
)
{
System
.
out
.
println
(
hit
.
toString
());
...
...
community-service/src/main/java/com/tanpu/community/service/base/ESService.java
View file @
b821c2f1
...
...
@@ -16,6 +16,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
import
org.elasticsearch.search.sort.SortOrder
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
...
...
@@ -29,8 +30,6 @@ public class ESService {
@Autowired
private
ESHelper
helper
;
private
static
final
String
INDEX_THEME
=
"theme"
;
public
void
insertOrUpdateThemes
(
List
<
ESThemeQo
>
qos
)
{
for
(
ESThemeQo
qo
:
qos
)
{
insertOrUpdateTheme
(
qo
);
...
...
@@ -38,7 +37,7 @@ public class ESService {
}
// 只要设置了_id,则直接覆盖
public
void
insertOrUpdateTheme
(
ESThemeQo
qo
)
{
helper
.
insert
(
INDEX_THEME
,
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
)
{
...
...
@@ -55,7 +54,7 @@ public class ESService {
search
.
query
(
boolQb
).
fetchSource
(
includes
,
excludes
).
sort
(
"createTime"
,
SortOrder
.
DESC
).
from
(
from
).
size
(
size
);
search
.
query
(
boolQb
).
sort
(
"createTime"
,
SortOrder
.
DESC
).
from
(
from
).
size
(
size
);
SearchHit
[]
hits
=
helper
.
selectLike
(
INDEX_THEME
,
search
);
SearchHit
[]
hits
=
helper
.
selectLike
(
search
);
return
Arrays
.
stream
(
hits
).
map
(
h
->
{
return
JsonUtil
.
toBean
(
h
.
getSourceAsString
(),
ESThemeQo
.
class
);
}).
collect
(
Collectors
.
toList
());
...
...
community-service/src/main/resources/application-dev.yml
View file @
b821c2f1
...
...
@@ -97,6 +97,7 @@ es:
port
:
9200
userName
:
1
userPasswd
:
2
index
:
dev
tencent
:
cloud
:
...
...
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