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
232bb276
authored
Mar 15, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
优化
parent
eed93a88
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
5 deletions
internal/logic/attr.go
internal/logic/search.go
internal/logic/attr.go
View file @
232bb276
...
...
@@ -75,7 +75,7 @@ func GetStandardAttrs(bomItems []model.BomItem) []model.BomItem {
if
!
strings
.
Contains
(
attr
,
"€"
)
{
attr
=
strings
.
ToUpper
(
attr
)
attrName
,
_
:=
redis
.
String
(
gredis
.
HGet
(
"sku_map2"
,
attr
))
if
attrName
!=
""
{
if
attrName
!=
""
{
attrsSlice
[
key
]
=
attrName
+
"€"
+
attr
}
}
...
...
internal/logic/search.go
View file @
232bb276
...
...
@@ -113,10 +113,14 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
replace
,
_
:=
regexp
.
Compile
(
"[^A-Za-z0-9]+"
)
goodsName
:=
replace
.
ReplaceAllString
(
bomItem
.
GoodsName
,
""
)
goodsName
=
strings
.
ToUpper
(
goodsName
)
//用于判断下面的miniShould,因为下面的参数里面,如果出现阻值的,用的是should语句
//为了保证所有参数都必须参与搜索,所以要用miniShould去做限制
//var shouldNumber int
//商品名称太短的或者没有商品名称的,去搜索参数
if
len
(
goodsName
)
<=
3
{
if
len
(
bomItem
.
AttrList
)
>
0
{
//var params []interface{}
q
:=
es
.
NewBoolQuery
()
q
.
MinimumNumberShouldMatch
(
1
)
for
_
,
attr
:=
range
bomItem
.
AttrList
{
if
!
strings
.
Contains
(
attr
,
"€"
)
{
continue
...
...
@@ -127,11 +131,13 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
}
//需要注意的点 : 因为0.158Ω可以对应 电阻 或者 直流电阻 ,所以当识别出来是电阻 或者 直流电阻 的时候,就不能用must,要用should
if
strings
.
Contains
(
attr
,
"ZLNZ€"
)
||
strings
.
Contains
(
attr
,
"OM€"
)
{
query
.
Should
(
es
.
NewTermQuery
(
"attr_bom"
,
attr
))
//query.Should(es.NewTermQuery("attr_bom", attr))
q
.
Should
(
es
.
NewTermQuery
(
"attr_bom"
,
attr
))
}
else
{
query
.
Must
(
es
.
NewTermQuery
(
"attr_bom"
,
attr
))
}
}
query
.
Must
(
q
)
}
else
{
query
=
query
.
Must
(
es
.
NewTermsQuery
(
"attr_bom"
,
"$_$"
))
}
...
...
@@ -141,7 +147,7 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
//判断是否存在brandName并且匹配不到对应的标准品牌
if
bomItem
.
BrandName
!=
""
{
bomItem
.
BrandName
=
strings
.
ToUpper
(
bomItem
.
BrandName
)
query
=
query
.
Should
(
es
.
New
ConstantScoreQuery
(
es
.
NewTermQuery
(
"brand_name"
,
bomItem
.
BrandName
))
.
Boost
(
2
))
query
=
query
.
Should
(
es
.
New
TermQuery
(
"brand_name"
,
bomItem
.
BrandName
))
}
//判断封装是否有,有的话,直接去搜索封装
if
bomItem
.
Encap
!=
""
{
...
...
@@ -149,7 +155,7 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
}
//搜索库存
//fmt.Println("总数量:", bomItem.Number, bomItem.Amount)
query
=
query
.
Should
(
es
.
New
ConstantScoreQuery
(
es
.
NewRangeQuery
(
"stock"
)
.
Gte
(
bomItem
.
Number
*
bomItem
.
Amount
)
))
query
=
query
.
Should
(
es
.
New
RangeQuery
(
"stock"
)
.
Gte
(
bomItem
.
Number
*
bomItem
.
Amount
))
}
else
{
query
=
query
.
Must
(
es
.
NewTermQuery
(
"auto_goods_name"
,
bomItem
.
GoodsName
))
}
...
...
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