Commit 96aa1fa8 authored by 段英荣's avatar 段英荣

modify

parent 05bcb84f
...@@ -60,12 +60,21 @@ def sync_face_similar_data_to_redis(): ...@@ -60,12 +60,21 @@ def sync_face_similar_data_to_redis():
item_list = list() item_list = list()
for item in similar_result_items: for item in similar_result_items:
weight_score = int(item.similarity * 100)
item_list.append( item_list.append(
{ {
"contrast_user_id": item.contrast_user_id, "filter":{
"similarity": item.similarity "constant_score":{
"filter":{
"term":{"user_id": item.contrast_user_id}
}
}
},
"weight": weight_score*2
} }
) )
if len(item_list)>=100:
break
redis_client.set(redis_key, json.dumps(item_list)) redis_client.set(redis_key, json.dumps(item_list))
logging.info("participant_user_id:%d set data done!" % participant_user_id) logging.info("participant_user_id:%d set data done!" % participant_user_id)
......
...@@ -11,6 +11,8 @@ from libs.es import ESPerform ...@@ -11,6 +11,8 @@ from libs.es import ESPerform
from .common import TopicDocumentField from .common import TopicDocumentField
from search.utils.common import * from search.utils.common import *
from trans2es.models.pictorial import PictorialTopics from trans2es.models.pictorial import PictorialTopics
from libs.cache import redis_client
class TopicUtils(object): class TopicUtils(object):
...@@ -158,14 +160,6 @@ class TopicUtils(object): ...@@ -158,14 +160,6 @@ class TopicUtils(object):
q["query"] = dict() q["query"] = dict()
functions_list = [ functions_list = [
# {
# "filter": {
# "term": {
# "language_type": 1
# }
# },
# "weight": 60
# },
{ {
"gauss": { "gauss": {
"create_time": { "create_time": {
...@@ -174,38 +168,22 @@ class TopicUtils(object): ...@@ -174,38 +168,22 @@ class TopicUtils(object):
} }
}, },
"weight": 60 "weight": 60
}, }
# {
# "filter": {
# "constant_score":{
# "filter":{
# "term": {
# "content_level": 6
# }
# }
# }
# },
# "weight": 600
# }
] ]
# if len(user_similar_score_list) > 0: if user_id and user_id>0:
# for item in user_similar_score_list[:100]: redis_key_prefix = "physical:user_similar:participant_user_id:"
# score_item = 2 + item[1] similar_redis_key = redis_key_prefix + str(user_id)
# functions_list.append( redis_user_similar_data = redis_client.get(similar_redis_key)
# { user_similar_list = json.loads(redis_user_similar_data) if redis_user_similar_data else []
# "filter": {"bool": { if len(user_similar_list)>0:
# "should": {"term": {"user_id": item[0]}}}}, functions_list.extend(user_similar_list)
# "weight": score_item,
# }
# )
if len(attention_user_id_list) > 0: if len(attention_user_id_list) > 0:
functions_list.append( functions_list.append(
{ {
"filter": {"bool": { "filter": {"constant_score":{"filter":{"terms": {"user_id": attention_user_id_list}}}},
"should": {"terms": {"user_id": attention_user_id_list}}}}, "weight": 100,
"weight": 30,
} }
) )
if len(attention_tag_list) > 0: if len(attention_tag_list) > 0:
...@@ -221,8 +199,6 @@ class TopicUtils(object): ...@@ -221,8 +199,6 @@ class TopicUtils(object):
"query": { "query": {
"bool": { "bool": {
"filter": [ "filter": [
# {"term": {"content_level": 6}},
# {"term": {"has_image":True}},
{"term": {"is_online": True}}, {"term": {"is_online": True}},
{"term": {"is_deleted": False}} {"term": {"is_deleted": False}}
], ],
...@@ -294,7 +270,7 @@ class TopicUtils(object): ...@@ -294,7 +270,7 @@ class TopicUtils(object):
] ]
query_function_score["query"]["bool"]["minimum_should_match"] = 1 query_function_score["query"]["bool"]["minimum_should_match"] = 1
query_function_score["query"]["bool"]["filter"].append( query_function_score["query"]["bool"]["filter"].append(
{"range": {"content_level": {"gte":4,"lte":6}}} {"range": {"content_level": {"gte":3,"lte":6}}}
) )
else: else:
if "must_not" in query_function_score["query"]["bool"]: if "must_not" in query_function_score["query"]["bool"]:
...@@ -318,7 +294,6 @@ class TopicUtils(object): ...@@ -318,7 +294,6 @@ class TopicUtils(object):
q["collapse"] = { q["collapse"] = {
"field": "user_id" "field": "user_id"
} }
# "includes": ["id", "pictorial_id", "offline_score", "user_id", "edit_tag_list"]
q["_source"] = { q["_source"] = {
"includes": ["id"] "includes": ["id"]
} }
......
...@@ -49,13 +49,15 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query ...@@ -49,13 +49,15 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
query_type=TopicPageType.HOME_RECOMMEND,promote_topic_list = [],disable_collpase=False): query_type=TopicPageType.HOME_RECOMMEND,promote_topic_list = [],disable_collpase=False):
try: try:
topic_star_routing = "6" topic_star_routing = "6"
index_type = "topic-high-star"
if query is None: if query is None:
if user_id>0: if user_id>0:
redis_key = "physical:home_recommend" + ":user_id:" + str(user_id) + ":query_type:" + str(query_type) redis_key = "physical:home_recommend" + ":user_id:" + str(user_id) + ":query_type:" + str(query_type)
else: else:
redis_key = "physical:home_recommend" + ":device_id:" + device_id + ":query_type:" + str(query_type) redis_key = "physical:home_recommend" + ":device_id:" + device_id + ":query_type:" + str(query_type)
else: else:
topic_star_routing = "4,5,6" topic_star_routing = "3,4,5,6"
index_type = "topic"
if user_id>0: if user_id>0:
redis_key = "physical:home_query" + ":user_id:" + str(user_id) + ":query:" + str(query) + ":query_type:" + str(query_type) redis_key = "physical:home_query" + ":user_id:" + str(user_id) + ":query:" + str(query) + ":query_type:" + str(query_type)
else: else:
...@@ -96,8 +98,8 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query ...@@ -96,8 +98,8 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
recommend_topic_id_list.sort(key=linucb_recommend_topic_id_list.index) recommend_topic_id_list.sort(key=linucb_recommend_topic_id_list.index)
# cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8")) # cursor = int(str(recommend_topic_dict[b"cursor"], encoding="utf-8"))
# newcursor = cursor + 6 # newcursor = cursor + 6
if len(recommend_topic_id_list) > 6: if len(recommend_topic_id_list) > 0:
recommend_topic_list = recommend_topic_id_list[0:6] recommend_topic_list = recommend_topic_id_list[0:size]
# redis_client.hset(topic_recommend_redis_key, "cursor", newcursor) # redis_client.hset(topic_recommend_redis_key, "cursor", newcursor)
if b"datadict" in recommend_topic_dict: if b"datadict" in recommend_topic_dict:
...@@ -120,11 +122,12 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query ...@@ -120,11 +122,12 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
# for topic_id in promote_recommend_topic_id_list: # for topic_id in promote_recommend_topic_id_list:
# have_read_topic_id_list_add_promote.append(topic_id) # have_read_topic_id_list_add_promote.append(topic_id)
have_read_topic_id_list.extend(promote_topic_list) have_read_topic_id_list.extend(promote_topic_list)
topic_id_list = list() rank_topic_id_list = list()
if size>0:
rank_topic_id_list = TopicUtils.get_recommend_topic_ids(user_id=user_id, tag_id=tag_id, offset=0, size=size, rank_topic_id_list = TopicUtils.get_recommend_topic_ids(user_id=user_id, tag_id=tag_id, offset=0, size=size,
single_size=size,query=query, query_type=query_type, single_size=size,query=query, query_type=query_type,
filter_topic_id_list=have_read_topic_id_list, filter_topic_id_list=have_read_topic_id_list,
index_type="topic-high-star",routing=topic_star_routing,attention_tag_list=attention_tag_list,linucb_user_id_list=recommend_topic_user_list,disable_collpase=disable_collpase) index_type=index_type,routing=topic_star_routing,attention_tag_list=attention_tag_list,linucb_user_id_list=recommend_topic_user_list,disable_collpase=disable_collpase)
# if len(recommend_topic_list) == 6 and query is None: # if len(recommend_topic_list) == 6 and query is None:
# if (size < 11): # if (size < 11):
......
...@@ -227,10 +227,6 @@ class Topic(models.Model): ...@@ -227,10 +227,6 @@ class Topic(models.Model):
elif user_query_results[0].is_shadow: elif user_query_results[0].is_shadow:
user_is_shadow = True user_is_shadow = True
# 是否官方推荐小组
# if self.group and self.group.is_recommend:
# offline_score += 4.0
# 帖子等级 # 帖子等级
if self.content_level == '5': if self.content_level == '5':
offline_score += 100.0 *3 offline_score += 100.0 *3
...@@ -239,20 +235,8 @@ class Topic(models.Model): ...@@ -239,20 +235,8 @@ class Topic(models.Model):
elif self.content_level == '6': elif self.content_level == '6':
offline_score += 200.0 *3 offline_score += 200.0 *3
# is_excellent = self.judge_if_excellent_topic(self.id)
# if is_excellent:
# offline_score += 200.0
if self.language_type == 1: if self.language_type == 1:
offline_score += 60.0 offline_score += 60.0
# exposure_count = ActionSumAboutTopic.objects.using(settings.SLAVE_DB_NAME).filter(topic_id=self.id, data_type=1).count()
# click_count = ActionSumAboutTopic.objects.using(settings.SLAVE_DB_NAME).filter(topic_id=self.id, data_type=2).count()
# uv_num = ActionSumAboutTopic.objects.using(settings.SLAVE_DB_NAME).filter(topic_id=self.id, data_type=3).count()
#
# if exposure_count > 0:
# offline_score += click_count / exposure_count
# if uv_num > 0:
# offline_score += (self.vote_num / uv_num + self.reply_num / uv_num)
""" """
1:马甲账号是否对总分降权? 1:马甲账号是否对总分降权?
......
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