Commit 0e06252e authored by 段英荣's avatar 段英荣

modify

parent 468b08e0
......@@ -90,7 +90,7 @@ class TopicUtils(object):
return []
@classmethod
def get_recommend_topic_ids(cls,user_id,offset,size,query=None,query_type=TopicPageType.HOME_RECOMMEND):
def get_recommend_topic_ids(cls,user_id,offset,size,query=None,query_type=TopicPageType.HOME_RECOMMEND,filter_topic_id_list=[]):
"""
:需增加打散逻辑
:remark:获取首页推荐帖子列表
......@@ -190,6 +190,12 @@ class TopicUtils(object):
"boost_mode": "sum",
"functions": functions_list
}
if query_type==TopicPageType.FIND_PAGE and len(filter_topic_id_list)>0:
query_function_score["query"]["bool"]["must_not"] = {
"terms":{
"id": filter_topic_id_list
}
}
if query is not None:#搜索帖子
multi_fields = {
......
......@@ -12,12 +12,47 @@ from libs.cache import redis_client
from search.utils.common import *
def get_home_recommend_topic_ids(user_id,session_id,offset,size,query=None,query_type=TopicPageType.HOME_RECOMMEND):
def get_discover_page_topic_ids(user_id,device_id,size,query_type=TopicPageType.HOME_RECOMMEND):
try:
if user_id == -1:
redis_key = "physical:discover_page" + ":user_id:" + str(user_id) + ":device_id:" + device_id
else:
redis_key = "physical:discover_page" + ":user_id:" + str(user_id)
redis_field_list = [b'have_read_topic_id']
redis_field_val_list = redis_client.hmget(redis_key,redis_field_list)
have_read_topic_id_list = json.loads(redis_field_val_list[0])
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)
for item in topic_id_list:
recommend_topic_ids.append(item["id"])
have_read_topic_id_list.extend(recommend_topic_ids)
redis_dict = {
"have_read_topic_id": json.dumps(have_read_topic_id_list)
}
redis_client.hmset(redis_key,redis_dict)
return recommend_topic_ids
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_home_recommend_topic_ids(user_id,device_id,offset,size,query=None,query_type=TopicPageType.HOME_RECOMMEND):
try:
if query is None:
redis_key = "physical:home_recommend" + ":user_id:" + str(user_id) + ":session_id:" + session_id + ":query_type:" + str(query_type)
if user_id == -1:
redis_key = "physical:home_recommend" + ":user_id:" + str(user_id) + ":device_id:" + device_id + ":query_type:" + str(query_type)
else:
redis_key = "physical:home_recommend" + ":user_id:" + str(user_id) + ":query_type:" + str(query_type)
else:
redis_key = "physical:home_query" + ":user_id:" + str(user_id) + ":session_id:" + session_id + ":query:" + str(query) + ":query_type:" + str(query_type)
if user_id == -1:
redis_key = "physical:home_query" + ":user_id:" + str(user_id) + ":device_id:" + device_id + ":query:" + str(query) + ":query_type:" + str(query_type)
else:
redis_key = "physical:home_query" + ":user_id:" + str(user_id) + ":query:" + str(query) + ":query_type:" + str(query_type)
redis_field_list = [b'last_offset_num', b'unread_topic_id']
for page_id in range(0,offset,size):
......@@ -90,9 +125,32 @@ def get_home_recommend_topic_ids(user_id,session_id,offset,size,query=None,query
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
@bind("physical/search/home_recommend")
def home_recommend(session_id="",user_id=-1,offset=0,size=10,query_type=TopicPageType.HOME_RECOMMEND):
def home_recommend(device_id="",user_id=-1,offset=0,size=10,query_type=TopicPageType.HOME_RECOMMEND):
"""
:remark:首页推荐,目前只推荐日记
:param session_id:
:param user_id:
:param offset:
:param size:
:return:
"""
try:
if not user_id:
user_id=-1
if not isinstance(device_id,str):
device_id = ""
recommend_topic_ids = get_home_recommend_topic_ids(user_id,device_id,offset,size,query_type=query_type)
return {"recommend_topic_ids":recommend_topic_ids}
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"recommend_topic_ids": []}
@bind("physical/search/discover_page")
def discover_page(device_id="",user_id=-1,size=10):
"""
:remark:首页推荐,目前只推荐日记
:param session_id:
......@@ -104,10 +162,10 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10,query_type=TopicPag
try:
if not user_id:
user_id=-1
if not isinstance(session_id,str):
session_id = ""
# if not isinstance(device_id,str):
# session_id = ""
recommend_topic_ids = get_home_recommend_topic_ids(user_id,session_id,offset,size,query_type=query_type)
recommend_topic_ids = get_discover_page_topic_ids(user_id,device_id,size,query_type=TopicPageType.HOME_RECOMMEND)
return {"recommend_topic_ids":recommend_topic_ids}
except:
......@@ -116,7 +174,7 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10,query_type=TopicPag
@bind("physical/search/home_query")
def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
def home_query(device_id="",user_id=-1,query="",offset=0,size=10):
"""
:remark:首页搜索,目前只推荐日记
:param session_id:
......@@ -129,10 +187,10 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
try:
if not user_id:
user_id=-1
if not isinstance(session_id,str):
session_id = ""
if not isinstance(device_id,str):
device_id = ""
recommend_topic_ids = get_home_recommend_topic_ids(user_id,session_id,offset,size,query)
recommend_topic_ids = get_home_recommend_topic_ids(user_id,device_id,offset,size,query)
return {"recommend_topic_ids":recommend_topic_ids}
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