Commit 5329f831 authored by Kai's avatar Kai

update

parent 4acc4604
...@@ -337,7 +337,7 @@ class TopicUtils(object): ...@@ -337,7 +337,7 @@ class TopicUtils(object):
@classmethod @classmethod
def userful_tag_topic_list(cls, user_id, have_read_topic_list, size, def userful_tag_topic_list(cls, user_id, have_read_topic_list, size,
index_type="topic-high-star",routing=None): index_type="topic-high-star",routing=None,useful_tag_list =[]):
""" """
:remark 帖子详情页推荐列表,缺少按时间衰减 :remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id: :param user_id:
...@@ -350,22 +350,22 @@ class TopicUtils(object): ...@@ -350,22 +350,22 @@ class TopicUtils(object):
""" """
try: try:
es_cli_obj = ESPerform.get_cli() es_cli_obj = ESPerform.get_cli()
useful_tag_list = list() # useful_tag_list = list()
q = dict() # q = dict()
q["query"] = { # q["query"] = {
"term": { # "term": {
"user_id": user_id # "user_id": user_id
} # }
} # }
#
q["_source"] = { # q["_source"] = {
"include": ["useful_tag_list"] # "include": ["useful_tag_list"]
} # }
result_dict = ESPerform.get_search_results(es_cli_obj, "user", q, 0, 1) # result_dict = ESPerform.get_search_results(es_cli_obj, "user", q, 0, 1)
if len(result_dict["hits"]) == 0: # if len(result_dict["hits"]) == 0:
logging.warning("not find user_id:%d in es!" % int(user_id)) # logging.warning("not find user_id:%d in es!" % int(user_id))
else: # else:
useful_tag_list = result_dict["hits"][0]["_source"]["useful_tag_list"] # useful_tag_list = result_dict["hits"][0]["_source"]["useful_tag_list"]
if len(useful_tag_list) == 0: if len(useful_tag_list) == 0:
return [] return []
else: else:
......
...@@ -48,7 +48,7 @@ def get_discover_page_topic_ids(user_id, device_id, size, query_type=TopicPageTy ...@@ -48,7 +48,7 @@ def get_discover_page_topic_ids(user_id, device_id, size, query_type=TopicPageTy
def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query=None, def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query=None,
query_type=TopicPageType.HOME_RECOMMEND,promote_topic_list = [],disable_collpase=False,usefulrecall = -1): query_type=TopicPageType.HOME_RECOMMEND,promote_topic_list = [],disable_collpase=False,usefulrecall = -1,useful_tag_list =[]):
try: try:
topic_star_routing = "6" topic_star_routing = "6"
index_type = "topic-high-star" index_type = "topic-high-star"
...@@ -90,7 +90,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query ...@@ -90,7 +90,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
# 有用标签召回 # 有用标签召回
if usefulrecall != -1: if usefulrecall != -1:
useful_topic_id_list = TopicUtils.userful_tag_topic_list(user_id, have_read_topic_id_list, 4, useful_topic_id_list = TopicUtils.userful_tag_topic_list(user_id, have_read_topic_id_list, 4,
"topic-high-star", "6") "topic-high-star", "6",useful_tag_list=useful_tag_list)
# user_similar_score_redis_key = "physical:user_similar_score:user_id:" + str(user_id) # user_similar_score_redis_key = "physical:user_similar_score:user_id:" + str(user_id)
# redis_user_similar_score_redis_val = redis_client.get(user_similar_score_redis_key) # redis_user_similar_score_redis_val = redis_client.get(user_similar_score_redis_key)
# user_similar_score_redis_list = json.loads( # user_similar_score_redis_list = json.loads(
...@@ -192,7 +192,7 @@ def query_tag_id_by_topic(offset=0, size=10, topic_id_list=[], user_id=-1): ...@@ -192,7 +192,7 @@ def query_tag_id_by_topic(offset=0, size=10, topic_id_list=[], user_id=-1):
@bind("physical/search/home_recommend") @bind("physical/search/home_recommend")
def home_recommend(device_id="", user_id=-1, offset=0, size=10, query_type=TopicPageType.HOME_RECOMMEND,promote_topic_list=[],usefulrecall = -1): def home_recommend(device_id="", user_id=-1, offset=0, size=10, query_type=TopicPageType.HOME_RECOMMEND,promote_topic_list=[],usefulrecall = -1,useful_tag_list=[]):
""" """
:remark:首页推荐,目前只推荐日记 :remark:首页推荐,目前只推荐日记
:param session_id: :param session_id:
...@@ -230,9 +230,9 @@ def home_recommend(device_id="", user_id=-1, offset=0, size=10, query_type=Topic ...@@ -230,9 +230,9 @@ def home_recommend(device_id="", user_id=-1, offset=0, size=10, query_type=Topic
recommend_topic_ids = have_read_topic_id_list[0:size] recommend_topic_ids = have_read_topic_id_list[0:size]
else: else:
if usefulrecall != -1: if usefulrecall != -1 and len(useful_tag_list)>0:
recommend_topic_ids,rank_topic_ids,useful_topic_ids = get_home_recommend_topic_ids(user_id, device_id, tag_id=0, offset=0, size=size, recommend_topic_ids,rank_topic_ids,useful_topic_ids = get_home_recommend_topic_ids(user_id, device_id, tag_id=0, offset=0, size=size,
query_type=query_type,promote_topic_list=promote_topic_list,usefulrecall=usefulrecall) query_type=query_type,promote_topic_list=promote_topic_list,usefulrecall=usefulrecall,useful_tag_list=useful_tag_list)
return {"linucb_topic_ids": recommend_topic_ids,"rank_topic_ids":rank_topic_ids,"useful_topic_ids":useful_topic_ids} return {"linucb_topic_ids": recommend_topic_ids,"rank_topic_ids":rank_topic_ids,"useful_topic_ids":useful_topic_ids}
else: else:
recommend_topic_ids,rank_topic_ids = get_home_recommend_topic_ids(user_id, device_id, tag_id=0, offset=0, size=size, recommend_topic_ids,rank_topic_ids = get_home_recommend_topic_ids(user_id, device_id, tag_id=0, offset=0, size=size,
......
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