Commit 6f22f345 authored by lixiaofang's avatar lixiaofang

721需求

parent ed060f31
...@@ -18,7 +18,6 @@ class ProductUtils(object): ...@@ -18,7 +18,6 @@ class ProductUtils(object):
@classmethod @classmethod
def get_product_sku(cls, query='', offset=0, size=10, sort_type='', filters={}): def get_product_sku(cls, query='', offset=0, size=10, sort_type='', filters={}):
try: try:
q = []
multi_fields = { multi_fields = {
'cn_name_pre': 2, 'cn_name_pre': 2,
'en_name_pre': 2, 'en_name_pre': 2,
...@@ -41,19 +40,24 @@ class ProductUtils(object): ...@@ -41,19 +40,24 @@ class ProductUtils(object):
logging.info("get sku_must_flter:%s " % sku_must_flter) logging.info("get sku_must_flter:%s " % sku_must_flter)
logging.info("get sku_must_flter:%s " % type(sku_must_flter)) logging.info("get sku_must_flter:%s " % type(sku_must_flter))
q["query"] = { q = {
"bool": { "query": {
"must": sku_must_flter "bool": {
"must": sku_must_flter
}
} }
} }
if query != '': if query != '':
q["query"] += { q = {
"bool": { "query": {
"should": { "bool": {
"multi_match": multi_match "must": sku_must_flter,
}, "should": {
"minimum_should_match": 1 "multi_match": multi_match
},
"minimum_should_match": 1
}
} }
} }
...@@ -97,19 +101,7 @@ class ProductUtils(object): ...@@ -97,19 +101,7 @@ class ProductUtils(object):
if k == "effect": if k == "effect":
f.append({"term": {"effect_cn_name": v}}) f.append({"term": {"effect_cn_name": v}})
if k == "catrgory": if k == "category":
f.append({"term": {"category_cn_name": v}}) f.append({"term": {"category_cn_name": v}})
else:
if isinstance(v, list):
f.append({
"terms": {k: v},
})
else:
f.append({
"term": {k: v},
})
return f return f
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from gm_rpcd.all import bind
import logging import logging
import traceback import traceback
import json import json
import time
import datetime
from libs.cache import redis_client
from gm_rpcd.all import bind
from libs.cache import redis_client from libs.cache import redis_client
from libs.es import ESPerform from libs.es import ESPerform
from search.utils.group import GroupUtils from search.utils.group import GroupUtils
from search.utils.common import GroupSortTypes from search.utils.common import GroupSortTypes
from libs.es import ESPerform from libs.es import ESPerform
from trans2es.models.pictorial import PictorialTopics from trans2es.models.pictorial import PictorialTopics
from trans2es.models.pictorial import CommunityPictorialActivity
from alpha_types.venus import PICTORIAL_ACTIVITY_SORT
@bind("physical/search/query_pictorial") @bind("physical/search/query_pictorial")
...@@ -331,3 +336,98 @@ def search_physical(query="", offset=0, size=10): ...@@ -331,3 +336,98 @@ def search_physical(query="", offset=0, size=10):
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"search_pictorial_ids": []} return {"search_pictorial_ids": []}
@bind("physical/search/pictorial_activity")
def pictorial_activity_sort(activity_id=0, offset=0, size=10, sort_type=1):
"""
榜单活动的排名和最新tab下的排序
排名根据该榜单下的帖子的总票数倒排
最新根据榜单的创建时间排序
过滤掉下线的无封面的帖子
:param activity_id:
:param offset:
:param size:
:param sort_type:
:return:
"""
try:
now = datetime.datetime.now()
activity_status = CommunityPictorialActivity.objects.filter(id=activity_id).values_list("end_time",
flat=True).first()
now = int(time.mktime(now.timetuple()))
activity_status = int(time.mktime(activity_status.timetuple()))
pictorial_ids_list = []
if sort_type == 1:
redis_key = "pictorial:activity:vote:id:" + str(activity_id)
else:
redis_key = "pictorial:activity:create:id:" + str(activity_id)
if now < activity_status:
q = {
"query": {
"bool": {
"must": [
{
"term": {
"activity_join": activity_id
}
},
# {
# "term": {
# "is_cover": True
# }
# },
{
"term": {
"is_online": True
}
}
]
}
}
}
q["sort"] = process_sort(sort_type)
es_cli_obj = ESPerform.get_cli()
result_dict = ESPerform.get_search_results(es_cli_obj, "pictorial", q, offset, size)
if len(result_dict["hits"]) > 0:
for item in result_dict["hits"]:
pictorial_id = item["_source"]["id"]
vote_num = item["_source"]["topic_vote_number"]
pictorial_ids_list.append({"pictorial_id": pictorial_id, "vote_num": vote_num})
redis_client.set(redis_key, json.dumps(pictorial_ids_list))
else:
redis_field_val_list = redis_client.get(redis_key)
pictorial_ids_list = json.loads(str(redis_field_val_list, encoding="utf-8"))
return {"pictorial_activity_sort": pictorial_ids_list}
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"pictorial_activity_sort": []}
def process_sort(sorts_by):
"""处理排序部分。"""
sort_rule = []
if isinstance(sorts_by, int):
if sorts_by == PICTORIAL_ACTIVITY_SORT.VOTE_NUM:
sort_rule.append({
"topic_vote_number": {
"order": "desc"
}
})
if sorts_by == PICTORIAL_ACTIVITY_SORT.CREATE_TIME:
sort_rule.append({
"create_time": {
"order": "desc"
}
})
logging.info("get picotirial:%s" % sort_rule)
return sort_rule
...@@ -13,7 +13,7 @@ from libs.es import ESPerform ...@@ -13,7 +13,7 @@ from libs.es import ESPerform
@bind("physical/search/query_product_sku") @bind("physical/search/query_product_sku")
def product_hot_sort(query='', offset=0, size=2, sort_type='', filters={}): def product_hot_sort(query='', offset=0, size=10, filters={}):
''' '''
商品sku排序 商品sku排序
:param query: :param query:
...@@ -27,13 +27,13 @@ def product_hot_sort(query='', offset=0, size=2, sort_type='', filters={}): ...@@ -27,13 +27,13 @@ def product_hot_sort(query='', offset=0, size=2, sort_type='', filters={}):
res = ProductUtils.get_product_sku(query=query, offset=offset, size=size, sort_type=sort_type, filters=filters) res = ProductUtils.get_product_sku(query=query, offset=offset, size=size, sort_type=sort_type, filters=filters)
product_list = [] product_list = []
res_hit = res["hits"]["hits"] res_hit = res["hits"]
for item in res_hit: for item in res_hit:
product_id = item["_source"]["id"] product_id = item["_source"]["id"]
product_list.append(product_id) product_list.append(product_id)
return {"product_hot_ids:%s" % product_list} return {"product_hot_ids": product_list}
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"pict_pictorial_ids_list": []} return {"product_hot_ids": []}
{
"dynamic":"strict",
"properties": {
"id":{"type":"long"},
"is_online":{"type":"boolean"},//上线
"is_deleted":{"type":"boolean"},
"description":{"type":"text","analyzer":"gm_default_index","search_analyzer":"gm_default_search"},
"create_time":{"type":"date", "format":"date_time_no_millis"},
"update_time":{"type":"date", "format":"date_time_no_millis"},
"start_time":{"type":"long"},
"end_time":{"type":"long"},
"version":{"type":"long"}
}
}
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
"effective":{"type":"boolean"}, "effective":{"type":"boolean"},
"offline_score":{"type":"long"}, "offline_score":{"type":"long"},
"is_default":{"type":"long"}, "is_default":{"type":"long"},
"is_cover":{"type":"boolean"} "is_cover":{"type":"boolean"},
"topic_vote_number":{"type":"long"},
"activity_join":{"type":"long"}
} }
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ import logging ...@@ -4,7 +4,7 @@ import logging
import traceback import traceback
from .tag import Tag from .tag import Tag
from .topic import Topic from .topic import Topic, TopicBillBoard
class PictorialFollow(models.Model): class PictorialFollow(models.Model):
...@@ -78,7 +78,8 @@ class Pictorial(models.Model): ...@@ -78,7 +78,8 @@ class Pictorial(models.Model):
for topic_id in topic_id_list: for topic_id in topic_id_list:
topic_id_object = Topic.objects.filter(id=int(topic_id)).first() topic_id_object = Topic.objects.filter(id=int(topic_id)).first()
if topic_id_object and topic_id_object.is_online and int(topic_id_object.content_level) in [0, 3, 4, 5,6]: if topic_id_object and topic_id_object.is_online and int(topic_id_object.content_level) in [0, 3, 4, 5,
6]:
effective_num += 1 effective_num += 1
if effective_num >= 5: if effective_num >= 5:
ret = True ret = True
...@@ -145,6 +146,31 @@ class Pictorial(models.Model): ...@@ -145,6 +146,31 @@ class Pictorial(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return False return False
def get_topic_vote_number(self):
try:
topic_vote = TopicBillBoard.objects.filter(pictorial_id=self.id).values("real_vote_cnt", "virt_vote_cnt")
total_vote_cnt = 0
if topic_vote:
for item in topic_vote:
total_vote_cnt += int(item["virt_vote_cnt"]) + int(item["real_vote_cnt"])
return total_vote_cnt
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return 0
def get_activity_join(self):
try:
activicy_list = list(CommunityPictorialActivityRelation.objects.filter(pictorial_id=self.id, is_online=True,
is_deleted=False).values_list(
"pictorial_activity_id", flat=True))
return activicy_list
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
class PictorialTag(models.Model): class PictorialTag(models.Model):
"""画报关注标签""" """画报关注标签"""
...@@ -160,3 +186,31 @@ class PictorialTag(models.Model): ...@@ -160,3 +186,31 @@ class PictorialTag(models.Model):
pictorial_id = models.BigIntegerField(verbose_name=u'画报ID', max_length=20) pictorial_id = models.BigIntegerField(verbose_name=u'画报ID', max_length=20)
tag_id = models.BigIntegerField(verbose_name=u'标签ID', max_length=20) tag_id = models.BigIntegerField(verbose_name=u'标签ID', max_length=20)
is_online = models.BooleanField(verbose_name=u'是否上线', max_length=1) is_online = models.BooleanField(verbose_name=u'是否上线', max_length=1)
class CommunityPictorialActivity(models.Model):
"""榜单活动"""
class Meta:
verbose_name = u"画报标签"
app_label = "community"
db_table = "community_pictorial_activity"
start_time = models.DateTimeField(verbose_name=u'开始时间', default=datetime.datetime.fromtimestamp(0))
end_time = models.DateTimeField(verbose_name=u'结束时间', default=datetime.datetime.fromtimestamp(0))
is_online = models.BooleanField(verbose_name=u'是否上线', max_length=1)
is_deleted = models.BooleanField(verbose_name=u'是否被删除', max_length=1)
class CommunityPictorialActivityRelation(models.Model):
"""榜单活动关系"""
class Meta:
verbose_name = u"画报标签"
app_label = "community"
db_table = "community_pictorial_activity_relation"
is_online = models.BooleanField(verbose_name=u'是否上线', max_length=1)
is_deleted = models.BooleanField(verbose_name=u'是否被删除', max_length=1)
pictorial_activity_id = models.BigIntegerField(verbose_name=u'活动ID', max_length=20)
pictorial_id = models.BigIntegerField(verbose_name=u'榜单ID', max_length=20)
...@@ -68,6 +68,8 @@ class PictorialTransfer(object): ...@@ -68,6 +68,8 @@ class PictorialTransfer(object):
res["offline_score"] = cls.get_offline_score(instance, res["topic_id_list"]) res["offline_score"] = cls.get_offline_score(instance, res["topic_id_list"])
res["is_default"] = instance.is_default res["is_default"] = instance.is_default
res["is_cover"] = instance.get_is_cover(res["topic_id_list"]) res["is_cover"] = instance.get_is_cover(res["topic_id_list"])
res["topic_vote_number"] = instance.get_topic_vote_number()
res["activity_join"] = instance.get_activity_join()
return res return res
except: except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc()) logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
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