Commit fe3f0cc3 authored by 段英荣's avatar 段英荣

Merge branch 'similar_sort' into 'master'

modify

See merge request alpha/physical!177
parents 884099cf 448708f3
......@@ -167,15 +167,15 @@ class TopicUtils(object):
},
"weight": 3
},
# {
# "linear": {
# "create_time": {
# "scale": "1d",
# "decay": 0.99
# }
# },
# "weight": 500
# }
{
"linear": {
"create_time": {
"scale": "1d",
"decay": 0.99
}
},
"weight": 500
}
]
if len(user_similar_score_list)>0:
......@@ -301,14 +301,13 @@ class TopicUtils(object):
query_function_score["query"]["bool"]["minimum_should_match"] = 1
q["query"]["function_score"] = query_function_score
# q["collapse"] = {
# "field": "user_id"
# }
q["collapse"] = {
"field": "user_id"
}
q["_source"] = {
"includes":["id","group_id","offline_score","user_id","edit_tag_list"]
}
q["sort"] = [
"create_time_val",
{
"_script":{
"type":"number",
......@@ -331,30 +330,32 @@ class TopicUtils(object):
same_user_id_set = set()
for item in result_dict["hits"]:
if item["_source"]["group_id"]>0 and item["_source"]["group_id"] not in same_group_id_set:
same_group_id_set.add(item["_source"]["id"])
topic_id_list.append(item["_source"]["id"])
else:
same_group_id_set.add(item["_source"]["id"])
if item["_source"]["user_id"] not in same_user_id_set:
same_user_id_set.add(item["_source"]["id"])
topic_id_list.append(item["_source"]["id"])
else:
same_user_id_set.add(item["_source"]["id"])
if len(topic_id_list) >= single_size:
break
if len(topic_id_list) < single_size:
for topic_id in same_group_id_set:
topic_id_list.append(topic_id)
if len(topic_id_list)>=single_size:
break
for topic_id in same_user_id_set:
topic_id_list.append(topic_id)
if len(topic_id_list)>=single_size:
break
topic_id_list.append(item["_source"]["id"])
# for item in result_dict["hits"]:
# if item["_source"]["group_id"]>0 and item["_source"]["group_id"] not in same_group_id_set:
# same_group_id_set.add(item["_source"]["id"])
# topic_id_list.append(item["_source"]["id"])
# else:
# same_group_id_set.add(item["_source"]["id"])
#
# if item["_source"]["user_id"] not in same_user_id_set:
# same_user_id_set.add(item["_source"]["id"])
# topic_id_list.append(item["_source"]["id"])
# else:
# same_user_id_set.add(item["_source"]["id"])
#
# if len(topic_id_list) >= single_size:
# break
#
# if len(topic_id_list) < single_size:
# for topic_id in same_group_id_set:
# topic_id_list.append(topic_id)
# if len(topic_id_list)>=single_size:
# break
# for topic_id in same_user_id_set:
# topic_id_list.append(topic_id)
# if len(topic_id_list)>=single_size:
# break
return topic_id_list
except:
......
......@@ -80,7 +80,7 @@ def get_home_recommend_topic_ids(user_id, device_id, tag_id, offset, size, query
user_similar_score_redis_list = json.loads(
redis_user_similar_score_redis_val) if redis_user_similar_score_redis_val else []
topic_id_list = TopicUtils.get_recommend_topic_ids(user_id=user_id, tag_id=tag_id, offset=offset, size=size * size,
topic_id_list = TopicUtils.get_recommend_topic_ids(user_id=user_id, tag_id=tag_id, offset=offset, size=size,
single_size=size,query=query, query_type=query_type,
filter_topic_id_list=have_read_topic_id_list,
recommend_tag_list=recommend_tag_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