Commit 6edfff1d authored by 段英荣's avatar 段英荣

modify

parent 40cea006
......@@ -144,49 +144,13 @@ class TypeInfo(object):
else:
if data:
if self.type == "topic":
# q = {
# "query":{
# "term":{
# "id": data["id"]
# }
# },
# "_source":{
# "include":["content_level"]
# }
# }
# search_results = ESPerform.get_search_results(ESPerform.get_cli(),sub_index_name="topic-star",query_body=q,offset=0,size=1)
# if len(search_results["hits"]) > 0:
# ori_topic_star = search_results["hits"][0]["_source"]["content_level"]
# else:
ori_topic_star = redis_client.hget(self.physical_topic_star, data["id"])
if ori_topic_star:
ori_topic_star = str(ori_topic_star, encoding="utf-8")
# else:
# q = {
# "query":{
# "term":{
# "id": data["id"]
# }
# },
# "_source":{
# "includes":["content_level"]
# }
# }
# search_results = ESPerform.get_search_results(ESPerform.get_cli(),sub_index_name="topic-star",query_body=q,offset=0,size=1)
# if len(search_results["hits"]) > 0:
# ori_topic_star = search_results["hits"][0]["_source"]["content_level"]
if not ori_topic_star:
# data_list = [
# {
# "id": data["id"],
# "content_level": data["content_level"]
# }
# ]
# ESPerform.es_helpers_bulk(ESPerform.get_cli(), data_list, "topic-star")
redis_client.hset(self.physical_topic_star, data["id"], data["content_level"])
else:
# int_ori_topic_star = int(str(ori_topic_star, encoding="utf-8"))
int_ori_topic_star = int(ori_topic_star)
if int_ori_topic_star != data["content_level"]:
old_data = copy.deepcopy(data)
......@@ -199,18 +163,16 @@ class TypeInfo(object):
if int_ori_topic_star>=4:
topic_data_high_star_list.append(old_data)
redis_client.hset(self.physical_topic_star, data["id"], data["content_level"])
# data_list = [
# {
# "id": data["id"],
# "content_level": data["content_level"]
# }
# ]
# ESPerform.es_helpers_bulk(ESPerform.get_cli(), data_list, "topic-star")
if data["content_level"] and int(data["content_level"])>=4:
topic_data_high_star_list.append(data)
data_list.append(data)
elif self.type == "tag" or self.type == "tag_v1":
(res, begin_res) = data
data_list.append(res)
data_list.append(begin_res)
else:
data_list.append(data)
return (data_list,topic_data_high_star_list)
......
......@@ -11,7 +11,7 @@ from trans2es.models.topic import Topic
from trans2es.models.tag import TopicTag,CommunityTagType,CommunityTagTypeRelation
import datetime
from django.conf import settings
import copy
class TagTransfer(object):
......@@ -34,15 +34,20 @@ class TagTransfer(object):
res["id"] = instance.id
begin_tag_name_terms_list = list()
tag_name_terms_list = list()
for i in range(len(instance.name)):
for j in range(i,len(instance.name)+1):
name_term = instance.name[i:j].strip()
if name_term:
tag_name_terms_list.append(name_term.lower())
if i == 0:
begin_tag_name_terms_list.append(name_term.lower())
else:
tag_name_terms_list.append(name_term.lower())
res["suggest"] = {
"input":tag_name_terms_list,
"weight": 1,
"contexts":{
"is_online": [instance.is_online],
"is_deleted": [instance.is_deleted]
......@@ -80,7 +85,13 @@ class TagTransfer(object):
res["collection"] = instance.collection
res["is_ai"] = instance.is_ai
res["is_own"] = instance.is_own
return res
begin_res = copy.deepcopy(res)
begin_res["id"] = str(begin_res["id"]) + "_begin"
begin_res["suggest"]["input"] = begin_tag_name_terms_list
begin_res["suggest"]["weight"] = 10
return (res, begin_res)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return dict()
\ No newline at end of file
return (dict(), dict())
\ 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