Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
alpha
physical
Commits
ed060f31
Commit
ed060f31
authored
Jul 09, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add
parent
7851173c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
9 deletions
+81
-9
product.py
search/utils/product.py
+68
-3
product.py
search/views/product.py
+12
-5
product.json
trans2es/mapping/product.json
+1
-1
No files found.
search/utils/product.py
View file @
ed060f31
...
...
@@ -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
search/views/product.py
View file @
ed060f31
...
...
@@ -7,14 +7,13 @@ import traceback
import
json
from
libs.cache
import
redis_client
from
libs.es
import
ESPerform
from
search.utils.
group
import
Group
Utils
from
search.utils.
product
import
Product
Utils
from
search.utils.common
import
GroupSortTypes
from
libs.es
import
ESPerform
from
trans2es.models.pictorial
import
PictorialTopics
@bind
(
"physical/search/
product_sort
"
)
def
p
ictorial_topic_sort
(
query
=
''
,
offset
=
0
,
size
=
2
,
sort_type
=
PRODUCT_ORDER_TYPE
.
DEFAULT
,
filters
=
{}):
@bind
(
"physical/search/
query_product_sku
"
)
def
p
roduct_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"
:
[]}
trans2es/mapping/product.json
View file @
ed060f31
{
"dynamic"
:
"strict"
,
"_routing"
:
{
"required"
:
tru
e
},
"_routing"
:
{
"required"
:
fals
e
},
"properties"
:
{
"id"
:{
"type"
:
"long"
},
//id
"is_online"
:{
"type"
:
"boolean"
},
//上线
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment