Commit 0725fb40 authored by lixiaofang's avatar lixiaofang

add

parent 65916c36
...@@ -13,7 +13,7 @@ from libs.es import ESPerform ...@@ -13,7 +13,7 @@ from libs.es import ESPerform
@bind("physical/search/query_pictorial") @bind("physical/search/query_pictorial")
def query_group(query="",offset=0,size=10): def query_group(query="", offset=0, size=10):
""" """
:remark:小组搜索排序策略,缺少排序策略 :remark:小组搜索排序策略,缺少排序策略
:param query: :param query:
...@@ -22,7 +22,7 @@ def query_group(query="",offset=0,size=10): ...@@ -22,7 +22,7 @@ def query_group(query="",offset=0,size=10):
:return: :return:
""" """
try: try:
result_dict = GroupUtils.get_group_query_result(query,offset,size) result_dict = GroupUtils.get_group_query_result(query, offset, size)
group_ids_list = [] group_ids_list = []
if len(result_dict["hits"]) > 0: if len(result_dict["hits"]) > 0:
...@@ -31,10 +31,11 @@ def query_group(query="",offset=0,size=10): ...@@ -31,10 +31,11 @@ def query_group(query="",offset=0,size=10):
return {"group_ids": group_ids_list} return {"group_ids": group_ids_list}
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"group_ids":[]} return {"group_ids": []}
@bind("physical/search/pictorial_sort") @bind("physical/search/pictorial_sort")
def pictorial_sort(user_id=-1,sort_type=GroupSortTypes.HOT_RECOMMEND,offset=0,size=10): def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0, size=10):
""" """
:remark 小组排序,缺少:前1天发评论人数*x :remark 小组排序,缺少:前1天发评论人数*x
:param user_id: :param user_id:
...@@ -44,34 +45,79 @@ def pictorial_sort(user_id=-1,sort_type=GroupSortTypes.HOT_RECOMMEND,offset=0,si ...@@ -44,34 +45,79 @@ def pictorial_sort(user_id=-1,sort_type=GroupSortTypes.HOT_RECOMMEND,offset=0,si
:return: :return:
""" """
try: try:
if not isinstance(user_id,int): if not isinstance(user_id, int):
user_id = -1 user_id = -1
#获取es链接对象 # 获取es链接对象
es_cli_obj = ESPerform.get_cli() es_cli_obj = ESPerform.get_cli()
if sort_type==GroupSortTypes.HOT_RECOMMEND: if sort_type == GroupSortTypes.HOT_RECOMMEND:
pictorial_ids_list = GroupUtils.get_hot_pictorial_recommend_result_list(offset,size,es_cli_obj) pictorial_ids_list = GroupUtils.get_hot_pictorial_recommend_result_list(offset, size, es_cli_obj)
return {"pictorial_recommend_ids":pictorial_ids_list} return {"pictorial_recommend_ids": pictorial_ids_list}
elif sort_type==GroupSortTypes.ATTENTION_RECOMMEND: elif sort_type == GroupSortTypes.ATTENTION_RECOMMEND:
attention_pictorial_list = GroupUtils.get_user_attention_pictorial_list(user_id,offset=0,size=1,es_cli_obj=es_cli_obj) attention_pictorial_list = GroupUtils.get_user_attention_pictorial_list(user_id, offset=0, size=1,
if len(attention_pictorial_list)==0: es_cli_obj=es_cli_obj)
if len(attention_pictorial_list) == 0:
return {"pictorial_recommend_ids": []} return {"pictorial_recommend_ids": []}
else: else:
attention_pictorial_id_list = [item["pictorial_id"] for item in attention_pictorial_list] attention_pictorial_id_list = [item["pictorial_id"] for item in attention_pictorial_list]
sorted_pictorial_ids_list = GroupUtils.get_pictorial_ids_by_aggs(attention_pictorial_id_list,es_cli_obj) sorted_pictorial_ids_list = GroupUtils.get_pictorial_ids_by_aggs(attention_pictorial_id_list,
es_cli_obj)
pictorial_recommend_ids_list = sorted_pictorial_ids_list pictorial_recommend_ids_list = sorted_pictorial_ids_list
#if len(group_recommend_ids_list) < size and len(group_recommend_ids_list)<len(attention_group_list): # if len(group_recommend_ids_list) < size and len(group_recommend_ids_list)<len(attention_group_list):
sorted_attention_pictorial_list = sorted(attention_pictorial_list,key=lambda item:item["update_time_val"],reverse=True) sorted_attention_pictorial_list = sorted(attention_pictorial_list,
key=lambda item: item["update_time_val"], reverse=True)
for item in sorted_attention_pictorial_list: for item in sorted_attention_pictorial_list:
if item["pictorial_id"] not in pictorial_recommend_ids_list: if item["pictorial_id"] not in pictorial_recommend_ids_list:
pictorial_recommend_ids_list.append(item["pictorial_id"]) pictorial_recommend_ids_list.append(item["pictorial_id"])
return {"pictorial_recommend_ids": pictorial_recommend_ids_list[offset:(offset+size)]} return {"pictorial_recommend_ids": pictorial_recommend_ids_list[offset:(offset + size)]}
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"pictorial_recommend_ids": []}
@bind("physical/search/pictorial_topic")
def pictorial_topic(topic_id=-1, offset=0, size=10):
"""
:remark 小组排序,缺少:前1天发评论人数*x
:param user_id:
:param sort_type:
:param offset:
:param size:
:return:
"""
try:
if not isinstance(topic_id, int):
user_id = -1
# 获取es链接对象
es_cli_obj = ESPerform.get_cli()
q = {}
# 获取帖子从属的画报
q["query"] = {
"term": {
"id": topic_id
}
}
q["_source"] = {
"include": ["id", "pictorial_id"]
}
result_dict = ESPerform.get_search_results(es_cli_obj, "topic", q, offset, size)
pictorial_ids_list = []
if len(result_dict["hits"]) > 0:
pictorial_ids_list = [item["_source"]["id"] for item in result_dict["hits"]] #
# if len(pictorial_ids_list) <10:
return {"pictorial_ids_list":[]}
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"pictorial_recommend_ids":[]} return {"pictorial_ids_list": []}
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
"create_time":{"type":"date", "format":"date_time_no_millis"}, "create_time":{"type":"date", "format":"date_time_no_millis"},
"update_time":{"type":"date", "format":"date_time_no_millis"}, "update_time":{"type":"date", "format":"date_time_no_millis"},
"tag_id":{"type":"long"}, "tag_id":{"type":"long"},
"tag_name":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_index"} "tag_name":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_index"},
"topic_id_list":{"type":"long"}
} }
} }
\ No newline at end of file
...@@ -60,6 +60,18 @@ class Pictorial(models.Model): ...@@ -60,6 +60,18 @@ class Pictorial(models.Model):
icon = models.CharField(verbose_name=u'画报名称', max_length=255) icon = models.CharField(verbose_name=u'画报名称', max_length=255)
topic_num = models.IntegerField(verbose_name=u'次数') topic_num = models.IntegerField(verbose_name=u'次数')
def get_topic_id(self):
try:
topic_id =[]
topic_id_list = PictorialTopics.objects.filter(pictorial_id=self.id).values_list("topic_id", flat=True)
for i in topic_id_list:
topic_id.append(i)
return topic_id
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False
# 获取前一天4,5星发帖数 # 获取前一天4,5星发帖数
def get_high_quality_topic_num(self): def get_high_quality_topic_num(self):
try: try:
......
...@@ -36,6 +36,7 @@ class PictorialTransfer(object): ...@@ -36,6 +36,7 @@ class PictorialTransfer(object):
tag_id = instance.get_tag_by_id() tag_id = instance.get_tag_by_id()
res["tag_id"] = tag_id res["tag_id"] = tag_id
res["tag_name"] = instance.get_tag_by_name(tag_id) res["tag_name"] = instance.get_tag_by_name(tag_id)
res["topic_id_list"] =instance.get_topic_id()
return res return res
except: except:
......
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