Commit b945e2f5 authored by lixiaofang's avatar lixiaofang

add

parents 70c617b6 afa5c366
...@@ -973,7 +973,18 @@ class TopicUtils(object): ...@@ -973,7 +973,18 @@ class TopicUtils(object):
"order": "desc" "order": "desc"
}, },
}) })
if sorts_by == TOPIC_SEARCH_SORT.TOPIC_ADD_TIME:
sort_rule.append({
"related_billboard.topic_add_createtime": {
"order": "desc",
"nested_path": "related_billboard",
"nested_filter": {
"term": {
"related_billboard.pictorial_id": pictorial_id
}
}
},
})
elif isinstance(sorts_by, list): elif isinstance(sorts_by, list):
for sort_by in sorts_by: for sort_by in sorts_by:
if sort_by == TOPIC_SEARCH_SORT.ID_AEC: if sort_by == TOPIC_SEARCH_SORT.ID_AEC:
...@@ -1068,19 +1079,6 @@ class TopicUtils(object): ...@@ -1068,19 +1079,6 @@ class TopicUtils(object):
}, },
}) })
elif sort_by == TOPIC_SEARCH_SORT.TOPIC_ADD_TIME:
sort_rule.append({
"related_billboard.topic_add_createtime": {
"order": "desc",
"nested_path": "related_billboard",
"nested_filter": {
"term": {
"related_billboard.pictorial_id": pictorial_id
}
}
},
})
logging.info("get picotirial:%s" % sort_rule) logging.info("get picotirial:%s" % sort_rule)
return sort_rule return sort_rule
...@@ -1098,10 +1096,16 @@ class TopicUtils(object): ...@@ -1098,10 +1096,16 @@ class TopicUtils(object):
} }
} }
if sorts_by: if 'pictorial_id' in filters.keys():
sorts = cls.process_sort(sorts_by, pictorial_id=None) if sorts_by:
if sorts: sorts = cls.process_sort(sorts_by, filters["pictorial_id"])
q["sort"] = sorts if sorts:
q["sort"] = sorts
else:
if sorts_by:
sorts = cls.process_sort(sorts_by, pictorial_id=None)
if sorts:
q["sort"] = sorts
result_dict = ESPerform.get_search_results( result_dict = ESPerform.get_search_results(
ESPerform.get_cli(), sub_index_name=index_name, ESPerform.get_cli(), sub_index_name=index_name,
......
...@@ -301,7 +301,7 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10): ...@@ -301,7 +301,7 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
es_cli_obj = ESPerform.get_cli() es_cli_obj = ESPerform.get_cli()
result_dict = ESPerform.get_search_results(es_cli_obj, "topic", q, offset, size) result_dict = ESPerform.get_search_results(es_cli_obj, "topic", q, offset, size)
logging.info("get pictorial_topic_sort res:%s" % result_dict) # logging.info("get pictorial_topic_sort res:%s" % result_dict)
for item in result_dict["hits"]: for item in result_dict["hits"]:
topic_id = item["_source"]["id"] topic_id = item["_source"]["id"]
...@@ -431,3 +431,71 @@ def process_sort(sorts_by): ...@@ -431,3 +431,71 @@ def process_sort(sorts_by):
logging.info("get picotirial:%s" % sort_rule) logging.info("get picotirial:%s" % sort_rule)
return sort_rule return sort_rule
@bind("physical/search/pictorialid_topic")
def pictorial_topic_sort_peoplehot(pictorial_id=-1, user_id=-1, offset=0, size=10):
try:
if not isinstance(pictorial_id, int):
pictorial_id = -1
results = pictorial_topic_sort(pictorial_id=pictorial_id, size=100)
pict_pictorial_ids_list = results["pict_pictorial_ids_list"]
logging.info("get pict_pictorial_ids_list res:%s" % pict_pictorial_ids_list)
q = {
"query": {
"bool": {
"must": [
{"term": {"is_online": True}},
{"term": {"is_deleted": False}},
{"term": {"pictorial_id": pictorial_id}},
{"term": {"user_id": user_id}}
]
}
},
"sort": [
{"related_billboard.total_vote_cnt": {
"order": "desc",
"nested_path": "related_billboard",
"missing": "_last",
"nested_filter": {
"term": {
"related_billboard.pictorial_id": pictorial_id
}
}
}},
{"create_time": {"order": "desc"}}
]
}
# 获取es链接对象
es_cli_obj = ESPerform.get_cli()
result_dict = ESPerform.get_search_results(es_cli_obj, "topic", q, offset, size)
user_pict_pictorial_ids_list = []
for item in result_dict["hits"]:
topic_id = item["_source"]["id"]
user_pict_pictorial_ids_list.append(topic_id)
logging.info("get user_pict_pictorial_ids_list res:%s" % user_pict_pictorial_ids_list)
pictorial_user_topicid_list = list()
for user_id_topic in user_pict_pictorial_ids_list:
if user_id_topic in pict_pictorial_ids_list:
topic_sort = pict_pictorial_ids_list.index(user_id_topic)
pictorial_user_topicid_list.append({"topic_id": user_id_topic, "topic_sort": topic_sort + 1})
else:
index = user_pict_pictorial_ids_list.index(user_id_topic)
pictorial_user_topicid_list.append({"topic_id": user_id_topic, "topic_sort": 100 + index})
return {"pictorial_user_topicid_list": pictorial_user_topicid_list}
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"pict_pictorial_ids_list": []}
...@@ -60,10 +60,14 @@ ...@@ -60,10 +60,14 @@
"type":"nested", "type":"nested",
"properties":{ "properties":{
"pictorial_id":{"type":"long"}, "pictorial_id":{"type":"long"},
"topic_add_createtime":{"type":"long"},
"real_vote_cnt":{"type":"long"}, "real_vote_cnt":{"type":"long"},
"virt_vote_cnt":{"type":"long"}, "virt_vote_cnt":{"type":"long"},
"total_vote_cnt":{"type":"long"} "total_vote_cnt":{"type":"long"}
} }
} }
} }
} }
\ No newline at end of file
...@@ -60,10 +60,14 @@ ...@@ -60,10 +60,14 @@
"type":"nested", "type":"nested",
"properties":{ "properties":{
"pictorial_id":{"type":"long"}, "pictorial_id":{"type":"long"},
"topic_add_createtime":{"type":"long"},
"real_vote_cnt":{"type":"long"}, "real_vote_cnt":{"type":"long"},
"virt_vote_cnt":{"type":"long"}, "virt_vote_cnt":{"type":"long"},
"total_vote_cnt":{"type":"long"} "total_vote_cnt":{"type":"long"}
} }
} }
} }
} }
\ No newline at end of file
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
"type":"nested", "type":"nested",
"properties":{ "properties":{
"pictorial_id":{"type":"long"}, "pictorial_id":{"type":"long"},
"topic_add_time":{"type":"long"}, "topic_add_createtime":{"type":"long"},
"real_vote_cnt":{"type":"long"}, "real_vote_cnt":{"type":"long"},
"virt_vote_cnt":{"type":"long"}, "virt_vote_cnt":{"type":"long"},
"total_vote_cnt":{"type":"long"} "total_vote_cnt":{"type":"long"}
......
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals, absolute_import, print_function from __future__ import unicode_literals, absolute_import, print_function
import time
from django.conf import settings from django.conf import settings
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
...@@ -281,9 +282,6 @@ class Topic(models.Model): ...@@ -281,9 +282,6 @@ class Topic(models.Model):
def get_related_billboard(self): def get_related_billboard(self):
try: try:
# pictorial_ids = Topic.get_pictorial_id(self)
pictorial_id_list = []
related_billboard_list = list() related_billboard_list = list()
pictorials = PictorialTopic.objects.filter(topic_id=self.id).values("pictorial_id", "create_time") pictorials = PictorialTopic.objects.filter(topic_id=self.id).values("pictorial_id", "create_time")
...@@ -293,10 +291,11 @@ class Topic(models.Model): ...@@ -293,10 +291,11 @@ class Topic(models.Model):
topic_id=self.id).values().first() topic_id=self.id).values().first()
if query_result == None: if query_result == None:
related_billboard_list.append({"pictorial_id": pictorial_id.get('pictorial_id', None), "real_vote_cnt": 0, related_billboard_list.append(
"virt_vote_cnt": 0, "total_vote_cnt": 0, {"pictorial_id": pictorial_id.get('pictorial_id', None), "real_vote_cnt": 0,
"topic_add_createtime": int( "virt_vote_cnt": 0, "total_vote_cnt": 0,
time.mktime(pictorial_id.get("create_time", None).timetuple()))}) "topic_add_createtime": int(
time.mktime(pictorial_id.get("create_time", None).timetuple()))})
else: else:
...@@ -310,6 +309,7 @@ class Topic(models.Model): ...@@ -310,6 +309,7 @@ class Topic(models.Model):
return related_billboard_list return related_billboard_list
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
......
...@@ -8,16 +8,15 @@ import logging ...@@ -8,16 +8,15 @@ import logging
import traceback import traceback
from libs.tools import tzlc from libs.tools import tzlc
from trans2es.models.topic import Topic from trans2es.models.topic import Topic
from trans2es.models.tag import TopicTag,CommunityTagType,CommunityTagTypeRelation from trans2es.models.tag import TopicTag, CommunityTagType, CommunityTagTypeRelation
import datetime import datetime
from django.conf import settings from django.conf import settings
class TagTransfer(object): class TagTransfer(object):
@classmethod @classmethod
def get_tag_name_data(cls,instance): def get_tag_name_data(cls, instance):
try: try:
res = dict() res = dict()
res["name"] = instance.name res["name"] = instance.name
...@@ -28,7 +27,7 @@ class TagTransfer(object): ...@@ -28,7 +27,7 @@ class TagTransfer(object):
return dict() return dict()
@classmethod @classmethod
def get_tag_data(cls,instance): def get_tag_data(cls, instance):
try: try:
res = dict() res = dict()
...@@ -36,14 +35,14 @@ class TagTransfer(object): ...@@ -36,14 +35,14 @@ class TagTransfer(object):
tag_name_terms_list = list() tag_name_terms_list = list()
for i in range(len(instance.name)): for i in range(len(instance.name)):
for j in range(i,len(instance.name)+1): for j in range(i, len(instance.name) + 1):
name_term = instance.name[i:j].strip() name_term = instance.name[i:j].strip()
if name_term: if name_term:
tag_name_terms_list.append(name_term.lower()) tag_name_terms_list.append(name_term.lower())
res["suggest"] = { res["suggest"] = {
"input":tag_name_terms_list, "input": tag_name_terms_list,
"contexts":{ "contexts": {
"is_online": [instance.is_online], "is_online": [instance.is_online],
"is_deleted": [instance.is_deleted] "is_deleted": [instance.is_deleted]
} }
...@@ -54,24 +53,27 @@ class TagTransfer(object): ...@@ -54,24 +53,27 @@ class TagTransfer(object):
topic_num = 0 topic_num = 0
res["near_new_topic_num"] = topic_num res["near_new_topic_num"] = topic_num
if instance.is_online==True and instance.is_deleted==False: if instance.is_online == True and instance.is_deleted == False:
topic_id_list = list() topic_id_list = list()
sql_result_results = list(TopicTag.objects.using(settings.SLAVE_DB_NAME).filter( sql_result_results = list(TopicTag.objects.using(settings.SLAVE_DB_NAME).filter(
tag_id=instance.id).values_list("topic_id", "is_online")) tag_id=instance.id).values_list("topic_id", "is_online"))
for topic_id,is_online in sql_result_results: for topic_id, is_online in sql_result_results:
if is_online: if is_online:
topic_id_list.append(topic_id) topic_id_list.append(topic_id)
time_base_val = datetime.datetime.strftime(datetime.datetime.now()+datetime.timedelta(-7), "%Y-%m-%d") time_base_val = datetime.datetime.strftime(datetime.datetime.now() + datetime.timedelta(-7), "%Y-%m-%d")
for topic_begin_index in range(0,len(topic_id_list),100): for topic_begin_index in range(0, len(topic_id_list), 100):
cur_topic_num = Topic.objects.using(settings.SLAVE_DB_NAME).filter(id__in=topic_id_list[topic_begin_index:topic_begin_index+100],create_time__gte=time_base_val).count() cur_topic_num = Topic.objects.using(settings.SLAVE_DB_NAME).filter(
id__in=topic_id_list[topic_begin_index:topic_begin_index + 100],
create_time__gte=time_base_val).count()
topic_num += cur_topic_num topic_num += cur_topic_num
res["near_new_topic_num"] = topic_num res["near_new_topic_num"] = topic_num
tag_type_sql_list = CommunityTagTypeRelation.objects.using(settings.SLAVE_DB_NAME).filter(tag_id=instance.id).values_list("tag_type_id",flat=True) tag_type_sql_list = CommunityTagTypeRelation.objects.using(settings.SLAVE_DB_NAME).filter(
tag_id=instance.id).values_list("tag_type_id", flat=True)
tag_type_list = list() tag_type_list = list()
for tag_type_id in tag_type_sql_list: for tag_type_id in tag_type_sql_list:
tag_type_list.append(tag_type_id) tag_type_list.append(tag_type_id)
...@@ -83,4 +85,4 @@ class TagTransfer(object): ...@@ -83,4 +85,4 @@ class TagTransfer(object):
return res return res
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return dict() return 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