Commit 4adc2d99 authored by 段英荣's avatar 段英荣

modify

parent fc3decbb
......@@ -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,user_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":user_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
}
}
}
......
......@@ -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:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment