Commit 279e49ab authored by lixiaofang's avatar lixiaofang

Merge branch 'master' into hotword

parents 8c600a7b 580c06fe
...@@ -260,7 +260,7 @@ class TopicUtils(object): ...@@ -260,7 +260,7 @@ class TopicUtils(object):
query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()] query_fields = ['^'.join((k, str(v))) for (k, v) in multi_fields.items()]
multi_match = { multi_match = {
'query': query, 'query': query,
'type': 'cross_fields', 'type': 'best_fields',
'operator': 'and', 'operator': 'and',
'fields': query_fields, 'fields': query_fields,
} }
...@@ -337,7 +337,7 @@ class TopicUtils(object): ...@@ -337,7 +337,7 @@ class TopicUtils(object):
@classmethod @classmethod
def userful_tag_topic_list(cls, user_id, have_read_topic_list, size, def userful_tag_topic_list(cls, user_id, have_read_topic_list, size,
index_type="topic-high-star",routing=None): index_type="topic-high-star",routing=None,useful_tag_list =[]):
""" """
:remark 帖子详情页推荐列表,缺少按时间衰减 :remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id: :param user_id:
...@@ -350,22 +350,22 @@ class TopicUtils(object): ...@@ -350,22 +350,22 @@ class TopicUtils(object):
""" """
try: try:
es_cli_obj = ESPerform.get_cli() es_cli_obj = ESPerform.get_cli()
useful_tag_list = list() # useful_tag_list = list()
q = dict() # q = dict()
q["query"] = { # q["query"] = {
"term": { # "term": {
"user_id": user_id # "user_id": user_id
} # }
} # }
#
q["_source"] = { # q["_source"] = {
"include": ["useful_tag_list"] # "include": ["useful_tag_list"]
} # }
result_dict = ESPerform.get_search_results(es_cli_obj, "user", q, 0, 1) # result_dict = ESPerform.get_search_results(es_cli_obj, "user", q, 0, 1)
if len(result_dict["hits"]) == 0: # if len(result_dict["hits"]) == 0:
logging.warning("not find user_id:%d in es!" % int(user_id)) # logging.warning("not find user_id:%d in es!" % int(user_id))
else: # else:
useful_tag_list = result_dict["hits"][0]["_source"]["useful_tag_list"] # useful_tag_list = result_dict["hits"][0]["_source"]["useful_tag_list"]
if len(useful_tag_list) == 0: if len(useful_tag_list) == 0:
return [] return []
else: else:
...@@ -375,7 +375,7 @@ class TopicUtils(object): ...@@ -375,7 +375,7 @@ class TopicUtils(object):
"must": [ "must": [
{"term": {"is_online": True}}, {"term": {"is_online": True}},
{"term": {"is_deleted": False}}, {"term": {"is_deleted": False}},
{"terms": {"tag_list": useful_tag_list}}, {"terms": {"useful_tag_list": useful_tag_list}},
{"term":{"content_level":6}} {"term":{"content_level":6}}
], ],
"must_not": { "must_not": {
......
...@@ -206,10 +206,9 @@ class Topic(models.Model): ...@@ -206,10 +206,9 @@ class Topic(models.Model):
def get_tag_name_list(self, tag_id_list): def get_tag_name_list(self, tag_id_list):
try: try:
tag_name_list = list() tag_name_list = list()
for i in range(0, len(tag_name_list), 1000): for i in range(0, len(tag_id_list), 100):
query_results = Tag.objects.using(settings.SLAVE_DB_NAME).filter(id__in=tag_id_list[i:i + 1000]) query_terms_list = list(Tag.objects.using(settings.SLAVE_DB_NAME).filter(id__in=tag_id_list[i:i + 100],is_online=True,is_deleted=False).values_list("name",flat=True))
for item in query_results: tag_name_list.extend(query_terms_list)
tag_name_list.append(item)
return tag_name_list return tag_name_list
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