Commit 92ec6cc3 authored by 段英荣's avatar 段英荣

Merge branch 'test' into 'branch_0520'

# Conflicts:
#   search/utils/topic.py
parents 96aa1fa8 c1b48f9f
...@@ -24,5 +24,29 @@ ...@@ -24,5 +24,29 @@
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" /> <option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings> </formatting-settings>
</DBN-SQL> </DBN-SQL>
<DBN-PSQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false" />
</DBN-PSQL>
<DBN-SQL>
<case-options enabled="false">
<option name="KEYWORD_CASE" value="lower" />
<option name="FUNCTION_CASE" value="lower" />
<option name="PARAMETER_CASE" value="lower" />
<option name="DATATYPE_CASE" value="lower" />
<option name="OBJECT_CASE" value="preserve" />
</case-options>
<formatting-settings enabled="false">
<option name="STATEMENT_SPACING" value="one_line" />
<option name="CLAUSE_CHOP_DOWN" value="chop_down_if_statement_long" />
<option name="ITERATION_ELEMENTS_WRAPPING" value="chop_down_if_not_single" />
</formatting-settings>
</DBN-SQL>
</code_scheme> </code_scheme>
</component> </component>
\ No newline at end of file
...@@ -18,4 +18,4 @@ def logging_exception(send_to_sentry=True): ...@@ -18,4 +18,4 @@ def logging_exception(send_to_sentry=True):
# send exception info to sentry, fail silently # send exception info to sentry, fail silently
_sentry_client.captureException() _sentry_client.captureException()
except: except:
pass passraven.contrib.django.raven_compat.models
...@@ -14,6 +14,7 @@ from trans2es.models.pictorial import PictorialTopics ...@@ -14,6 +14,7 @@ from trans2es.models.pictorial import PictorialTopics
from libs.cache import redis_client from libs.cache import redis_client
class TopicUtils(object): class TopicUtils(object):
@classmethod @classmethod
...@@ -122,9 +123,11 @@ class TopicUtils(object): ...@@ -122,9 +123,11 @@ class TopicUtils(object):
return {} return {}
@classmethod @classmethod
def get_recommend_topic_ids(cls,user_id,tag_id,offset,size,single_size,query=None,query_type=TopicPageType.HOME_RECOMMEND, def get_recommend_topic_ids(cls, user_id, tag_id, offset, size, single_size, query=None,
filter_topic_id_list=[],test_score=False,must_topic_id_list=[],recommend_tag_list=[], query_type=TopicPageType.HOME_RECOMMEND,
user_similar_score_list=[],index_type="topic",routing=None,attention_tag_list=[],linucb_user_id_list = [],disable_collpase=False): 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=[],
linucb_user_id_list=[], disable_collpase=False):
""" """
:remark:获取首页推荐帖子列表 :remark:获取首页推荐帖子列表
:param user_id: :param user_id:
...@@ -220,7 +223,7 @@ class TopicUtils(object): ...@@ -220,7 +223,7 @@ class TopicUtils(object):
], ],
"minimum_should_match": 1, "minimum_should_match": 1,
"must_not": [ "must_not": [
{"term": {"is_history":True}} {"term": {"is_history": True}}
] ]
} }
}, },
...@@ -236,10 +239,10 @@ class TopicUtils(object): ...@@ -236,10 +239,10 @@ class TopicUtils(object):
} }
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":{"id":filter_topic_id_list}} {"terms": {"id": filter_topic_id_list}}
] ]
if len(linucb_user_id_list)>0: if len(linucb_user_id_list) > 0:
if "must_not" in query_function_score["query"]["bool"]: if "must_not" in query_function_score["query"]["bool"]:
query_function_score["query"]["bool"]["must_not"] += [ query_function_score["query"]["bool"]["must_not"] += [
{"terms": {"user_id": linucb_user_id_list}} {"terms": {"user_id": linucb_user_id_list}}
...@@ -322,7 +325,7 @@ class TopicUtils(object): ...@@ -322,7 +325,7 @@ class TopicUtils(object):
} }
] ]
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name=index_type, query_body=q, result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name=index_type, query_body=q,
offset=offset, size=size,routing=routing) offset=offset, size=size, routing=routing)
topic_id_list = list() topic_id_list = list()
...@@ -335,7 +338,8 @@ class TopicUtils(object): ...@@ -335,7 +338,8 @@ class TopicUtils(object):
@classmethod @classmethod
def get_topic_detail_recommend_list(cls, user_id, topic_id, topic_tag_list, topic_pictorial_id, topic_user_id, def get_topic_detail_recommend_list(cls, user_id, topic_id, topic_tag_list, topic_pictorial_id, topic_user_id,
filter_topic_user_id, have_read_topic_list, offset, size, es_cli_obj=None,index_type="topic",routing=None): filter_topic_user_id, have_read_topic_list, offset, size, es_cli_obj=None,
index_type="topic", routing=None):
""" """
:remark 帖子详情页推荐列表,缺少按时间衰减 :remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id: :param user_id:
...@@ -412,7 +416,7 @@ class TopicUtils(object): ...@@ -412,7 +416,7 @@ class TopicUtils(object):
} }
result_dict = ESPerform.get_search_results(es_cli_obj, sub_index_name=index_type, query_body=q, result_dict = ESPerform.get_search_results(es_cli_obj, sub_index_name=index_type, query_body=q,
offset=offset, size=size,routing=routing) offset=offset, size=size, routing=routing)
return result_dict["hits"] return result_dict["hits"]
except: except:
...@@ -420,9 +424,10 @@ class TopicUtils(object): ...@@ -420,9 +424,10 @@ class TopicUtils(object):
return [] return []
@classmethod @classmethod
def top_get_topic_detail_recommend_list(cls, user_id, topic_id,have_read_topic_list, size, es_cli_obj=None, 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 = [], index_type="topic", routing=None, collection_topic_tag_list=[],
topic_user_id =-1): topic_tag_list=[],
topic_user_id=-1):
""" """
:remark 帖子详情页推荐列表,缺少按时间衰减 :remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id: :param user_id:
...@@ -466,7 +471,7 @@ class TopicUtils(object): ...@@ -466,7 +471,7 @@ class TopicUtils(object):
# "weight": 5000 # "weight": 5000
# } # }
# ) # )
if len(topic_tag_list) != 0 or topic_user_id!= -1: if len(topic_tag_list) != 0 or topic_user_id != -1:
query_function_score = { query_function_score = {
"query": { "query": {
"bool": { "bool": {
...@@ -534,7 +539,8 @@ class TopicUtils(object): ...@@ -534,7 +539,8 @@ class TopicUtils(object):
# {"create_time": {"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) 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() topic_id_list = list()
for item in result_dict["hits"]: for item in result_dict["hits"]:
...@@ -677,7 +683,7 @@ class TopicUtils(object): ...@@ -677,7 +683,7 @@ class TopicUtils(object):
{"term": {"is_deleted": False}}, {"term": {"is_deleted": False}},
] ]
logging.info("get filters:%s"%filters) logging.info("get filters:%s" % filters)
if not filters: if not filters:
return f return f
...@@ -867,21 +873,23 @@ class TopicUtils(object): ...@@ -867,21 +873,23 @@ class TopicUtils(object):
query_body=q, offset=offset, size=size query_body=q, offset=offset, size=size
) )
if len(result_dict["hits"])>0: if len(result_dict["hits"]) > 0:
topic_id_list = [item["_source"]["id"] for item in result_dict["hits"]] topic_id_list = [item["_source"]["id"] for item in result_dict["hits"]]
return (topic_id_list,result_dict["total_count"]) return (topic_id_list, result_dict["total_count"])
elif offset==0 and "pictorial_id" in filters: # 防止帖子同步延迟,画报详情页为空 elif offset == 0 and "pictorial_id" in filters: # 防止帖子同步延迟,画报详情页为空
pictorial_id = int(filters["pictorial_id"]) pictorial_id = int(filters["pictorial_id"])
topic_id_list = list(PictorialTopics.objects.filter(pictorial_id=pictorial_id,is_online=True,is_deleted=False).values_list("topic_id", flat=True)[offset:size]) topic_id_list = list(PictorialTopics.objects.filter(pictorial_id=pictorial_id, is_online=True,
is_deleted=False).values_list("topic_id",
flat=True)[
offset:size])
return (topic_id_list,len(topic_id_list)) return (topic_id_list, len(topic_id_list))
else: else:
return ([], 0) return ([], 0)
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ([],0) return ([], 0)
@classmethod @classmethod
def business_topic_ids(cls, filters, nfilters, sorts_by, offset=0, size=10, index_name="topic", filter_online=True): def business_topic_ids(cls, filters, nfilters, sorts_by, offset=0, size=10, index_name="topic", filter_online=True):
...@@ -969,7 +977,20 @@ class TopicUtils(object): ...@@ -969,7 +977,20 @@ class TopicUtils(object):
} }
} }
}) })
elif k == "drop_score":
if v == "0":
f.append({
"term": {k: v}
})
else:
f.append({
"range": {
"drop_score": {
"gte": v,
}
}
})
else: else:
if isinstance(v, list): if isinstance(v, list):
......
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