Commit 5165bfc2 authored by Kai's avatar Kai

update

parent 26f999f1
...@@ -220,7 +220,7 @@ class TopicUtils(object): ...@@ -220,7 +220,7 @@ class TopicUtils(object):
{ {
"filter": {"bool": { "filter": {"bool": {
"should": {"term": {"user_id": topic_user_id}}}}, "should": {"term": {"user_id": topic_user_id}}}},
"weight": 30000 "weight": 5000
} }
) )
query_function_score = { query_function_score = {
...@@ -425,6 +425,131 @@ class TopicUtils(object): ...@@ -425,6 +425,131 @@ class TopicUtils(object):
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
@classmethod
def top_get_topic_detail_recommend_list(cls, user_id, topic_id,have_read_topic_list, size, es_cli_obj=None,
index_type="topic", routing=None,collection_topic_tag_list = [],topic_tag_list = [],
topic_user_id =-1):
"""
:remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
:param topic_tag_list:
:param topic_group_id:
:param topic_user_id:
:param offset:
:param size:
:return:
"""
try:
if not es_cli_obj:
es_cli_obj = ESPerform.get_cli()
q = dict()
q["query"] = dict()
# logging.warning("topic_tag_list:%s"%str(topic_tag_list))
functions_list = [
{
"linear": {
"create_time": {
"scale": "1d",
"decay": 0.5
}
}
}
]
# if len(topic_tag_list) > 0:
# functions_list.append(
# {
# "filter": {"bool": {
# "should": {"terms": {"tag_list": topic_tag_list}}}},
# "weight": 5000
# }
# )
# if topic_user_id != -1:
# functions_list.append(
# {
# "filter": {"bool": {
# "should": {"term": {"user_id": topic_user_id}}}},
# "weight": 5000
# }
# )
if len(topic_tag_list) != 0 or topic_user_id!= -1:
query_function_score = {
"query": {
"bool": {
"must": [
{"range": {"content_level": {"gte": 3, "lte": 6}}},
{"term": {"is_online": True}},
{"term": {"is_deleted": False}}
],
"must_not": {
"terms": {
"id": have_read_topic_list
}
}
}
},
"score_mode": "sum",
"boost_mode": "sum",
"functions": functions_list
}
else:
query_function_score = {
"query": {
"bool": {
"must": [
{"range": {"content_level": {"gte": 4, "lte": 6}}},
{"term": {"is_online": True}},
{"term": {"is_deleted": False}}
],
"must_not": {
"terms": {
"id": have_read_topic_list
}
}
}
},
"score_mode": "sum",
"boost_mode": "sum",
"functions": functions_list
}
if len(topic_tag_list) > 0:
query_function_score["query"]["bool"]["filter"] = {
"terms": {
"tag_list": topic_tag_list
}
}
if topic_user_id != -1:
query_function_score["query"]["bool"]["filter"] = {
"term": {
"user_id": topic_user_id
}
}
q["query"]["function_score"] = query_function_score
if topic_user_id == -1:
q["collapse"] = {
"field": "user_id"
}
q["_source"] = {
"includes": ["id", "pictorial_id", "user_id", "_score"]
}
# "includes": ["id", "pictorial_id", "user_id", "_score", "create_time", "content_level"]
# q['sort'] = [
# {"content_level": {"order": "desc"}},
# {"create_time": {"order": "desc"}}
# ]
result_dict = ESPerform.get_search_results(es_cli_obj, sub_index_name=index_type, query_body=q, size=size, routing=routing)
topic_id_list = list()
for item in result_dict["hits"]:
topic_id_list.append(item["_source"]["id"])
return topic_id_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
@classmethod @classmethod
def get_topic_tag_id_list(cls, topic_id, es_cli_obj=None): def get_topic_tag_id_list(cls, topic_id, es_cli_obj=None):
""" """
......
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