Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
bom_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
1bf9ad55
authored
Dec 09, 2022
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复状态问题
parent
192071e0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
12 deletions
internal/logic/search.go
internal/logic/search.go
View file @
1bf9ad55
...
...
@@ -10,7 +10,7 @@ import (
"strings"
)
func
search
(
index
string
,
bomId
int
,
bomItems
[]
model
.
BomItem
,
deliveryType
,
sort
int
,
client
*
es
.
Client
,
rawSearch
bool
,
isAlike
bool
)
(
goodsMapList
[]
GoodsMap
,
err
error
)
{
func
search
(
index
string
,
bomId
int
,
bomItems
[]
model
.
BomItem
,
deliveryType
,
sort
int
,
client
*
es
.
Client
,
rawSearch
bool
,
isAlike
bool
)
(
goodsMapList
[]
GoodsMap
,
err
error
)
{
//先去自营查一遍
search
:=
client
.
MultiSearch
()
.
Index
(
index
)
//是否已经搜索过标签
...
...
@@ -32,10 +32,10 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
paramsRawSearch
=
true
}
//构建一个goods_name对应的bomItems列表
searchRequest
:=
getSearchParams
(
index
,
bom
,
sort
,
paramsRawSearch
,
rawSearch
,
isAlike
)
searchRequest
:=
getSearchParams
(
index
,
bom
,
sort
,
paramsRawSearch
,
rawSearch
,
isAlike
)
searchFlag
=
true
common
.
PrintDebug
(
"查询es索引,"
,
"是否原生rawSearch:"
,
rawSearch
,
" 是否类似:"
,
isAlike
,
index
)
common
.
PrintDebug
(
"查询es索引,"
,
"是否原生rawSearch:"
,
rawSearch
,
" 是否类似:"
,
isAlike
,
index
)
common
.
PrintDebug
(
searchRequest
.
Body
())
//randInt := rand.Intn(10)
...
...
@@ -50,7 +50,6 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
common
.
PrintDebug
(
res
.
Responses
)
if
err
!=
nil
{
return
}
...
...
@@ -83,16 +82,18 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
}
}
}
common
.
PrintDebug
(
"search end"
)
return
}
//构建请求参数
func
getSearchParams
(
index
string
,
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
,
rawSearch
bool
,
isAlike
bool
)
(
searchRequest
*
es
.
SearchRequest
)
{
func
getSearchParams
(
index
string
,
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
,
rawSearch
bool
,
isAlike
bool
)
(
searchRequest
*
es
.
SearchRequest
)
{
//fmt.Println("商品名称 : ", bomItem.GoodsName)
//fmt.Println("参数列表 : ", bomItem.AttrList)
bomItem
.
Encap
=
TransformEncap
(
bomItem
.
Encap
)
//fmt.Println("封装 : ", bomItem.Encap)
query
:=
getTermQuery
(
bomItem
,
sort
,
flag
,
rawSearch
,
isAlike
)
query
:=
getTermQuery
(
bomItem
,
sort
,
flag
,
rawSearch
,
isAlike
)
source
:=
es
.
NewSearchSource
()
.
Query
(
query
)
if
sort
==
1
{
//source.Sort("_score", false)
...
...
@@ -114,7 +115,7 @@ func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool,ra
}
//构建term条件
func
getTermQuery
(
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
,
rawSearch
bool
,
isAlike
bool
)
(
query
*
es
.
BoolQuery
)
{
func
getTermQuery
(
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
,
rawSearch
bool
,
isAlike
bool
)
(
query
*
es
.
BoolQuery
)
{
query
=
es
.
NewBoolQuery
()
goodsName
:=
common
.
DrawLetterNum
(
bomItem
.
GoodsName
)
if
flag
{
...
...
@@ -169,19 +170,19 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,rawSearch bool,isAl
//精确匹配
if
rawSearch
{
query
=
query
.
Must
(
es
.
NewRangeQuery
(
"stock"
)
.
Gte
(
bomItem
.
Number
*
bomItem
.
Amount
))
//搜索库存
}
else
{
}
else
{
query
=
query
.
Should
(
es
.
NewRangeQuery
(
"stock"
)
.
Gte
(
bomItem
.
Number
*
bomItem
.
Amount
))
//搜索库存
}
}
else
if
isAlike
&&
goodsName
!=
""
{
//todo 推荐型号搜索
}
else
if
isAlike
&&
goodsName
!=
""
{
//todo 推荐型号搜索
query
=
query
.
Must
(
es
.
NewTermsQuery
(
"alike_spu_name.raw"
,
goodsName
))
}
else
if
goodsName
!=
""
{
query
=
query
.
Must
(
es
.
NewTermQuery
(
"goods_name"
,
goodsName
))
}
common
.
PrintDebug
(
"isalike:"
,
isAlike
)
common
.
PrintDebug
(
"isalike:"
,
isAlike
)
//只显示库存大于0的数据
if
rawSearch
==
false
{
//不是精确匹配
if
rawSearch
==
false
{
//不是精确匹配
query
.
Must
(
es
.
NewRangeQuery
(
"stock"
)
.
Gt
(
0
))
}
...
...
@@ -190,7 +191,7 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,rawSearch bool,isAl
// query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
//}
//只显示起订量大于0
query
.
Must
(
es
.
NewRangeQuery
(
"moq"
)
.
Gt
(
0
)
.
Lte
(
bomItem
.
Number
*
bomItem
.
Amount
))
//todo 2021.4.17 起订量高于需求数量的排除;
query
.
Must
(
es
.
NewRangeQuery
(
"moq"
)
.
Gt
(
0
)
.
Lte
(
bomItem
.
Number
*
bomItem
.
Amount
))
//todo 2021.4.17 起订量高于需求数量的排除;
if
configs
.
ApiSetting
.
Mode
!=
"debug"
{
query
=
query
.
Filter
(
es
.
NewTermQuery
(
"status"
,
1
))
...
...
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