Commit 1d0021b8 authored by Kai's avatar Kai

tencent

parent 5165bfc2
......@@ -265,7 +265,56 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
try:
if not isinstance(user_id, int):
user_id = -1
if user_id > 0:
redis_key = "physical:topic_detail_recommend" + ":user_id:" + str(user_id) + "topic_id:"+str(topic_id)
else:
redis_key = "physical:topic_detail_recommend" + ":device_id:" + device_id + "topic_id:"+str(topic_id)
if int(offset) == 0:
have_read_topic_list = list()
# redis_dict = {
# "have_read_topic_id": json.dumps(have_read_topic_list)
# }
redis_client.delete(redis_key)
# redis_client.expire(redis_key, 60 * 60 * 24)
else:
have_read_topic_list = list()
redis_field_list = [b'have_read_topic_list']
have_read_topic_redis_data = redis_client.hmget(redis_key,redis_field_list)
have_read_topic_list = json.loads(have_read_topic_redis_data[0]) if have_read_topic_redis_data[0] else []
es_cli_obj = ESPerform.get_cli()
have_read_topic_list.append(topic_id)
topic_user_result = list()
topic_tag_result = list()
result = list()
if len(topic_tag_list) != 0:
topic_tag_result = TopicUtils.top_get_topic_detail_recommend_list(user_id,topic_id,have_read_topic_list,size,es_cli_obj,
index_type="topic",routing="4,5,6",topic_tag_list = topic_tag_list)
topic_tag_size = len(topic_tag_result)
have_read_topic_list.extend(topic_tag_result)
else:
topic_tag_size = 0
if topic_tag_size <size:
size = size - topic_tag_size
if topic_user_id != -1:
topic_user_result = TopicUtils.top_get_topic_detail_recommend_list(user_id, topic_id, have_read_topic_list,
size, es_cli_obj,
index_type="topic", routing="4,5,6",topic_user_id = topic_user_id
)
topic_user_size = len(topic_user_result)
have_read_topic_list.extend(topic_user_result)
if topic_user_size < size:
size = size - topic_user_size
result = TopicUtils.top_get_topic_detail_recommend_list(user_id, topic_id,
have_read_topic_list,
size, es_cli_obj,
index_type="topic", routing="4,5,6")
have_read_topic_list.extend(result)
# have_read_topic_redis_data = redis_client.get(redis_key)
# have_read_topic_list = json.loads(have_read_topic_redis_data) if have_read_topic_redis_data else []
#
# redis_key = "physical:topic_detail_page_recommend" + ":user_id:" + str(user_id) + ":device_id:" + str(device_id)
# have_read_topic_redis_data = redis_client.get(redis_key)
# have_read_topic_list = json.loads(have_read_topic_redis_data) if have_read_topic_redis_data else []
......@@ -279,21 +328,27 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
# result_list = TopicUtils.get_topic_detail_recommend_list(user_id, topic_id, topic_tag_list, topic_pictorial_id,
# topic_user_id, filter_topic_user_id,
# have_read_topic_list, offset, size, es_cli_obj,index_type="topic",routing="4,5,6")
result_list = TopicUtils.get_recommend_topic_ids(user_id, tag_id=-1, single_size=size, offset=offset, size=size,
topic_user_id=topic_user_id, current_topic_id=topic_id,
topic_tag_list=topic_tag_list)
recommend_topic_ids_list = list()
# if len(result_list) > 0:
# recommend_topic_ids_list = [item["_source"]["id"] for item in result_list]
recommend_topic_ids_list.extend(result_list)
#
# have_read_topic_list.extend(recommend_topic_ids_list)
# result_list = TopicUtils.get_recommend_topic_ids(user_id, tag_id=-1, single_size=size, offset=offset, size=size,
# topic_user_id=topic_user_id, current_topic_id=topic_id,
# topic_tag_list=topic_tag_list)
#
# have_read_topic_len = len(have_read_topic_list)
# if have_read_topic_len > 5000:
# have_read_topic_list = have_read_topic_list[(have_read_topic_len - 5000):]
#
# redis_client.set(redis_key, json.dumps(have_read_topic_list))
# user_recommend_list = TopicUtils.get_recommend_topic_ids(user_id, tag_id=-1, single_size=size, offset=offset, size=size,
# topic_user_id=topic_user_id, current_topic_id=topic_id,
# topic_tag_list=topic_tag_list)
redis_dict = {
"have_read_topic_list": json.dumps(have_read_topic_list),
}
redis_client.hmset(redis_key, redis_dict)
redis_client.expire(redis_key, 60 * 60 * 24)
result_list = []
logging.warning("topic_tag_result:%s" % str(topic_tag_result))
logging.warning("topic_user_result:%s" % str(topic_user_result))
logging.warning("result:%s" % str(result))
recommend_topic_ids_list = list()
recommend_topic_ids_list.extend(topic_tag_result)
recommend_topic_ids_list.extend(topic_user_result)
recommend_topic_ids_list.extend(result)
return {"recommend_topic_ids": recommend_topic_ids_list}
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
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