Commit c2f61e2c authored by lixiaofang's avatar lixiaofang

修改排序逻辑

parent f896baad
...@@ -14,7 +14,6 @@ from trans2es.models.pictorial import PictorialTopics ...@@ -14,7 +14,6 @@ from trans2es.models.pictorial import PictorialTopics
from libs.cache import redis_client from libs.cache import redis_client
class TopicUtils(object): class TopicUtils(object):
@classmethod @classmethod
...@@ -35,7 +34,7 @@ class TopicUtils(object): ...@@ -35,7 +34,7 @@ class TopicUtils(object):
} }
q["_source"] = { q["_source"] = {
"include": ["tag_list","attention_user_id_list", "pick_user_id_list", "same_pictorial_user_id_list"] "include": ["tag_list", "attention_user_id_list", "pick_user_id_list", "same_pictorial_user_id_list"]
} }
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), "user", q, offset, size) result_dict = ESPerform.get_search_results(ESPerform.get_cli(), "user", q, offset, size)
...@@ -174,18 +173,18 @@ class TopicUtils(object): ...@@ -174,18 +173,18 @@ class TopicUtils(object):
} }
] ]
if user_id and user_id>0: if user_id and user_id > 0:
redis_key_prefix = "physical:user_similar:participant_user_id:" redis_key_prefix = "physical:user_similar:participant_user_id:"
similar_redis_key = redis_key_prefix + str(user_id) similar_redis_key = redis_key_prefix + str(user_id)
redis_user_similar_data = redis_client.get(similar_redis_key) 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 [] user_similar_list = json.loads(redis_user_similar_data) if redis_user_similar_data else []
if len(user_similar_list)>0: if len(user_similar_list) > 0:
functions_list.extend(user_similar_list) functions_list.extend(user_similar_list)
if len(attention_user_id_list) > 0: if len(attention_user_id_list) > 0:
functions_list.append( functions_list.append(
{ {
"filter": {"constant_score":{"filter":{"terms": {"user_id": attention_user_id_list}}}}, "filter": {"constant_score": {"filter": {"terms": {"user_id": attention_user_id_list}}}},
"weight": 100, "weight": 100,
} }
) )
...@@ -272,7 +271,7 @@ class TopicUtils(object): ...@@ -272,7 +271,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":3,"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"]:
...@@ -337,7 +336,7 @@ class TopicUtils(object): ...@@ -337,7 +336,7 @@ class TopicUtils(object):
@classmethod @classmethod
def userful_tag_topic_list(cls, user_id, have_read_topic_list, size, def userful_tag_topic_list(cls, user_id, have_read_topic_list, size,
index_type="topic-high-star",routing=None,useful_tag_list =[]): index_type="topic-high-star", routing=None, useful_tag_list=[]):
""" """
:remark 帖子详情页推荐列表,缺少按时间衰减 :remark 帖子详情页推荐列表,缺少按时间衰减
:param user_id: :param user_id:
...@@ -371,20 +370,20 @@ class TopicUtils(object): ...@@ -371,20 +370,20 @@ class TopicUtils(object):
else: else:
q = dict() q = dict()
q["query"] = { q["query"] = {
"bool": { "bool": {
"must": [ "must": [
{"term": {"is_online": True}}, {"term": {"is_online": True}},
{"term": {"is_deleted": False}}, {"term": {"is_deleted": False}},
{"terms": {"useful_tag_list": useful_tag_list}}, {"terms": {"useful_tag_list": useful_tag_list}},
{"term":{"content_level":6}} {"term": {"content_level": 6}}
], ],
"must_not": { "must_not": {
"terms": { "terms": {
"id": have_read_topic_list "id": have_read_topic_list
}
}
} }
} }
}
}
# logging.warning("topic_tag_list:%s"%str(topic_tag_list)) # logging.warning("topic_tag_list:%s"%str(topic_tag_list))
# query_function_score = { # query_function_score = {
# "query": { # "query": {
...@@ -406,7 +405,8 @@ class TopicUtils(object): ...@@ -406,7 +405,8 @@ class TopicUtils(object):
"includes": ["id"] "includes": ["id"]
} }
result_dict = ESPerform.get_search_results(es_cli_obj, sub_index_name=index_type, query_body=q, size=size, result_dict = ESPerform.get_search_results(es_cli_obj, sub_index_name=index_type, query_body=q,
size=size,
routing=routing) routing=routing)
topic_id_list = list() topic_id_list = list()
...@@ -998,7 +998,7 @@ class TopicUtils(object): ...@@ -998,7 +998,7 @@ class TopicUtils(object):
} }
if sorts_by: if sorts_by:
sorts = cls.process_sort(sorts_by,pictorial_id=None) sorts = cls.process_sort(sorts_by, pictorial_id=None)
if sorts: if sorts:
q["sort"] = sorts q["sort"] = sorts
...@@ -1029,7 +1029,6 @@ class TopicUtils(object): ...@@ -1029,7 +1029,6 @@ class TopicUtils(object):
def business_topic_ids(cls, filters, nfilters, sorts_by, offset=0, size=10, index_name="topic", filter_online=True): def business_topic_ids(cls, filters, nfilters, sorts_by, offset=0, size=10, index_name="topic", filter_online=True):
must = cls.business_filters(filters, filter_online=filter_online) must = cls.business_filters(filters, filter_online=filter_online)
logging.info("get must:%s" % must)
q = { q = {
"query": { "query": {
"bool": { "bool": {
...@@ -1039,11 +1038,17 @@ class TopicUtils(object): ...@@ -1039,11 +1038,17 @@ class TopicUtils(object):
} }
} }
if 'pictorial_id' in filters.keys():
if sorts_by: logging.info("get picotirial:%s" % filters["pictorial_id"])
sorts = cls.process_sort(sorts_by) if sorts_by:
if sorts: sorts = cls.process_sort(sorts_by, filters["pictorial_id"])
q["sort"] = sorts if sorts:
q["sort"] = sorts
else:
if sorts_by:
sorts = cls.process_sort(sorts_by,pictorial_id=None)
if sorts:
q["sort"] = sorts
try: try:
result_dict = ESPerform.get_search_results( result_dict = ESPerform.get_search_results(
...@@ -1144,7 +1149,6 @@ class TopicUtils(object): ...@@ -1144,7 +1149,6 @@ class TopicUtils(object):
# } # }
# }) # })
else: else:
if isinstance(v, list): if isinstance(v, 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