Commit ac4b0fee authored by lixiaofang's avatar lixiaofang

add

parent 887acd9d
This diff is collapsed.
......@@ -113,7 +113,7 @@ class GroupUtils(object):
return []
@classmethod
def get_group_ids_by_aggs(cls,pictorial_ids_list,es_cli_obj=None):
def get_pictorial_ids_by_aggs(cls,pictorial_ids_list,es_cli_obj=None):
"""
:remark:聚合查询获取小组列表
:param group_id_list:
......@@ -131,9 +131,9 @@ class GroupUtils(object):
}
}
q["aggs"] = {
"group_ids":{
"pictorial_ids":{
"terms":{
"field":"group_id"
"field":"pictorial_id"
},
"aggs":{
"max_date":{
......@@ -146,12 +146,12 @@ class GroupUtils(object):
}
result_dict = ESPerform.get_search_results(es_cli_obj,"topic",q,aggregations_query=True)
buckets_list = result_dict["aggregations"]["group_ids"]["buckets"]
buckets_list = result_dict["aggregations"]["pictorial_ids"]["buckets"]
sorted_buckets_list = sorted(buckets_list,key=lambda item:item["max_date"]["value"],reverse=True)
sorted_group_id_list = [item["key"] for item in sorted_buckets_list]
sorted_pictorial_id_list = [item["key"] for item in sorted_buckets_list]
return sorted_group_id_list
return sorted_pictorial_id_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
\ No newline at end of file
......@@ -32,7 +32,7 @@ class TopicUtils(object):
}
}
q["_source"] = ["tag_list","attention_user_id_list", "pick_user_id_list", "same_group_user_id_list"]
q["_source"] = ["tag_list","attention_user_id_list", "pick_user_id_list", "same_pictorial_user_id_list"]
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), "user", q, offset, size)
......@@ -101,7 +101,7 @@ class TopicUtils(object):
}
},
"_source":{
"includes": ["id", "group_id", "offline_score", "user_id", "edit_tag_list"]
"includes": ["id", "pictorial_id", "offline_score", "user_id", "edit_tag_list"]
}
}
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="topic", query_body=q,
......@@ -148,9 +148,9 @@ class TopicUtils(object):
pick_user_info_list = result_dict["hits"][0]["_source"]["pick_user_id_list"]
pick_user_id_list = [item["user_id"] for item in pick_user_info_list]
same_group_user_info_list = result_dict["hits"][0]["_source"]["same_group_user_id_list"]
same_group_id_list = [item["user_id"] for item in same_group_user_info_list]
same_group_id_list = same_group_id_list[:100]
same_pictorial_user_info_list = result_dict["hits"][0]["_source"]["same_pictorial_user_id_list"]
same_pictorial_id_list = [item["user_id"] for item in same_pictorial_user_info_list]
same_pictorial_id_list = same_pictorial_id_list[:100]
user_tag_list = result_dict["hits"][0]["_source"]["tag_list"]
......@@ -204,11 +204,11 @@ class TopicUtils(object):
"weight": 2
}
)
if len(same_group_id_list)>0:
if len(same_pictorial_id_list)>0:
functions_list.append(
{
"filter": {"bool": {
"should": {"terms":{"user_id":same_group_id_list}}}},
"should": {"terms":{"user_id":same_pictorial_id_list}}}},
"weight": 1
}
)
......@@ -304,7 +304,7 @@ class TopicUtils(object):
"field": "user_id"
}
q["_source"] = {
"includes":["id","group_id","offline_score","user_id","edit_tag_list"]
"includes":["id","pictorial_id","offline_score","user_id","edit_tag_list"]
}
q["sort"] = [
{
......@@ -325,7 +325,7 @@ class TopicUtils(object):
offset=offset, size=size)
topic_id_list = list()
same_group_id_set = set()
same_pictorial_id_set = set()
same_user_id_set = set()
for item in result_dict["hits"]:
......@@ -362,7 +362,7 @@ class TopicUtils(object):
return list()
@classmethod
def get_topic_detail_recommend_list(cls,user_id,topic_id,topic_tag_list,topic_group_id,topic_user_id,filter_topic_user_id,have_read_topic_list,offset,size,es_cli_obj=None):
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):
"""
:remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id:
......@@ -395,11 +395,11 @@ class TopicUtils(object):
}
}
]
if isinstance(topic_group_id,int) and topic_group_id > 0:
if isinstance(topic_pictorial_id,int) and topic_pictorial_id > 0:
functions_list.append(
{
"filter": {"term": {
"group_id": topic_group_id}},
"pictorial_id": topic_pictorial_id}},
"weight": 1,
}
)
......@@ -435,7 +435,7 @@ class TopicUtils(object):
}
q["query"]["function_score"] = query_function_score
q["_source"] = {
"includes":["id","group_id","user_id","_score"]
"includes":["id","pictorial_id","user_id","_score"]
}
result_dict = ESPerform.get_search_results(es_cli_obj, sub_index_name="topic", query_body=q,
......@@ -547,7 +547,7 @@ class TopicUtils(object):
"function_score":query_function_score
}
q["_source"] = {
"includes":["id","group_id","user_id","_score","offline_score","manual_score"]
"includes":["id","pictorial_id","user_id","_score","offline_score","manual_score"]
}
q["sort"] = [
{
......
......@@ -12,7 +12,7 @@ from search.utils.common import GroupSortTypes
from libs.es import ESPerform
@bind("physical/search/query_group")
@bind("physical/search/query_pictorial")
def query_group(query="",offset=0,size=10):
"""
:remark:小组搜索排序策略,缺少排序策略
......@@ -33,7 +33,7 @@ def query_group(query="",offset=0,size=10):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"group_ids":[]}
@bind("physical/search/group_sort")
@bind("physical/search/pictorial_sort")
def group_sort(user_id=-1,sort_type=GroupSortTypes.HOT_RECOMMEND,offset=0,size=10):
"""
:remark 小组排序,缺少:前1天发评论人数*x
......@@ -61,14 +61,14 @@ def group_sort(user_id=-1,sort_type=GroupSortTypes.HOT_RECOMMEND,offset=0,size=1
return {"pictorial_recommend_ids": []}
else:
attention_pictorial_id_list = [item["pictorial_id"] for item in attention_pictorial_list]
sorted_pictorial_ids_list = GroupUtils.get_group_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
#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)
for item in sorted_attention_pictorial_list:
if item["group_id"] not in pictorial_recommend_ids_list:
pictorial_recommend_ids_list.append(item["group_id"])
if item["pictorial_id"] not in pictorial_recommend_ids_list:
pictorial_recommend_ids_list.append(item["pictorial_id"])
return {"pictorial_recommend_ids": pictorial_recommend_ids_list[offset:(offset+size)]}
......
......@@ -225,7 +225,7 @@ def home_query(device_id="", tag_id=-1, user_id=-1, query="", offset=0, size=10)
@bind("physical/search/topic_detail_page_recommend")
def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_group_id=-1, topic_user_id=-1,
def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pictorial_id=-1, topic_user_id=-1,
filter_topic_user_id=False, offset=0, size=10):
"""
:remark:帖子详情页推荐策略,缺少第一个卡片策略
......@@ -249,7 +249,7 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_gro
# 获取帖子标签列表
topic_tag_list = TopicUtils.get_topic_tag_id_list(topic_id, es_cli_obj)
result_list = TopicUtils.get_topic_detail_recommend_list(user_id, topic_id, topic_tag_list, topic_group_id,
result_list = TopicUtils.get_topic_detail_recommend_list(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)
recommend_topic_ids_list = 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