Commit 30fa81b9 authored by 黄凯's avatar 黄凯

Merge branch 'hk' into 'master'

revise usefultag

See merge request alpha/physical!362
parents 55a14f0d 5329f831
......@@ -337,7 +337,7 @@ class TopicUtils(object):
@classmethod
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 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
......@@ -350,22 +350,22 @@ class TopicUtils(object):
"""
try:
es_cli_obj = ESPerform.get_cli()
useful_tag_list = list()
q = dict()
q["query"] = {
"term": {
"user_id": user_id
}
}
q["_source"] = {
"include": ["useful_tag_list"]
}
result_dict = ESPerform.get_search_results(es_cli_obj, "user", q, 0, 1)
if len(result_dict["hits"]) == 0:
logging.warning("not find user_id:%d in es!" % int(user_id))
else:
useful_tag_list = result_dict["hits"][0]["_source"]["useful_tag_list"]
# useful_tag_list = list()
# q = dict()
# q["query"] = {
# "term": {
# "user_id": user_id
# }
# }
#
# q["_source"] = {
# "include": ["useful_tag_list"]
# }
# result_dict = ESPerform.get_search_results(es_cli_obj, "user", q, 0, 1)
# if len(result_dict["hits"]) == 0:
# logging.warning("not find user_id:%d in es!" % int(user_id))
# else:
# useful_tag_list = result_dict["hits"][0]["_source"]["useful_tag_list"]
if len(useful_tag_list) == 0:
return []
else:
......
......@@ -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,
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:
topic_star_routing = "6"
index_type = "topic-high-star"
......@@ -104,7 +104,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
# 有用标签召回
if usefulrecall != -1:
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)
# redis_user_similar_score_redis_val = redis_client.get(user_similar_score_redis_key)
# user_similar_score_redis_list = json.loads(
......@@ -206,7 +206,7 @@ def query_tag_id_by_topic(offset=0, size=10, topic_id_list=[], user_id=-1):
@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:首页推荐,目前只推荐日记
:param session_id:
......@@ -244,9 +244,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]
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,
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}
else:
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