Commit 88be45f9 authored by Kai's avatar Kai

Merge branch 'test' of git.wanmeizhensuo.com:alpha/physical into test

parents f5267594 69885347
...@@ -47,7 +47,7 @@ class GroupUtils(object): ...@@ -47,7 +47,7 @@ class GroupUtils(object):
return {"total_count": 0, "hits": []} return {"total_count": 0, "hits": []}
@classmethod @classmethod
def get_hot_pictorial_recommend_result_list(cls,offset,size,es_cli_obj=None,attention_tag_list=[]): def get_hot_pictorial_recommend_result_list(cls, offset, size, es_cli_obj=None, attention_tag_list=[]):
try: try:
if not es_cli_obj: if not es_cli_obj:
es_cli_obj = ESPerform.get_cli() es_cli_obj = ESPerform.get_cli()
...@@ -55,10 +55,10 @@ class GroupUtils(object): ...@@ -55,10 +55,10 @@ class GroupUtils(object):
functions_list = list() functions_list = list()
for tag_id in attention_tag_list: for tag_id in attention_tag_list:
functions_list.append({ functions_list.append({
"filter":{ "filter": {
"constant_score":{ "constant_score": {
"filter":{ "filter": {
"term":{ "term": {
"tag_id": tag_id "tag_id": tag_id
} }
} }
...@@ -67,7 +67,7 @@ class GroupUtils(object): ...@@ -67,7 +67,7 @@ class GroupUtils(object):
"weight": 20 "weight": 20
}) })
if len(functions_list)>=20: if len(functions_list) >= 20:
break break
functions_list.append( functions_list.append(
...@@ -82,17 +82,17 @@ class GroupUtils(object): ...@@ -82,17 +82,17 @@ class GroupUtils(object):
} }
) )
q = { q = {
"query":{ "query": {
"function_score":{ "function_score": {
"query":{ "query": {
"bool":{ "bool": {
"filter":[ "filter": [
{"term": {"is_online": True}}, {"term": {"is_online": True}},
{"term": {"is_deleted": False}}, {"term": {"is_deleted": False}},
{"term": {"effective": True}} {"term": {"effective": True}}
], ],
"must_not":[ "must_not": [
{"term":{"is_default":1}} {"term": {"is_default": 1}}
] ]
} }
}, },
...@@ -116,16 +116,16 @@ class GroupUtils(object): ...@@ -116,16 +116,16 @@ class GroupUtils(object):
} }
}, },
{ {
"_score":{ "_score": {
"order": "desc" "order": "desc"
} }
} }
] ]
q["_source"] = { q["_source"] = {
"includes":["id"] "includes": ["id"]
} }
result_dict = ESPerform.get_search_results(es_cli_obj,"pictorial",q,offset,size) result_dict = ESPerform.get_search_results(es_cli_obj, "pictorial", q, offset, size)
pictorial_ids_list = [] pictorial_ids_list = []
if len(result_dict["hits"]) > 0: if len(result_dict["hits"]) > 0:
...@@ -153,7 +153,7 @@ class GroupUtils(object): ...@@ -153,7 +153,7 @@ class GroupUtils(object):
{"term": {"is_online": True}}, {"term": {"is_online": True}},
{"term": {"user_id": user_id}}, {"term": {"user_id": user_id}},
{"term": {"is_deleted": False}}, {"term": {"is_deleted": False}},
{"term":{"effective":True}} {"term": {"effective": True}}
] ]
} }
} }
...@@ -171,7 +171,6 @@ class GroupUtils(object): ...@@ -171,7 +171,6 @@ class GroupUtils(object):
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return [] return []
@classmethod @classmethod
def get_pictorial_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):
""" """
......
...@@ -55,11 +55,12 @@ def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0, ...@@ -55,11 +55,12 @@ def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0,
if sort_type == GroupSortTypes.HOT_RECOMMEND: if sort_type == GroupSortTypes.HOT_RECOMMEND:
# 用户关注标签 # 用户关注标签
attention_tag_list = list() attention_tag_list = list()
if user_id>0: if user_id > 0:
redis_tag_data = redis_client.hget("physical:linucb:register_user_tag_info", user_id) redis_tag_data = redis_client.hget("physical:linucb:register_user_tag_info", user_id)
attention_tag_list = json.loads(redis_tag_data) if redis_tag_data else [] attention_tag_list = json.loads(redis_tag_data) if redis_tag_data else []
pictorial_ids_list = GroupUtils.get_hot_pictorial_recommend_result_list(offset, size, es_cli_obj,attention_tag_list) pictorial_ids_list = GroupUtils.get_hot_pictorial_recommend_result_list(offset, size, es_cli_obj,
attention_tag_list)
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:
...@@ -174,6 +175,13 @@ def pictorial_topic(topic_id=-1, offset=0, size=10): ...@@ -174,6 +175,13 @@ def pictorial_topic(topic_id=-1, offset=0, size=10):
"term": { "term": {
"is_deleted": False "is_deleted": False
} }
}, {
"range": {
"topic_id_list": {
"gte": 0
}
}
}] }]
} }
} }
...@@ -222,36 +230,33 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10): ...@@ -222,36 +230,33 @@ def pictorial_topic_sort(pictorial_id=-1, offset=0, size=10):
user_id = -1 user_id = -1
q = { q = {
"query":{ "query": {
"bool":{ "bool": {
"must":[ "must": [
{"term":{"pictorial_id": pictorial_id}}, {"term": {"pictorial_id": pictorial_id}},
{"term": {"is_online": True}}, {"term": {"is_online": True}},
{"term": {"is_deleted": False}}, {"term": {"is_deleted": False}},
] ]
} }
}, },
"sort":[ "sort": [
{"total_vote_num": {"order": "desc"}}, {"total_vote_num": {"order": "desc"}},
{"create_time": {"order": "desc"}} {"create_time": {"order": "desc"}}
] ]
} }
pict_pictorial_ids_list =[] pict_pictorial_ids_list = []
# 获取es链接对象 # 获取es链接对象
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)
for item in result_dict["hits"]: for item in result_dict["hits"]:
topic_id = item["_source"]["id"] topic_id = item["_source"]["id"]
pict_pictorial_ids_list.append(topic_id) pict_pictorial_ids_list.append(topic_id)
if len(pict_pictorial_ids_list)==0 and offset==0: return {"pict_pictorial_ids_list": pict_pictorial_ids_list}
pict_pictorial_ids_list = list(
PictorialTopics.objects.filter(pictorial_id=pictorial_id, is_online=True, is_deleted=False).values_list(
"topic_id", flat=True)[offset:size])
return {"pict_pictorial_ids_list":pict_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())
......
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