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

modify

parent 254ad39f
......@@ -327,9 +327,90 @@ class TopicUtils(object):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return list()
@classmethod
def get_tag_aggregation_topic_id_list(cls):
def get_tag_aggregation_topic_id_list(cls,user_id,tag_id,offset,size):
try:
attention_user_id_list = list()
pick_user_id_list = list()
result_dict = TopicUtils.get_related_user_info(user_id, 0, 1)
if len(result_dict["hits"]) == 0:
logging.warning("not find user_id:%d in es!" % int(user_id))
else:
attention_user_info_list = result_dict["hits"][0]["_source"]["attention_user_id_list"]
attention_user_id_list = [item["user_id"] for item in attention_user_info_list]
pick_user_info_list = result_dict["hits"][0]["_source"]["pick_user_id_list"]
pick_user_id_list = [item["user_id"] for item in pick_user_info_list]
q = dict()
q["query"] = dict()
functions_list = [
{
"gauss": {
"update_time": {
"scale": "1d",
"decay": 0.5
}
}
}
]
if len(attention_user_id_list)>0:
functions_list.append(
{
"filter": {"bool": {
"should": {"terms":{"user_id":attention_user_id_list}}}},
"weight": 3,
}
)
if len(pick_user_id_list)>0:
functions_list.append(
{
"filter": {"bool": {
"should": {"terms":{"user_id":pick_user_id_list}}}},
"weight": 2
}
)
query_function_score = {
"query":{
"bool":{
"must": [
{"range": {"content_level": {"gte": 3, "lte": 5}}},
{"term": {"is_online": True}},
{"term": {"is_deleted": False}},
{"term": {"tag_list":tag_id}}
]
}
},
"score_mode": "sum",
"boost_mode": "sum",
"functions": functions_list
}
q["query"]["function_score"] = query_function_score
q["_source"] = {
"include":["id","group_id","user_id","_score"]
}
q["sort"] = [
{
"_script":{
"type":"number",
"script":{
"lang":"painless",
"source":"_score"
}
}
}
]
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="topic", query_body=q,
offset=offset, size=size)
return list()
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
......@@ -7,6 +7,6 @@
"tag_type":{"type":"long"},
"is_online":{"type":"boolean"},//上线
"is_deleted":{"type":"boolean"},
"near_new_topic_num":{"type":"long"}
"near_new_topic_num":{"type":"long","store": true}
}
}
\ No newline at end of file
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