Commit 45d32a16 authored by 段英荣's avatar 段英荣

modify home_query

parent eadbbcd8
...@@ -122,7 +122,7 @@ class TopicUtils(object): ...@@ -122,7 +122,7 @@ class TopicUtils(object):
@classmethod @classmethod
def get_recommend_topic_ids(cls,user_id,tag_id,offset,size,single_size,query=None,query_type=TopicPageType.FIND_PAGE, def get_recommend_topic_ids(cls,user_id,tag_id,offset,size,single_size,query=None,query_type=TopicPageType.FIND_PAGE,
filter_topic_id_list=[],test_score=False,must_topic_id_list=[],recommend_tag_list=[], filter_topic_id_list=[],test_score=False,must_topic_id_list=[],recommend_tag_list=[],
user_similar_score_list=[],index_type="topic",routing=None,attention_tag_list=[],current_topic_id =-1,topic_tag_list =[],topic_user_id =-1): user_similar_score_list=[],index_type="topic",routing=None,attention_tag_list=[],current_topic_id =-1,topic_tag_list =[],topic_user_id =-1,disable_collpase=False):
""" """
:remark:获取首页推荐帖子列表 :remark:获取首页推荐帖子列表
:param user_id: :param user_id:
...@@ -304,7 +304,7 @@ class TopicUtils(object): ...@@ -304,7 +304,7 @@ class TopicUtils(object):
query_function_score["query"]["bool"]["should"] = [ query_function_score["query"]["bool"]["should"] = [
{'multi_match': multi_match}, {'multi_match': multi_match},
{"term": {"tag_list": tag_id}}, {"term": {"tag_list": tag_id}},
{"term": {"user_nick_name": query}} {"term": {"user_nick_name_pre": query}}
] ]
query_function_score["query"]["bool"]["minimum_should_match"] = 1 query_function_score["query"]["bool"]["minimum_should_match"] = 1
else: else:
...@@ -317,6 +317,7 @@ class TopicUtils(object): ...@@ -317,6 +317,7 @@ class TopicUtils(object):
{"term": {"is_operation_home_recommend": True}} {"term": {"is_operation_home_recommend": True}}
] ]
q["query"]["function_score"] = query_function_score q["query"]["function_score"] = query_function_score
if not disable_collpase:
q["collapse"] = { q["collapse"] = {
"field": "user_id" "field": "user_id"
} }
......
...@@ -46,7 +46,7 @@ def get_discover_page_topic_ids(user_id, device_id, size, query_type=TopicPageTy ...@@ -46,7 +46,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, def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query=None,
query_type=TopicPageType.HOME_RECOMMEND): query_type=TopicPageType.HOME_RECOMMEND,disable_collpase=False):
try: try:
if query is None: if query is None:
if user_id>0: if user_id>0:
...@@ -113,7 +113,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query ...@@ -113,7 +113,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
topic_id_list = list() topic_id_list = list()
rank_topic_id_list = TopicUtils.get_recommend_topic_ids(user_id=user_id, tag_id=tag_id, offset=0, size=size, rank_topic_id_list = TopicUtils.get_recommend_topic_ids(user_id=user_id, tag_id=tag_id, offset=0, size=size,
single_size=size,query=query, query_type=query_type, single_size=size,query=query, query_type=query_type,
filter_topic_id_list=have_read_topic_id_list,index_type="topic-high-star",routing="4,5,6",attention_tag_list=attention_tag_list) filter_topic_id_list=have_read_topic_id_list,index_type="topic-high-star",routing="4,5,6",attention_tag_list=attention_tag_list,disable_collpase=disable_collpase)
if len(recommend_topic_list) == 6 and query is None: if len(recommend_topic_list) == 6 and query is None:
if (size < 11): if (size < 11):
...@@ -244,6 +244,11 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10) ...@@ -244,6 +244,11 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10)
device_id = "" device_id = ""
recommend_topic_ids = get_home_recommend_topic_ids(user_id, device_id, tag_id, offset=offset, size=size, query=query) recommend_topic_ids = get_home_recommend_topic_ids(user_id, device_id, tag_id, offset=offset, size=size, query=query)
#todo 因为按用户打散,会出现召回数量少于请求数的情况,再次去掉打散请求
if len(recommend_topic_ids)>0 and len(recommend_topic_ids)<size:
recommend_topic_ids = get_home_recommend_topic_ids(user_id, device_id, tag_id, offset=offset, size=size,
query=query,disable_collpase=True)
return {"recommend_topic_ids": recommend_topic_ids} return {"recommend_topic_ids": recommend_topic_ids}
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) 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