Commit e0dc1c54 authored by Kai's avatar Kai

update

parent 2b2f87fb
......@@ -264,7 +264,9 @@ class ESPerform(object):
return True
@classmethod
def get_tag_topic_list(cls,tag_id):
def get_tag_topic_list(cls,tag_id,have_read_topic_id_list):
try:
functions_list = list()
for id in tag_id:
functions_list.append(
{
......@@ -272,19 +274,18 @@ class ESPerform(object):
"weight": 1
}
)
try:
q = {
"query":{
"bool":{
"must":[
{"range": {"content_level": {"gte": 4, "lte": 5}}},
{"range": {"content_level": {"gte": 3, "lte": 5}}},
{"term":{"is_online": True}},
{"term":{"is_deleted": False}},
{"terms":{"tag_list":tag_id}}
]
}
},
"boost_mode": "sum",
"score_mode": "sum",
"functions": functions_list,
"_source":{
......@@ -296,8 +297,10 @@ class ESPerform(object):
{"language_type":{"order":"asc"}},
]
}
if len(have_read_topic_id_list)>0:
q["query"]["bool"]["must_not"] = have_read_topic_id_list
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="topic", query_body=q,
offset=0, size=5000,routing="4,5")
offset=0, size=100,routing="3,4,5")
topic_id_list = [item["_source"]["id"] for item in result_dict["hits"]]
return topic_id_list
......
......@@ -74,8 +74,10 @@ class CollectData(object):
have_read_topic_id_list = Tools.get_have_read_topic_id_list(device_id,-1,TopicPageType.HOME_RECOMMEND)
recommend_topic_id_list = list()
for index in range(0,100):
recommend_topic_id_list_es = list()
tag_id_list = recommend_tag_list[0:100]
tag_topic_id_list = ESPerform.get_tag_topic_list(tag_id_list,have_read_topic_id_list)
# for index in range(0,100):
# recommend_topic_id_list_es = list()
# for tag_id in recommend_tag_list[0:100]:
# redis_tag_id_key = self.tag_topic_id_redis_prefix + str(tag_id)
# redis_tag_id_data = redis_client.get(redis_tag_id_key)
......@@ -90,20 +92,19 @@ class CollectData(object):
# if topic_id not in have_read_topic_id_list and topic_id not in recommend_topic_id_list_random and topic_id not in recommend_topic_id_list:
# recommend_topic_id_list_random.append(topic_id)
# break
tag_id = recommend_tag_list[0:100]
tag_topic_id_list = ESPerform.get_tag_topic_list(tag_id)
if len(tag_topic_id_list) > index:
for topic_id in tag_topic_id_list[index:]:
if topic_id not in have_read_topic_id_list and topic_id not in recommend_topic_id_list_es and topic_id not in recommend_topic_id_list:
recommend_topic_id_list_es.append(topic_id)
if len(recommend_topic_id_list_es) == 100:
break
# random.shuffle(recommend_topic_id_list_random)
recommend_topic_id_list.extend(recommend_topic_id_list_es)
# tag_id = recommend_tag_list[0:100]
# tag_topic_id_list = ESPerform.get_tag_topic_list(tag_id)
# if len(tag_topic_id_list) > index:
# for topic_id in tag_topic_id_list[index:]:
# if topic_id not in have_read_topic_id_list and topic_id not in recommend_topic_id_list_es and topic_id not in recommend_topic_id_list:
# recommend_topic_id_list_es.append(topic_id)
# if len(recommend_topic_id_list_es) == 100:
# break
# # random.shuffle(recommend_topic_id_list_random)
# recommend_topic_id_list.extend(recommend_topic_id_list_es)
topic_recommend_redis_key = self.linucb_recommend_topic_id_prefix + str(device_id)
redis_data_dict = {
"data": json.dumps(recommend_topic_id_list),
"data": json.dumps(tag_topic_id_list),
"cursor":0
}
redis_client.hmset(topic_recommend_redis_key,redis_data_dict)
......
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