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
4adc2d99
Commit
4adc2d99
authored
Dec 05, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
fc3decbb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
20 deletions
+31
-20
user.py
search/utils/user.py
+25
-13
user.py
search/views/user.py
+6
-7
No files found.
search/utils/user.py
View file @
4adc2d99
...
...
@@ -9,7 +9,7 @@ from libs.es import ESPerform
class
UserUtils
(
object
):
@classmethod
def
get_attention_user_list
(
cls
,
use
_id_list
):
def
get_attention_user_list
(
cls
,
use
r_id_list
,
self_user_id
):
"""
:remark 获取指定用户列表 关注的 用户列表
:param user_id:
...
...
@@ -19,32 +19,36 @@ class UserUtils(object):
q
=
dict
()
q
[
"query"
]
=
{
"terms"
:{
"user_id"
:
use_id_list
"user_id"
:
use
r
_id_list
}
}
q
[
"_source"
]
=
{
"include"
:[
"attention_user_id_list"
]
"include"
:[
"attention_user_id_list"
,
"user_id"
]
}
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
=
0
,
size
=
1
)
result_dict
=
ESPerform
.
get_search_results
(
ESPerform
.
get_cli
(),
"user"
,
q
,
offset
=
0
,
size
=
len
(
user_id_list
)
)
attention_user_id_list
=
[]
self_attention_user_id_list
=
[]
recursion_attention_user_id_list
=
[]
for
hit_item
in
result_dict
[
"hits"
]:
attention_user_id_list
=
[
item
[
"user_id"
]
for
item
in
hit_item
[
"_source"
][
"attention_user_id_list"
]]
if
hit_item
[
"_source"
][
"user_id"
]
==
self_user_id
:
self_attention_user_id_list
=
[
item
[
"user_id"
]
for
item
in
hit_item
[
"_source"
][
"attention_user_id_list"
]]
else
:
recursion_attention_user_id_list
=
[
item
[
"user_id"
]
for
item
in
hit_item
[
"_source"
][
"attention_user_id_list"
]]
return
attention_user_id_list
return
(
self_attention_user_id_list
,
recursion_attention_user_id_list
)
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
[]
return
([],[])
@classmethod
def
___get_should_term_list
(
cls
,
ori_list
):
def
___get_should_term_list
(
cls
,
ori_list
,
field_name
=
"tag_list"
):
try
:
should_term_list
=
list
()
for
term_id
in
ori_list
:
term_dict
=
{
"term"
:{
"tag_list"
:{
"value"
:
term_id
}
field_name
:{
"value"
:
term_id
}
}
}
should_term_list
.
append
(
term_dict
)
...
...
@@ -54,7 +58,7 @@ class UserUtils(object):
return
[]
@classmethod
def
get_recommend_user_list
(
cls
,
attention_user_id_list
,
recursion_attention_user_id_list
,
offset
,
size
):
def
get_recommend_user_list
(
cls
,
self_
attention_user_id_list
,
recursion_attention_user_id_list
,
offset
,
size
):
"""
:remark 获取推荐用户列表
:param attention_user_id_list:
...
...
@@ -65,7 +69,7 @@ class UserUtils(object):
q
=
dict
()
q
[
"query"
]
=
dict
()
recursion_attention_user_list
=
cls
.
___get_should_term_list
(
recursion_attention_user_id_list
)
recursion_attention_user_list
=
cls
.
___get_should_term_list
(
recursion_attention_user_id_list
,
field_name
=
"user_id"
)
functions_list
=
[
{
...
...
@@ -75,6 +79,14 @@ class UserUtils(object):
}
},
"weight"
:
10
},
{
"gauss"
:
{
"latest_topic_time_val"
:
{
"scale"
:
"600"
,
"decay"
:
0.1
}
}
}
]
query_function_score
=
{
...
...
@@ -87,7 +99,7 @@ class UserUtils(object):
"minimum_should_match"
:
2
,
"must_not"
:{
"terms"
:{
"user_id"
:
attention_user_id_list
"user_id"
:
self_
attention_user_id_list
}
}
}
...
...
search/views/user.py
View file @
4adc2d99
...
...
@@ -13,21 +13,20 @@ from search.utils.common import *
@bind
(
"physical/search/recommend_user"
)
def
recommend_user
(
user_id
=-
1
,
offset
=
0
,
size
=
10
):
def
recommend_user
(
self_user_id
,
interesting_user_id
,
offset
=
0
,
size
=
10
):
"""
:remark: 点关注推荐用户,缺少按时间排序策略
:param user_id:
:remark 点关注推荐用户,缺少按时间排序策略
:param self_user_id:
:param interesting_user_id:
:param offset:
:param size:
:return:
"""
try
:
#获取关注用户列表
attention_user_id_list
=
UserUtils
.
get_attention_user_list
([
user_id
])
#关注的用户 关注用户列表
recursion_attention_user_id_list
=
UserUtils
.
get_attention_user_list
(
attention_user_id_list
)
(
self_attention_user_id_list
,
recursion_attention_user_id_list
)
=
UserUtils
.
get_attention_user_list
([
self_user_id
,
interesting_user_id
],
self_user_id
)
recommend_user_list
=
UserUtils
.
get_recommend_user_list
(
attention_user_id_list
,
recursion_attention_user_id_list
,
offset
,
size
)
recommend_user_list
=
UserUtils
.
get_recommend_user_list
(
self_
attention_user_id_list
,
recursion_attention_user_id_list
,
offset
,
size
)
return
recommend_user_list
except
:
...
...
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