Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
streamingUserPortrait
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵威
streamingUserPortrait
Commits
96cafa2c
Commit
96cafa2c
authored
Feb 05, 2021
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate answer
parent
f7e12461
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
67 deletions
+106
-67
Main.scala
src/main/scala/com.gmei.up/Main.scala
+8
-7
ES.scala
src/main/scala/com.gmei.up/utils/ES.scala
+95
-59
User.scala
src/main/scala/com.gmei.up/utils/User.scala
+3
-1
No files found.
src/main/scala/com.gmei.up/Main.scala
View file @
96cafa2c
...
...
@@ -30,8 +30,7 @@ class UserInfoDeserializationSchema extends KafkaDeserializationSchema[UserInfo]
object
Main
{
def
main
(
args
:
Array
[
String
])
:
Unit
=
{
// println("###############")
// val query = ES.generateDiaryQuery(List("光子嫩肤", "水光针"), List("丰胸", "胸部塑身"), -1)
// query
// val query = ES.generateAnswerRequest(List("光子嫩肤", "水光针"), List("丰胸", "胸部塑身"))
// println("###############")
val
env
=
StreamExecutionEnvironment
.
getExecutionEnvironment
...
...
@@ -57,12 +56,14 @@ object Main {
val
secondDemands
=
user
.
secondDemands
.
toList
println
(
user
.
deviceId
)
println
(
projects
.
mkString
(
" "
))
if
((
projects
.
size
>
0
)
||
(
secondDemands
.
size
>
0
))
{
val
diaryQuery
=
ES
.
generateDiaryQuery
(
projects
,
secondDemands
,
-
1
)
val
tractateQuery
=
ES
.
generateTractateQuery
(
projects
,
secondDemands
)
ES
.
test
(
diaryQuery
,
tractateQuery
)
}
val
diaryReq
=
ES
.
generateDiaryRequest
(
projects
,
secondDemands
,
user
.
cityId
)
val
tractateReq
=
ES
.
generateTractateRequest
(
projects
,
secondDemands
)
val
answerReq
=
ES
.
generateAnswerRequest
(
projects
,
secondDemands
)
ES
.
test
(
diaryReq
,
tractateReq
,
answerReq
)
println
(
"########################"
)
user
.
deviceId
}
// stream.print
...
...
src/main/scala/com.gmei.up/utils/ES.scala
View file @
96cafa2c
...
...
@@ -59,21 +59,23 @@ object ES {
}
}
def
test
(
diary
Query
:
SearchRequest
,
tractateQuery
:
String
)
=
{
def
test
(
diary
Request
:
SearchRequest
,
tractateRequest
:
SearchRequest
,
answerRequest
:
SearchRequest
)
=
{
// TODO read from config
val
client
:
ElasticClient
=
ESClient
.
create
(
"172.16.52.33"
,
9200
,
"elastic"
,
"gengmei!@#"
)
val
bb
=
multi
(
diaryQuery
,
search
(
"gm-dbmw-tractate-read"
).
source
(
tractateQuery
)
val
multiReq
=
multi
(
diaryRequest
,
tractateRequest
,
answerRequest
)
println
(
bb
.
show
)
println
(
diaryQuery
)
println
(
tractateQuery
)
println
(
multiReq
.
show
)
println
(
diaryRequest
)
println
(
tractateRequest
)
println
(
answerRequest
)
// TODO remove await
val
resp
=
client
.
execute
(
bb
).
await
val
resp
=
client
.
execute
(
multiReq
).
await
// println(resp)
...
...
@@ -89,7 +91,7 @@ object ES {
resp
}
def
generateDiary
Query
(
def
generateDiary
Request
(
projects
:
List
[
String
],
secondDemands
:
List
[
String
],
cityId
:
Int
=
-
1
...
...
@@ -154,67 +156,101 @@ object ES {
res
}
def
generateTractate
Query
(
projects
:
List
[
String
],
secondDemands
:
List
[
String
])
:
String
=
{
val
size
=
30
def
generateTractate
Request
(
projects
:
List
[
String
],
secondDemands
:
List
[
String
])
:
SearchRequest
=
{
val
size
=
15
val
includes
=
List
(
"id"
,
"tags_v3"
)
var
scoreListBuffer
:
ListBuffer
[
ScoreFunction
]
=
ListBuffer
.
empty
[
ScoreFunction
]
var
shouldListBuffer
:
ListBuffer
[
Query
]
=
ListBuffer
.
empty
[
Query
]
val
functions
=
new
ListBuffer
[
JObject
]()
val
shoulds
=
new
ListBuffer
[
JObject
]()
if
(
projects
.
size
>
0
)
{
val
promotes
:
List
[
JObject
]
=
List
((
"terms"
->
(
"tags_v3"
->
projects
)),
(
"term"
->
(
"is_promote"
->
true
)))
scoreListBuffer
+=
WeightScore
(
60
).
filter
(
must
(
termsQuery
(
"tags_v3"
,
projects
),
termQuery
(
"is_promote"
,
true
))
)
scoreListBuffer
+=
WeightScore
(
50
).
filter
(
termsQuery
(
"tags_v3"
,
projects
))
shouldListBuffer
+=
TermsQuery
(
"tags_v3"
,
projects
)
}
if
(
secondDemands
.
size
>
0
)
{
scoreListBuffer
+=
WeightScore
(
40
).
filter
(
termsQuery
(
"second_demands"
,
secondDemands
))
shouldListBuffer
+=
TermsQuery
(
"second_demands"
,
secondDemands
)
}
functions
+=
(
"filter"
->
(
"bool"
->
(
"must"
->
promotes
)))
~
(
"weight"
->
60
)
val
res
=
search
(
"gm-dbmw-tractate-read"
)
.
query
{
functionScoreQuery
()
.
functions
(
scoreListBuffer
.
toList
)
.
scoreMode
(
FunctionScoreQueryScoreMode
.
Max
)
.
boostMode
(
CombineFunction
.
Replace
)
.
query
{
boolQuery
()
.
must
(
termQuery
(
"is_online"
,
true
),
rangeQuery
(
"content_level"
).
gte
(
3
)
)
.
not
(
termQuery
(
"show_by_index"
,
2
),
termQuery
(
"status"
,
4
))
.
should
(
shouldListBuffer
.
toList
)
.
minimumShouldMatch
(
1
)
}
}
.
size
(
size
)
.
sourceInclude
(
includes
)
.
sortBy
(
FieldSort
(
"_score"
).
desc
()
)
functions
+=
(
"filter"
->
(
"terms"
->
{
"tags_v3"
->
projects
}))
~
(
"weight"
->
50
)
// println("tractate query")
// println(res.show)
shoulds
+=
(
"terms"
->
(
"tags_v3"
->
projects
))
}
res
}
if
(
secondDemands
.
size
>
0
)
{
functions
+=
(
"filter"
->
(
"terms"
->
(
"second_demands"
->
secondDemands
)))
~
(
"weight"
->
40
)
def
generateAnswerRequest
(
projects
:
List
[
String
],
secondDemands
:
List
[
String
])
:
SearchRequest
=
{
val
size
=
15
val
includes
=
List
(
"id"
,
"tags_v3"
)
var
scoreListBuffer
:
ListBuffer
[
ScoreFunction
]
=
ListBuffer
.
empty
[
ScoreFunction
]
var
shouldListBuffer
:
ListBuffer
[
Query
]
=
ListBuffer
.
empty
[
Query
]
shoulds
+=
(
"terms"
->
(
"second_demands"
->
secondDemands
))
if
(
projects
.
size
>
0
)
{
scoreListBuffer
+=
WeightScore
(
60
).
filter
(
must
(
termsQuery
(
"tags_v3"
,
projects
),
termQuery
(
"is_promote"
,
true
))
)
scoreListBuffer
+=
WeightScore
(
50
).
filter
(
termsQuery
(
"tags_v3"
,
projects
))
shouldListBuffer
+=
TermsQuery
(
"tags_v3"
,
projects
)
}
if
(
secondDemands
.
size
>
0
)
{
scoreListBuffer
+=
WeightScore
(
40
).
filter
(
termsQuery
(
"second_demands"
,
secondDemands
))
shouldListBuffer
+=
TermsQuery
(
"second_demands"
,
secondDemands
)
}
val
query
=
s
"""
{
"query": {
"function_score": {
"functions": ${pretty(render(functions.toList))},
"boost_mode": "replace",
"score_mode": "max",
"query": {
"bool": {
"should": ${pretty(render(shoulds.toList))},
"minimum_should_match": 1,
"must": [
{
"term": {
"is_online": "true"
}
},
{
"terms": {
"content_level": [6, 5, 4, 3.5, 3]
}
}
],
"must_not": [
{ "term": { "status": 4 } },
{ "term": { "show_by_index": 2 } }
]
}
val
res
=
search
(
"gm-dbmw-tractate-read"
)
.
query
{
functionScoreQuery
()
.
functions
(
scoreListBuffer
.
toList
)
.
scoreMode
(
FunctionScoreQueryScoreMode
.
Max
)
.
boostMode
(
CombineFunction
.
Replace
)
.
query
{
boolQuery
()
.
must
(
termQuery
(
"is_online"
,
true
),
rangeQuery
(
"content_level"
).
gte
(
3
),
rangeQuery
(
"content_length"
).
gte
(
30
)
)
.
not
(
termQuery
(
"show_by_index"
,
2
))
.
should
(
shouldListBuffer
.
toList
)
.
minimumShouldMatch
(
1
)
}
}
}
},
"size": ${size},
"_source": {"include": ${pretty(render(includes))}}
}
"""
.
stripMargin
.
size
(
size
)
.
sourceInclude
(
includes
)
.
sortBy
(
FieldSort
(
"_score"
).
desc
(),
FieldSort
(
"has_picture"
).
desc
(),
FieldSort
(
"smart_rank_v2"
).
desc
(),
FieldSort
(
"good_click"
).
desc
()
)
// println("tractate query:")
// println(query)
query
// println("answer query")
// println(res.show)
res
}
}
src/main/scala/com.gmei.up/utils/User.scala
View file @
96cafa2c
...
...
@@ -5,6 +5,8 @@ case class UserInfo(
action
:
String
,
logTime
:
Double
,
eventCn
:
String
,
cityId
:
Int
,
secondDemands
:
Array
[
String
],
projects
:
Array
[
String
]
projects
:
Array
[
String
],
bussinessTags
:
Array
[
String
]
)
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