Commit 111bbf4f authored by 段英荣's avatar 段英荣

Merge branch 'duanyr' into 'master'

Duanyr

See merge request alpha/physical!74
parents d48972a4 0af6a951
......@@ -238,13 +238,14 @@ class TopicUtils(object):
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="topic", query_body=q,
offset=offset, size=size)
if len(result_dict["hits"])>0:
return [item["_source"] for item in result_dict["hits"]]
else:
return []
topic_id_dict = dict()
for item in result_dict["hits"]:
topic_id_dict[item["_source"]["id"]] = item["_source"]["group_id"]
return topic_id_dict
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
return dict()
@classmethod
def get_topic_detail_recommend_list(cls,user_id,topic_id,topic_tag_list,topic_group_id,topic_user_id,filter_topic_user_id,offset,size,es_cli_obj=None):
......
......@@ -26,10 +26,10 @@ def get_discover_page_topic_ids(user_id,device_id,size,query_type=TopicPageType.
have_read_topic_id_list = json.loads(redis_field_val_list[0]) if redis_field_val_list[0] else []
recommend_topic_ids = []
topic_id_list = TopicUtils.get_recommend_topic_ids(user_id=user_id, offset=0, size=size,query_type=query_type,filter_topic_id_list=have_read_topic_id_list)
topic_id_dict = TopicUtils.get_recommend_topic_ids(user_id=user_id, offset=0, size=size,query_type=query_type,filter_topic_id_list=have_read_topic_id_list)
for item in topic_id_list:
recommend_topic_ids.append(item["id"])
for topic_id in topic_id_dict:
recommend_topic_ids.append(topic_id)
have_read_topic_id_list.extend(recommend_topic_ids)
redis_dict = {
......@@ -63,17 +63,17 @@ def get_home_recommend_topic_ids(user_id,device_id,offset,size,query=None,query_
last_offset_num = int(redis_field_val_list[0]) if redis_field_val_list[0] else -1
recommend_topic_ids = []
topic_id_list = TopicUtils.get_recommend_topic_ids(user_id, offset, size*size,query,query_type=query_type)
topic_id_dict = TopicUtils.get_recommend_topic_ids(user_id, offset, size*size,query,query_type=query_type)
have_read_group_id_set = set()
unread_topic_id_list = list()
unread_topic_id_dict = dict()
have_read_topic_id_set = set()
ori_unread_topic_id_list = list()
ori_unread_topic_id_dict = list()
if redis_field_val_list[1] and offset>0:
if (user_id>0 and offset==last_offset_num) or user_id==-1:
ori_unread_topic_id_list = json.loads(redis_field_val_list[1])
topic_id_list = ori_unread_topic_id_list + topic_id_list
ori_unread_topic_id_dict = json.loads(redis_field_val_list[1])
topic_id_dict = ori_unread_topic_id_dict.update(topic_id_dict)
for have_read_item in redis_field_val_list[2:]:
if have_read_item:
......@@ -84,36 +84,36 @@ def get_home_recommend_topic_ids(user_id,device_id,offset,size,query=None,query_
# 当前页用户数量
cur_page_user_num = 0
for item in topic_id_list:
if item["group_id"] in have_read_group_id_set:
unread_topic_id_list.append(item)
for topic_id in topic_id_dict:
if topic_id_dict[topic_id] in have_read_group_id_set:
unread_topic_id_dict[topic_id] = topic_id_dict[topic_id]
else:
if item["id"] not in have_read_topic_id_set:
if isinstance(item["group_id"],int) and item["group_id"]>0 and cur_page_group_num<(size*0.9):
have_read_group_id_set.add(item["group_id"])
have_read_topic_id_set.add(item["id"])
if topic_id not in have_read_topic_id_set:
if isinstance(topic_id_dict[topic_id],int) and topic_id_dict[topic_id]>0 and cur_page_group_num<(size*0.9):
have_read_group_id_set.add(topic_id_dict[topic_id])
have_read_topic_id_set.add(topic_id)
cur_page_group_num += 1
recommend_topic_ids.append(item["id"])
elif item["group_id"]<=0 and cur_page_user_num<(size*0.1):
recommend_topic_ids.append(topic_id)
elif topic_id_dict[topic_id] and cur_page_user_num<(size*0.1):
cur_page_user_num += 1
recommend_topic_ids.append(item["id"])
recommend_topic_ids.append(topic_id)
else:
unread_topic_id_list.append(item)
unread_topic_id_dict[topic_id] = topic_id_dict[topic_id]
if len(recommend_topic_ids) >= size:
break
if len(recommend_topic_ids) < size and len(unread_topic_id_list)>0:
recommend_len = len(recommend_topic_ids)
offi_unread_topic_id = [item["id"] for item in unread_topic_id_list[:(size-recommend_len)]]
recommend_topic_ids = recommend_topic_ids + offi_unread_topic_id
unread_topic_id_list = unread_topic_id_list[(size-recommend_len):]
offi_unread_topic_id_dict = dict()
if len(recommend_topic_ids) < size and len(unread_topic_id_dict)>0:
for unread_topic_id in unread_topic_id_dict:
if len(recommend_topic_ids)<size:
recommend_topic_ids.append(unread_topic_id)
else:
offi_unread_topic_id_dict[unread_topic_id] = unread_topic_id_dict[unread_topic_id]
if user_id==-1:
unread_topic_id_list = ori_unread_topic_id_list + unread_topic_id_list
redis_dict = {
"unread_topic_id":json.dumps(unread_topic_id_list),
"unread_topic_id":json.dumps(offi_unread_topic_id_dict),
"last_offset_num":offset+size,
offset: json.dumps(recommend_topic_ids)
}
......
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