Commit d0bcfa5e authored by 段英荣's avatar 段英荣

modify

parent ec2cb251
......@@ -69,6 +69,22 @@ class TopicUtils(object):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
@classmethod
def ___get_should_term_list(cls,ori_list):
try:
should_term_list = list()
for term_id in ori_list:
term_dict = {
"term":{
"tag_list":{"value":term_id}
}
}
should_term_list.append(term_dict)
return should_term_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
@classmethod
def get_recommend_topic_ids(cls,user_id,offset,size,is_first_time,group_topic_ids_index,not_group_topic_ids_index,query=None):
"""
......@@ -115,6 +131,13 @@ class TopicUtils(object):
user_tag_list = result_dict["hits"][0]["_source"]["tag_list"]
q = dict()
q["query"] = dict()
q["query"]["bool"] = {
"must":{
"range": {"content_level": {"gte": 3, "lte": 5}}
}
}
"""
q["filter"] = {
"range": {"content_level": {"gte": 3, "lte": 5}}
}
......@@ -127,28 +150,34 @@ class TopicUtils(object):
q["filter"]["range"]["group_id"] = {
"lt": 0
}
"""
attention_user_id_term_list = cls.___get_should_term_list(attention_chinese_user_id_list + attention_japan_user_id_list + attention_korea_user_id_list)
pick_user_id_term_list = cls.___get_should_term_list(pick_chinese_user_id_list + pick_japan_user_id_list + pick_korea_user_id_list)
same_group_user_id_term_list = cls.___get_should_term_list(same_group_chinese_user_id_list + same_group_japan_user_id_list + same_group_korea_user_id_list)
functions_list = [
{
"filter": {"match": {
"user_id": attention_chinese_user_id_list + attention_japan_user_id_list + attention_korea_user_id_list}},
"filter": {"bool": {
"should": attention_user_id_term_list}},
"weight": 5,
},
{
"filter": {"match": {
"user_id": pick_chinese_user_id_list + pick_japan_user_id_list + pick_korea_user_id_list}},
"user_id": pick_user_id_term_list}},
"weight": 3
},
{
"filter": {"match": {
"user_id": same_group_chinese_user_id_list + same_group_japan_user_id_list + same_group_korea_user_id_list}},
"user_id": same_group_user_id_term_list}},
"weight": 2
}
]
query_tag_term_list = cls.___get_should_term_list(user_tag_list)
query_function_score = {
"query": {
"match": {
"tag_list": user_tag_list
"bool": {
"should": query_tag_term_list
}
},
"score_mode": "sum",
......@@ -156,9 +185,7 @@ class TopicUtils(object):
"functions": functions_list
}
q["query"] = {
"function_score": query_function_score
}
q["query"]["function_score"] = query_function_score
if query is not None:#搜索帖子
multi_fields = {
......
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