Commit 2dd629c9 authored by 段英荣's avatar 段英荣

modify pictorial sort

parent cae0f3ad
......@@ -47,23 +47,76 @@ class GroupUtils(object):
return {"total_count": 0, "hits": []}
@classmethod
def get_hot_pictorial_recommend_result_list(cls,offset,size,es_cli_obj=None):
def get_hot_pictorial_recommend_result_list(cls,offset,size,es_cli_obj=None,attention_tag_list=[]):
try:
if not es_cli_obj:
es_cli_obj = ESPerform.get_cli()
q = dict()
q["query"] = {
"bool":{
"must":[
{"term": {"is_online": True}},
{"term":{"is_deleted": False}},
{"term": {"effective": True}}
]
functions_list = list()
for tag_id in attention_tag_list:
functions_list.append({
"filter":{
"constant_score":{
"filter":{
"term":{
"tag_id": tag_id
}
}
},
"weight": 20
}
})
if len(functions_list)>=20:
break
functions_list.append(
{
"gauss": {
"create_time": {
"scale": "1d",
"decay": 0.99
}
},
"weight": 60
}
)
q = {
"query":{
"function_score":{
"query":{
"bool":{
"filter":[
{"term": {"is_online": True}},
{"term": {"is_deleted": False}},
{"term": {"effective": True}}
]
}
},
"score_mode": "sum",
"boost_mode": "sum",
"functions": functions_list
}
}
}
q["sort"] = [
{"high_quality_topic_num":{"order":"desc"}}
{
"_script": {
"type": "number",
"script": {
"lang": "expression",
"source": "_score+doc['offline_score']"
# "lang":"painless",
# "source":"_score+params._source.offline_score"
},
"order": "desc"
}
},
{
"_score":{
"order": "desc"
}
}
]
q["_source"] = {
"includes":["id"]
......
......@@ -52,9 +52,15 @@ def pictorial_sort(user_id=-1, sort_type=GroupSortTypes.HOT_RECOMMEND, offset=0,
es_cli_obj = ESPerform.get_cli()
if sort_type == GroupSortTypes.HOT_RECOMMEND:
pictorial_ids_list = GroupUtils.get_hot_pictorial_recommend_result_list(offset, size, es_cli_obj)
return {"pictorial_recommend_ids": pictorial_ids_list}
# 用户关注标签
attention_tag_list = list()
if user_id>0:
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 []
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}
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)
......
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