Commit ed060f31 authored by lixiaofang's avatar lixiaofang

add

parent 7851173c
......@@ -13,8 +13,12 @@ from libs.es import ESPerform
from trans2es.models.pictorial import PictorialTopics
def get_product_sku(query='', offset=0, size=10, sort_type=PRODUCT_ORDER_TYPE.DEFAULT, filters={}):
class ProductUtils(object):
@classmethod
def get_product_sku(cls, query='', offset=0, size=10, sort_type='', filters={}):
try:
q = []
multi_fields = {
'cn_name_pre': 2,
'en_name_pre': 2,
......@@ -32,10 +36,19 @@ def get_product_sku(query='', offset=0, size=10, sort_type=PRODUCT_ORDER_TYPE.DE
'operator': 'and',
'fields': query_fields,
}
q = []
if query != '':
sku_must_flter = cls.sku_filter(filters)
logging.info("get sku_must_flter:%s " % sku_must_flter)
logging.info("get sku_must_flter:%s " % type(sku_must_flter))
q["query"] = {
"bool": {
"must": sku_must_flter
}
}
if query != '':
q["query"] += {
"bool": {
"should": {
"multi_match": multi_match
......@@ -44,7 +57,59 @@ def get_product_sku(query='', offset=0, size=10, sort_type=PRODUCT_ORDER_TYPE.DE
}
}
q["sort"] = [{"comment_nums": {"order": "desc"}}]
logging.info("get product query:%s" % q)
result_dict = ESPerform.get_search_results(ESPerform.get_cli(), sub_index_name="product", query_body=q,
offset=offset, size=size)
return result_dict
except:
logging.error("catch exception, query_sku:%s" % traceback.format_exc())
return []
@classmethod
def sku_filter(cls, filters):
"""处理过滤器部分。"""
logging.info("get filters:%s" % filters)
f = [
{'term': {"have_image": True}},
{'term': {"is_online": True}},
{'term': {"is_deleted": False}},
]
if not filters:
return f
for k, v in filters.items():
if v in (None, '', []):
continue
if k == "brand":
f.append({"term": {"cn_name_pre": v}},
{"term": {"en_name_pre": v}},
{"term": {"alias": v}}, )
if k == "effect":
f.append({"term": {"effect_cn_name": v}})
if k == "catrgory":
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
......@@ -7,14 +7,13 @@ import traceback
import json
from libs.cache import redis_client
from libs.es import ESPerform
from search.utils.group import GroupUtils
from search.utils.product import ProductUtils
from search.utils.common import GroupSortTypes
from libs.es import ESPerform
from trans2es.models.pictorial import PictorialTopics
@bind("physical/search/product_sort")
def pictorial_topic_sort(query='', offset=0, size=2, sort_type=PRODUCT_ORDER_TYPE.DEFAULT, filters={}):
@bind("physical/search/query_product_sku")
def product_hot_sort(query='', offset=0, size=2, sort_type='', filters={}):
'''
商品sku排序
:param query:
......@@ -25,8 +24,16 @@ def pictorial_topic_sort(query='', offset=0, size=2, sort_type=PRODUCT_ORDER_TYP
:return:
'''
try:
res = 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 = []
res_hit = res["hits"]["hits"]
for item in res_hit:
product_id = item["_source"]["id"]
product_list.append(product_id)
return {"product_hot_ids:%s" % product_list}
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return {"pict_pictorial_ids_list": []}
{
"dynamic":"strict",
"_routing": {"required": true},
"_routing": {"required": false},
"properties": {
"id":{"type":"long"}, //id
"is_online":{"type":"boolean"},//上线
......
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