Commit 24a32996 authored by 段英荣's avatar 段英荣

add query_topic_by_user_similarity

parent 59e9675f
...@@ -93,7 +93,7 @@ class TopicUtils(object): ...@@ -93,7 +93,7 @@ class TopicUtils(object):
return [] return []
@classmethod @classmethod
def get_recommend_topic_ids(cls,user_id,offset,size,query=None,query_type=TopicPageType.FIND_PAGE,filter_topic_id_list=[],test_score=False): def get_recommend_topic_ids(cls,user_id,offset,size,query=None,query_type=TopicPageType.FIND_PAGE,filter_topic_id_list=[],test_score=False,must_topic_id_list=[]):
""" """
:需增加打散逻辑 :需增加打散逻辑
:remark:获取首页推荐帖子列表 :remark:获取首页推荐帖子列表
...@@ -212,6 +212,12 @@ class TopicUtils(object): ...@@ -212,6 +212,12 @@ class TopicUtils(object):
"boost_mode": "sum", "boost_mode": "sum",
"functions": functions_list "functions": functions_list
} }
if len(must_topic_id_list) > 0:
query_function_score["query"]["bool"]["must"] = {
"terms":{
"id": must_topic_id_list
}
}
if len(filter_topic_id_list)>0: if len(filter_topic_id_list)>0:
query_function_score["query"]["bool"]["must_not"] = { query_function_score["query"]["bool"]["must_not"] = {
"terms":{ "terms":{
......
...@@ -346,3 +346,24 @@ def topic_search(filters, nfilters=None, sorts_by=None, offset=0, size=10): ...@@ -346,3 +346,24 @@ def topic_search(filters, nfilters=None, sorts_by=None, offset=0, size=10):
except: except:
logging.error("catch exception, err_msg:%s" % traceback.format_exc()) logging.error("catch exception, err_msg:%s" % traceback.format_exc())
return {"topic_ids": []} return {"topic_ids": []}
@bind("physical/search/query_topic_by_user_similarity")
def query_topic_by_user_similarity(topic_similarity_score_dict, offset=0, size=10):
"""
:remark 按帖子所属用户相似度召回帖子
:param tag_id:
:param offset:
:param size:
:return:
"""
try:
must_topic_id_list = list(topic_similarity_score_dict.keys())
topic_id_dict = TopicUtils.get_recommend_topic_ids(user_id=-1, offset=offset, size=size,must_topic_id_list=must_topic_id_list)
recommend_topic_ids = list(topic_id_dict.keys())
return {"recommend_topic_ids":recommend_topic_ids}
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"recommend_topic_id": []}
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