Commit 8b330f9a authored by 高雅喆's avatar 高雅喆

帖子详情页标签清洗

parent 24598e75
...@@ -173,11 +173,11 @@ class CollectData(object): ...@@ -173,11 +173,11 @@ class CollectData(object):
click_results = TopicTag.objects.using(settings.SLAVE_DB_NAME).filter( click_results = TopicTag.objects.using(settings.SLAVE_DB_NAME).filter(
topic_id=topic_id, is_online=True).values_list("tag_id", "is_collection") topic_id=topic_id, is_online=True).values_list("tag_id", "is_collection")
for tag_id, is_collection in click_results: for tag_id, is_collection in click_results:
topic_tag_list.append(tag_id) # topic_tag_list.append(tag_id)
if is_collection: if is_collection:
click_topic_tag_list.append(tag_id) topic_tag_list.append(tag_id)
tag_query_results = Tag.objects.using(settings.SLAVE_DB_NAME).filter( tag_query_results = Tag.objects.using(settings.SLAVE_DB_NAME).filter(
id__in=topic_tag_list, is_online=True, is_deleted=False).values_list("id", id__in=topic_tag_list, is_online=True, is_deleted=False, is_category=False).values_list("id",
"is_ai") "is_ai")
for id, is_ai in tag_query_results: for id, is_ai in tag_query_results:
if is_ai: if is_ai:
...@@ -191,7 +191,7 @@ class CollectData(object): ...@@ -191,7 +191,7 @@ class CollectData(object):
device_id = raw_val_dict["device"]["device_id"] device_id = raw_val_dict["device"]["device_id"]
user_id = raw_val_dict["user_id"] if "user_id" in raw_val_dict else None user_id = raw_val_dict["user_id"] if "user_id" in raw_val_dict else None
if query_type=="do": if query_type=="do":
tag_list = list(Tag.objects.using(settings.SLAVE_DB_NAME).filter(name=tag_name,is_online=True,is_deleted=False).values_list("id",flat=True)) tag_list = list(Tag.objects.using(settings.SLAVE_DB_NAME).filter(name=tag_name,is_online=True,is_deleted=False, is_category=False).values_list("id",flat=True))
click_topic_tag_list.extend(tag_list) click_topic_tag_list.extend(tag_list)
logging.info("query tag attention,positive tag_list,device_id:%s,query_name:%s,tag_list:%s" % ( logging.info("query tag attention,positive tag_list,device_id:%s,query_name:%s,tag_list:%s" % (
str(device_id), tag_name, str(click_topic_tag_list))) str(device_id), tag_name, str(click_topic_tag_list)))
...@@ -276,15 +276,19 @@ class CollectData(object): ...@@ -276,15 +276,19 @@ class CollectData(object):
# if len(exposure_sql_query_results)>0: # if len(exposure_sql_query_results)>0:
if len(tagid_list) > 0: if len(tagid_list) > 0:
tag_query_results = Tag.objects.using(settings.SLAVE_DB_NAME).filter(
id__in=tagid_list, is_online=True, is_deleted=False,
is_category=False).values_list("id",flat =True)
is_click = 1 is_click = 1
is_vote = 0 is_vote = 0
reward = 1 if is_click or is_vote else 0 reward = 1 if is_click or is_vote else 0
for tag_id in tagid_list: for tag_id in tag_query_results:
self.update_user_linucb_tag_info(reward, device_id, tag_id, user_feature) self.update_user_linucb_tag_info(reward, device_id, tag_id, user_feature)
# 更新该用户的推荐tag数据,放在 更新完成user tag行为信息之后 # 更新该用户的推荐tag数据,放在 更新完成user tag行为信息之后
self.update_recommend_tag_list(device_id, user_feature, user_id,new_user_click_tag_list=tagid_list) self.update_recommend_tag_list(device_id, user_feature, user_id,
new_user_click_tag_list=tag_query_results)
else: else:
logging.warning("unknown type msg:%s" % raw_val_dict.get("type", "missing type")) logging.warning("unknown type msg:%s" % raw_val_dict.get("type", "missing type"))
except: except:
......
...@@ -14,6 +14,7 @@ from search.utils.common import * ...@@ -14,6 +14,7 @@ from search.utils.common import *
from libs.es import ESPerform from libs.es import ESPerform
from django.conf import settings from django.conf import settings
import datetime import datetime
from trans2es.models.tag import Tag
def get_discover_page_topic_ids(user_id, device_id, size, query_type=TopicPageType.FIND_PAGE): def get_discover_page_topic_ids(user_id, device_id, size, query_type=TopicPageType.FIND_PAGE):
...@@ -390,18 +391,47 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic ...@@ -390,18 +391,47 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
have_read_topic_list.append(topic_id) have_read_topic_list.append(topic_id)
topic_user_result = list() topic_user_result = list()
topic_tag_result = list() topic_tag_result = list()
normal_tag_result = list()
category_tag_reuslt = list()
result = list() result = list()
if len(topic_tag_list) != 0: tag_query_results = Tag.objects.using(settings.SLAVE_DB_NAME).filter(
topic_tag_result = TopicUtils.top_get_topic_detail_recommend_list(user_id, topic_id, have_read_topic_list, id__in=topic_tag_list, is_online=True, is_deleted=False).values_list("id", "is_category")
category_tag_list = list()
normal_tag_list = list()
for id, is_category in tag_query_results:
if is_category:
category_tag_list.append(id)
else:
normal_tag_list.append(id)
if len(normal_tag_list) != 0:
normal_tag_result = TopicUtils.top_get_topic_detail_recommend_list(user_id, topic_id, have_read_topic_list,
size, es_cli_obj, size, es_cli_obj,
index_type="topic", routing="3,4,5,6", index_type="topic", routing="3,4,5,6",
topic_tag_list=topic_tag_list) topic_tag_list=normal_tag_list)
topic_tag_size = len(topic_tag_result) normal_tag_size = len(normal_tag_result)
have_read_topic_list.extend(topic_tag_result) have_read_topic_list.extend(normal_tag_result)
else: else:
topic_tag_size = 0 normal_tag_size = 0
if topic_tag_size < size:
size = size - topic_tag_size if normal_tag_size < size:
size = size - normal_tag_size
if len(category_tag_list) != 0:
category_tag_reuslt = TopicUtils.top_get_topic_detail_recommend_list(user_id, topic_id,
have_read_topic_list,
size, es_cli_obj,
index_type="topic",
routing="3,4,5,6",
topic_tag_list=category_tag_list)
category_tag_size = len(category_tag_reuslt)
have_read_topic_list.extend(category_tag_reuslt)
else:
category_tag_size = 0
if category_tag_size < size:
size = size - category_tag_size
if topic_user_id != -1: if topic_user_id != -1:
topic_user_result = TopicUtils.top_get_topic_detail_recommend_list(user_id, topic_id, topic_user_result = TopicUtils.top_get_topic_detail_recommend_list(user_id, topic_id,
have_read_topic_list, have_read_topic_list,
...@@ -454,7 +484,8 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic ...@@ -454,7 +484,8 @@ def topic_detail_page_recommend(device_id="", user_id=-1, topic_id=-1, topic_pic
logging.warning("topic_user_result:%s" % str(topic_user_result)) logging.warning("topic_user_result:%s" % str(topic_user_result))
logging.warning("result:%s" % str(result)) logging.warning("result:%s" % str(result))
recommend_topic_ids_list = list() recommend_topic_ids_list = list()
recommend_topic_ids_list.extend(topic_tag_result) recommend_topic_ids_list.extend(normal_tag_result)
recommend_topic_ids_list.extend(category_tag_reuslt)
recommend_topic_ids_list.extend(topic_user_result) recommend_topic_ids_list.extend(topic_user_result)
recommend_topic_ids_list.extend(result) recommend_topic_ids_list.extend(result)
return {"recommend_topic_ids": recommend_topic_ids_list} return {"recommend_topic_ids": recommend_topic_ids_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