Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
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
钟尚武
physical
Commits
fee3b7d0
Commit
fee3b7d0
authored
Jan 11, 2019
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add batch_recommend_user
parent
0affd82d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
61 deletions
+70
-61
user.py
search/utils/user.py
+68
-58
user.py
search/views/user.py
+2
-3
No files found.
search/utils/user.py
View file @
fee3b7d0
...
...
@@ -10,7 +10,7 @@ from libs.es import ESPerform
class
UserUtils
(
object
):
@classmethod
def
get_batch_attention_user_
dic
t
(
cls
,
user_id_list
,
self_user_id
):
def
get_batch_attention_user_
lis
t
(
cls
,
user_id_list
,
self_user_id
):
"""
:remark 批量用户 关注的 用户列表
:param user_id_list:
...
...
@@ -32,17 +32,25 @@ class UserUtils(object):
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
=
0
,
size
=
len
(
user_id_list
))
attention_user_dict
=
dict
()
self_attention_user_id_list
=
[]
attention_user_dict_list
=
list
()
for
hit_item
in
result_dict
[
"hits"
]:
attention_user_dict
=
dict
()
user_id
=
hit_item
[
"_source"
][
"user_id"
]
attention_user_id_list
=
[
item
[
"user_id"
]
for
item
in
hit_item
[
"_source"
][
"attention_user_id_list"
]]
attention_user_dict
[
user_id
]
=
attention_user_id_list
if
user_id
==
self_user_id
:
self_attention_user_id_list
=
[
item
[
"user_id"
]
for
item
in
hit_item
[
"_source"
][
"attention_user_id_list"
]]
else
:
attention_user_id_list
=
[
item
[
"user_id"
]
for
item
in
hit_item
[
"_source"
][
"attention_user_id_list"
]]
attention_user_dict
[
user_id
]
=
attention_user_id_list
attention_user_dict_list
.
append
(
attention_user_dict
)
return
attention_user_dict
return
[
self_attention_user_id_list
,
attention_user_dict_list
]
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
dict
(
)
return
([],[]
)
@classmethod
...
...
@@ -170,7 +178,7 @@ class UserUtils(object):
@classmethod
def
get_batch_recommend_user_dict
(
cls
,
need_filter_attention_user_id_list
,
attention_user_dict
,
self_user_id
,
offset
,
size
):
def
get_batch_recommend_user_dict
(
cls
,
need_filter_attention_user_id_list
,
attention_user_dict
_list
,
self_user_id
,
offset
,
size
):
"""
:remark 获取批量推荐用户
:param need_filter_attention_user_id_list:
...
...
@@ -182,66 +190,68 @@ class UserUtils(object):
"""
try
:
batch_query_list
=
list
()
for
interesting_user_id
in
attention_user_dict
:
if
interesting_user_id
!=
self_user_id
:
filter_user_id_list
=
need_filter_attention_user_id_list
filter_user_id_list
.
append
(
interesting_user_id
)
q
=
dict
()
q
[
"from"
]
=
offset
q
[
"size"
]
=
size
q
[
"query"
]
=
dict
()
for
interesting_user_item_dict
in
attention_user_dict_list
:
for
interesting_user_id
in
interesting_user_item_dict
:
if
interesting_user_id
!=
self_user_id
:
logging
.
info
(
"duan add,interesting_user_id:
%
d"
%
interesting_user_id
)
filter_user_id_list
=
need_filter_attention_user_id_list
filter_user_id_list
.
append
(
interesting_user_id
)
functions_list
=
[
{
"gauss"
:
{
"latest_topic_time_val"
:
{
"origin"
:
int
(
time
.
time
()),
"scale"
:
"600"
,
"decay"
:
0.1
}
}
}
]
q
=
dict
()
q
[
"from"
]
=
offset
q
[
"size"
]
=
size
q
[
"query"
]
=
dict
()
if
len
(
attention_user_dict
[
interesting_user_id
])
>
0
:
functions_list
.
append
(
functions_list
=
[
{
"filter"
:{
"bool"
:{
"should"
:{
"terms"
:{
"user_id"
:
attention_user_dict
[
interesting_user_id
]}}
"gauss"
:
{
"latest_topic_time_val"
:
{
"origin"
:
int
(
time
.
time
()),
"scale"
:
"600"
,
"decay"
:
0.1
}
},
"weight"
:
10
}
}
)
]
query_function_score
=
{
"query"
:
{
"bool"
:
{
"must"
:
[
{
"term"
:
{
"is_recommend"
:
True
}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"term"
:
{
"is_shadow"
:
False
}}
],
"must_not"
:{
"terms"
:{
"user_id"
:
filter_user_id_list
if
len
(
interesting_user_item_dict
[
interesting_user_id
])
>
0
:
functions_list
.
append
(
{
"filter"
:{
"bool"
:{
"should"
:{
"terms"
:{
"user_id"
:
interesting_user_item_dict
[
interesting_user_id
]}}
}
},
"weight"
:
10
}
)
query_function_score
=
{
"query"
:
{
"bool"
:
{
"must"
:
[
{
"term"
:
{
"is_recommend"
:
True
}},
{
"term"
:
{
"is_online"
:
True
}},
{
"term"
:
{
"is_deleted"
:
False
}},
{
"term"
:
{
"is_shadow"
:
False
}}
],
"must_not"
:{
"terms"
:{
"user_id"
:
filter_user_id_list
}
}
}
}
},
"score_mode"
:
"sum"
,
"boost_mode"
:
"sum"
,
"functions"
:
functions_list
}
q
[
"query"
][
"function_score"
]
=
query_function_score
q
[
"_source"
]
=
{
"include"
:[
"user_id"
]
}
},
"score_mode"
:
"sum"
,
"boost_mode"
:
"sum"
,
"functions"
:
functions_list
}
q
[
"query"
][
"function_score"
]
=
query_function_score
q
[
"_source"
]
=
{
"include"
:[
"user_id"
]
}
batch_query_list
.
append
(
q
)
batch_query_list
.
append
(
q
)
index_name
=
ESPerform
.
get_official_index_name
(
"user"
,
"read"
)
search_header_dict
=
{
'index'
:
index_name
,
'type'
:
"_doc"
}
...
...
search/views/user.py
View file @
fee3b7d0
...
...
@@ -55,15 +55,14 @@ def batch_recommend_user(self_user_id,interesting_user_id_list,offset=0,size=10)
self_user_id
=
-
1
#获取关注用户列表
attention_user_dict
=
UserUtils
.
get_batch_attention_user_dic
t
(
interesting_user_id_list
,
self_user_id
)
(
need_filter_attention_user_id_list
,
attention_user_dict_list
)
=
UserUtils
.
get_batch_attention_user_lis
t
(
interesting_user_id_list
,
self_user_id
)
#去除自身及感兴趣的用户ID
need_filter_attention_user_id_list
=
attention_user_dict
[
self_user_id
]
if
self_user_id
in
attention_user_dict
else
list
()
need_filter_attention_user_id_list
.
append
(
self_user_id
)
recommend_user_list
=
UserUtils
.
get_batch_recommend_user_dict
(
need_filter_attention_user_id_list
=
need_filter_attention_user_id_list
,
attention_user_dict
=
attention_user_dic
t
,
recommend_user_list
=
UserUtils
.
get_batch_recommend_user_dict
(
need_filter_attention_user_id_list
=
need_filter_attention_user_id_list
,
attention_user_dict
_list
=
attention_user_dict_lis
t
,
self_user_id
=
self_user_id
,
offset
=
offset
,
size
=
size
)
...
...
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