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