Commit 7543e7ec authored by 段英荣's avatar 段英荣

modify

parent 5d71c369
...@@ -158,6 +158,12 @@ class TopicUtils(object): ...@@ -158,6 +158,12 @@ class TopicUtils(object):
} }
} }
}, },
"gauss": {
"update_time": {
"scale": "1d",
"decay": 0.5
}
},
"score_mode": "sum", "score_mode": "sum",
"boost_mode": "sum", "boost_mode": "sum",
"functions": functions_list "functions": functions_list
...@@ -274,6 +280,12 @@ class TopicUtils(object): ...@@ -274,6 +280,12 @@ class TopicUtils(object):
} }
} }
}, },
"gauss":{
"update_time":{
"scale":"1d",
"decay":0.5
}
},
"score_mode": "sum", "score_mode": "sum",
"boost_mode": "sum", "boost_mode": "sum",
"functions": functions_list "functions": functions_list
......
...@@ -13,21 +13,22 @@ from search.utils.common import PickType ...@@ -13,21 +13,22 @@ from search.utils.common import PickType
@bind("physical/search/pick_celebrity") @bind("physical/search/pick_celebrity")
def pick_celebrity(user_id,pick_id,offset=0,size=10): def pick_celebrity(user_id,pick_id,offset=0,size=10):
try: try:
redis_key = "physical:pick_celebrity:" + "user_id:" + str(user_id) + ":pick_id:" + str(pick_id)
have_read_pick_celebrity_ids = list() have_read_pick_celebrity_ids = list()
try: redis_key = "physical:pick_celebrity:" + "user_id:" + str(user_id) + ":pick_id:" + str(pick_id)
redis_celebrity_info = redis_client.get(redis_key)
if redis_celebrity_info: if user_id != -1:
have_read_pick_celebrity_ids = json.loads(redis_celebrity_info) try:
except: redis_celebrity_info = redis_client.get(redis_key)
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) if redis_celebrity_info:
pass have_read_pick_celebrity_ids = json.loads(redis_celebrity_info)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
pass
recommend_pick_celebrity_list = PickUtils.get_recommend_celebrity_id_list(pick_id,have_read_pick_celebrity_ids,offset,size) recommend_pick_celebrity_list = PickUtils.get_recommend_celebrity_id_list(pick_id,have_read_pick_celebrity_ids,offset,size)
if len(recommend_pick_celebrity_list) > 0: if len(recommend_pick_celebrity_list)>0 and user_id!=-1:
total_read_celebrity_ids = have_read_pick_celebrity_ids + recommend_pick_celebrity_list total_read_celebrity_ids = have_read_pick_celebrity_ids + recommend_pick_celebrity_list
PickUtils.refresh_redis_data(have_read_celebrity_list=total_read_celebrity_ids, PickUtils.refresh_redis_data(have_read_celebrity_list=total_read_celebrity_ids,
redis_cli=redis_client,redis_key=redis_key) redis_cli=redis_client,redis_key=redis_key)
...@@ -41,16 +42,18 @@ def pick_celebrity(user_id,pick_id,offset=0,size=10): ...@@ -41,16 +42,18 @@ def pick_celebrity(user_id,pick_id,offset=0,size=10):
@bind("physical/search/pick_topic") @bind("physical/search/pick_topic")
def pick_topic(user_id,pick_id,offset=0,size=10): def pick_topic(user_id,pick_id,offset=0,size=10):
try: try:
redis_key = "physical:pick_topic:" + "user_id:" + str(user_id) + ":pick_id:" + str(pick_id)
have_read_pick_topic_ids = list() have_read_pick_topic_ids = list()
try: redis_key = "physical:pick_topic:" + "user_id:" + str(user_id) + ":pick_id:" + str(pick_id)
redis_celebrity_info = redis_client.get(redis_key)
if redis_celebrity_info: if user_id != -1:
have_read_pick_topic_ids = json.loads(redis_celebrity_info) try:
except: redis_celebrity_info = redis_client.get(redis_key)
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) if redis_celebrity_info:
have_read_pick_topic_ids = json.loads(redis_celebrity_info)
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
pass
q = dict() q = dict()
functions_list = [ functions_list = [
...@@ -102,7 +105,7 @@ def pick_topic(user_id,pick_id,offset=0,size=10): ...@@ -102,7 +105,7 @@ def pick_topic(user_id,pick_id,offset=0,size=10):
if len(result_dict["hits"]) > 0: if len(result_dict["hits"]) > 0:
recommend_pick_topic_list = [item["_source"]["id"] for item in result_dict["hits"]] recommend_pick_topic_list = [item["_source"]["id"] for item in result_dict["hits"]]
if len(recommend_pick_topic_list) > 0: if len(recommend_pick_topic_list)>0 and user_id!=-1:
total_read_topic_ids = have_read_pick_topic_ids + recommend_pick_topic_list total_read_topic_ids = have_read_pick_topic_ids + recommend_pick_topic_list
PickUtils.refresh_redis_data(have_read_celebrity_list=total_read_topic_ids, PickUtils.refresh_redis_data(have_read_celebrity_list=total_read_topic_ids,
redis_cli=redis_client,redis_key=redis_key) redis_cli=redis_client,redis_key=redis_key)
......
...@@ -13,7 +13,11 @@ from libs.cache import redis_client ...@@ -13,7 +13,11 @@ from libs.cache import redis_client
@bind("physical/search/home_recommend") @bind("physical/search/home_recommend")
def home_recommend(session_id="",user_id=-1,offset=0,size=10): def home_recommend(session_id="",user_id=-1,offset=0,size=10):
""" """
:remark:首页推荐,目前只推荐日记,缺少小组打散策略 :remark:首页推荐,目前只推荐日记
:param session_id:
:param user_id:
:param offset:
:param size:
:return: :return:
""" """
try: try:
...@@ -57,6 +61,8 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10): ...@@ -57,6 +61,8 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
"have_read_topic_id":json.dumps(list(have_read_topic_id_tuple)) "have_read_topic_id":json.dumps(list(have_read_topic_id_tuple))
} }
redis_client.hmset(redis_key,redis_dict) redis_client.hmset(redis_key,redis_dict)
# 每个session key保存15分钟
redis_client.expire(redis_key,15*60*60)
return {"recommend_topic_ids":recommend_topic_ids} return {"recommend_topic_ids":recommend_topic_ids}
except: except:
...@@ -67,7 +73,9 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10): ...@@ -67,7 +73,9 @@ def home_recommend(session_id="",user_id=-1,offset=0,size=10):
@bind("physical/search/home_query") @bind("physical/search/home_query")
def home_query(session_id="",user_id=-1,query="",offset=0,size=10): def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
""" """
:remark 首页搜索排序,没有做打散,搜索逻辑优化 :remark:首页搜索,目前只推荐日记
:param session_id:
:param user_id:
:param query: :param query:
:param offset: :param offset:
:param size: :param size:
...@@ -114,6 +122,8 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10): ...@@ -114,6 +122,8 @@ def home_query(session_id="",user_id=-1,query="",offset=0,size=10):
"have_read_topic_id":json.dumps(list(have_read_topic_id_tuple)) "have_read_topic_id":json.dumps(list(have_read_topic_id_tuple))
} }
redis_client.hmset(redis_key,redis_dict) redis_client.hmset(redis_key,redis_dict)
# 每个session key保存15分钟
redis_client.expire(redis_key,15*60*60)
return {"recommend_topic_ids":recommend_topic_ids} return {"recommend_topic_ids":recommend_topic_ids}
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