Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7250594f
authored
Oct 29, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
619cd36c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
23 deletions
service/query/optimum_query.go
service/query/optimum_query.go
View file @
7250594f
...
...
@@ -18,40 +18,36 @@ https://ichunt.com/optimum-9987_1.html?ev=brand_12042^2660_128036||128037
*/
func
GetOptimumAttrQuery
(
ctx
*
gin
.
Context
,
REQUEST_ATTR
*
map
[
string
][]
string
,
types
int
)
(
param
string
,
err
error
){
query
:=
elastic
.
NewBoolQuery
()
query1
:=
elastic
.
NewBoolQuery
()
query2
:=
elastic
.
NewBoolQuery
()
//
query1 := elastic.NewBoolQuery()
//
query2 := elastic.NewBoolQuery()
//二级分类查询
class_id2
:=
ctx
.
Request
.
FormValue
(
"class_id2"
)
if
class_id2
==
""
{
return
""
,
errors
.
New
(
"二级分类不得为空"
)
}
else
{
query
1
.
Must
(
elastic
.
NewTermQuery
(
"class_id2"
,
class_id2
))
query
.
Must
(
elastic
.
NewTermQuery
(
"class_id2"
,
class_id2
))
}
if
ctx
.
Request
.
FormValue
(
"avail_rank"
)
==
"1"
{
//只显示有货
query
.
Must
(
elastic
.
NewRangeQuery
(
"stock"
)
.
Gt
(
0
))
}
if
ctx
.
Request
.
FormValue
(
"goods_name/condition"
)
!=
""
{
//型号搜索
query
1
.
Must
(
elastic
.
NewTermQuery
(
"goods_name"
,
ctx
.
Request
.
FormValue
(
"goods_name/condition"
)))
query
.
Must
(
elastic
.
NewTermQuery
(
"goods_name"
,
ctx
.
Request
.
FormValue
(
"goods_name/condition"
)))
}
//存在属性查询
isClassAttr
:=
0
//存在其他属性搜索
if
len
(
*
REQUEST_ATTR
)
>
0
{
//存在属性搜索
redisr
:=
gredis
.
Conn
(
"search_r"
)
for
attr_name_id
,
attr_value_ids
:=
range
*
REQUEST_ATTR
{
print
(
attr_name_id
)
if
attr_name_id
==
"brand"
{
for
_
,
attr_value_id
:=
range
attr_value_ids
{
query
1
.
Should
(
elastic
.
NewTermQuery
(
"brand_id"
,
attr_value_id
))
query
.
Must
(
elastic
.
NewTermQuery
(
"brand_id"
,
attr_value_id
))
}
}
else
{
isClassAttr
=
1
for
_
,
attr_value_id
:=
range
attr_value_ids
{
attr_name
,
_
:=
gredis
.
String
(
redisr
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_by_id"
)
.
String
(),
attr_name_id
))
//查询唯一值,反查sku_id
attr_value_name
,
_
:=
gredis
.
String
(
redisr
.
Do
(
"HGET"
,
config
.
Get
(
"redis_all.class_attr_value_by_id"
)
.
String
(),
attr_value_id
))
//查询唯一值,反查sku_id
query
2
.
Should
(
elastic
.
NewNestedQuery
(
"attrs"
,
elastic
.
NewBoolQuery
()
.
Must
(
elastic
.
NewTermQuery
(
"attrs.attr_name"
,
attr_name
),
elastic
.
NewTermQuery
(
"attrs.attr_value"
,
attr_value_name
))))
query
.
Must
(
elastic
.
NewNestedQuery
(
"attrs"
,
elastic
.
NewBoolQuery
()
.
Must
(
elastic
.
NewTermQuery
(
"attrs.attr_name"
,
attr_name
),
elastic
.
NewTermQuery
(
"attrs.attr_value"
,
attr_value_name
))))
}
}
}
...
...
@@ -86,26 +82,26 @@ func GetOptimumAttrQuery(ctx *gin.Context,REQUEST_ATTR *map[string][]string,type
source
.
Size
(
common
.
MyInt
(
page_size
))
source
.
From
(
page_from
)
source
.
Sort
(
"supplier_name"
,
true
)
//true asc,自营数据在前
source
.
Sort
(
"sort"
,
false
)
//true asc,可购买在前
//排序
if
ctx
.
Request
.
FormValue
(
"stock_rank"
)
==
"2"
{
source
.
Sort
(
"stock"
,
true
)
//true asc
}
else
{
source
.
Sort
(
"stock"
,
false
)
//true asc
if
ctx
.
Request
.
FormValue
(
"stock_rank"
)
==
"1"
{
//库存排序,最多库存最前
source
.
Sort
(
"stock"
,
false
)
//true asc
}
if
ctx
.
Request
.
FormValue
(
"single_rank"
)
==
"2"
{
source
.
Sort
(
"lower_price"
,
true
)
//true asc
}
else
{
source
.
Sort
(
"lower_price"
,
false
)
//true asc
if
ctx
.
Request
.
FormValue
(
"stock_rank"
)
==
"2"
{
//库存排序,最少库存最前
source
.
Sort
(
"stock"
,
true
)
//true asc
}
}
if
ctx
.
Request
.
FormValue
(
"single_rank"
)
==
"1"
{
//价格最高在前
source
.
Sort
(
"lower_price"
,
false
)
//true asc
}
if
ctx
.
Request
.
FormValue
(
"single_rank"
)
==
"2"
{
//价格最高在后
source
.
Sort
(
"lower_price"
,
true
)
//true asc
}
query
.
Must
(
query1
)
if
isClassAttr
==
1
{
//存在nested 参数搜索
query
.
Must
(
query2
)
}
source
.
Query
(
query
)
searchRequest
:=
elastic
.
NewSearchRequest
()
.
Source
(
source
)
param
,
_
=
searchRequest
.
Body
()
...
...
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