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
8b77667a
authored
Apr 21, 2021
by
hcy001
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
BOM4
parent
9793c198
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
10 deletions
internal/common/common.go
internal/logic/search.go
internal/common/common.go
View file @
8b77667a
...
@@ -9,10 +9,24 @@ import (
...
@@ -9,10 +9,24 @@ import (
"github.com/shopspring/decimal"
"github.com/shopspring/decimal"
"github.com/syyongx/php2go"
"github.com/syyongx/php2go"
"reflect"
"reflect"
"regexp"
"strconv"
"strconv"
"strings"
)
)
/*
/*
提取字符串的字母数字并去掉空格
@param string target_str 目标字符串
@return 返回格式化后字符串
*/
func
DrawLetterNum
(
target_str
string
)
(
str
string
)
{
if
target_str
==
""
{
return
""
}
replace
,
_
:=
regexp
.
Compile
(
"[^A-Za-z0-9]+"
)
return
strings
.
ToUpper
(
replace
.
ReplaceAllString
(
target_str
,
""
))
}
/*
定时任务打印输出
定时任务打印输出
@parm jsonStr 需要json输出的内容
@parm jsonStr 需要json输出的内容
*/
*/
...
...
internal/logic/search.go
View file @
8b77667a
...
@@ -7,7 +7,6 @@ import (
...
@@ -7,7 +7,6 @@ import (
"context"
"context"
"encoding/json"
"encoding/json"
es
"gopkg.in/olivere/elastic.v5"
es
"gopkg.in/olivere/elastic.v5"
"regexp"
"strings"
"strings"
)
)
...
@@ -112,11 +111,8 @@ func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool,is
...
@@ -112,11 +111,8 @@ func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool,is
//构建term条件
//构建term条件
func
getTermQuery
(
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
,
isAlike
bool
)
(
query
*
es
.
BoolQuery
)
{
func
getTermQuery
(
bomItem
model
.
BomItem
,
sort
int
,
flag
bool
,
isAlike
bool
)
(
query
*
es
.
BoolQuery
)
{
query
=
es
.
NewBoolQuery
()
query
=
es
.
NewBoolQuery
()
goodsName
:=
common
.
DrawLetterNum
(
bomItem
.
GoodsName
)
if
flag
{
if
flag
{
field
:=
"auto_goods_name.raw"
replace
,
_
:=
regexp
.
Compile
(
"[^A-Za-z0-9]+"
)
goodsName
:=
replace
.
ReplaceAllString
(
bomItem
.
GoodsName
,
""
)
goodsName
=
strings
.
ToUpper
(
goodsName
)
//用于判断下面的miniShould,因为下面的参数里面,如果出现阻值的,用的是should语句
//用于判断下面的miniShould,因为下面的参数里面,如果出现阻值的,用的是should语句
//为了保证所有参数都必须参与搜索,所以要用miniShould去做限制
//为了保证所有参数都必须参与搜索,所以要用miniShould去做限制
//var shouldNumber int
//var shouldNumber int
...
@@ -150,7 +146,10 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
...
@@ -150,7 +146,10 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
query
=
query
.
Must
(
es
.
NewTermsQuery
(
"attr_bom"
,
"$_$"
))
query
=
query
.
Must
(
es
.
NewTermsQuery
(
"attr_bom"
,
"$_$"
))
}
}
}
}
query
=
query
.
Filter
(
es
.
NewTermQuery
(
field
,
goodsName
))
if
goodsName
!=
""
{
query
=
query
.
Filter
(
es
.
NewTermQuery
(
"auto_goods_name.raw"
,
goodsName
))
}
//判断是否存在brandName并且匹配不到对应的标准品牌
//判断是否存在brandName并且匹配不到对应的标准品牌
if
bomItem
.
BrandName
!=
""
{
if
bomItem
.
BrandName
!=
""
{
...
@@ -163,10 +162,10 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
...
@@ -163,10 +162,10 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
}
}
//搜索库存
//搜索库存
query
=
query
.
Should
(
es
.
NewRangeQuery
(
"stock"
)
.
Gte
(
bomItem
.
Number
*
bomItem
.
Amount
))
query
=
query
.
Should
(
es
.
NewRangeQuery
(
"stock"
)
.
Gte
(
bomItem
.
Number
*
bomItem
.
Amount
))
}
else
if
isAlike
{
//todo 推荐型号搜索
}
else
if
isAlike
&&
goodsName
!=
""
{
//todo 推荐型号搜索
query
=
query
.
Must
(
es
.
NewTermsQuery
(
"alike_spu_name.raw"
,
bomItem
.
G
oodsName
))
query
=
query
.
Must
(
es
.
NewTermsQuery
(
"alike_spu_name.raw"
,
g
oodsName
))
}
else
{
}
else
if
goodsName
!=
""
{
query
=
query
.
Must
(
es
.
NewTermQuery
(
"auto_goods_name"
,
bomItem
.
G
oodsName
))
query
=
query
.
Must
(
es
.
NewTermQuery
(
"auto_goods_name"
,
g
oodsName
))
}
}
common
.
PrintDebug
(
"isalike:"
,
isAlike
)
common
.
PrintDebug
(
"isalike:"
,
isAlike
)
...
...
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