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
818d2023
authored
Jun 23, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复结果为空
parent
f5879ea5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
2 deletions
service/attr_service.go
service/bom_service.go
service/attr_service.go
View file @
818d2023
...
...
@@ -18,6 +18,23 @@ import (
func
SearchAttr
(
attrOrigin
,
encap
string
)
(
goodsName
string
,
err
error
)
{
//先去切割参数得到参数列表
attrs
:=
splitAttrs
(
attrOrigin
)
//当切割出来的参数大于1个的时候,就要去针对每个参数进行里面再一次提纯
if
len
(
attrs
)
>
1
{
for
key
,
attr
:=
range
attrs
{
attrs
[
key
]
=
changeKeyword
(
attr
)
//切割完以后,还要去对切割后的参数提取值,因为有可能参数没有分隔符
extractRes
:=
extractAttr
(
attrs
[
key
])
for
ek
,
eAttr
:=
range
extractRes
{
if
ek
==
0
{
attrs
[
key
]
=
extractRes
[
0
]
}
else
{
attrs
=
append
(
attrs
,
eAttr
)
}
}
}
}
else
{
attrs
=
extractAttrsByStr
(
attrs
[
0
])
}
var
attrsSlice
[]
string
//去转换每一个参数,得到去查询es的标准格式
for
_
,
attr
:=
range
attrs
{
...
...
@@ -72,6 +89,34 @@ func splitAttrs(attrs string) (result []string) {
return
}
//提取参数
func
extractAttr
(
attr
string
)
[]
string
{
regexpUnit
:=
strings
.
Join
(
getNeedCheckUnit
(),
"|"
)
r
,
_
:=
regexp
.
Compile
(
"(
\\
d+[
\\
/
\\
d. ]*|
\\
d)("
+
regexpUnit
+
")"
+
""
)
res
:=
r
.
FindAllString
(
attr
,
100
)
return
res
}
//提取参数,从一个字符串里面,注意要提取出两个参数才当作是
func
extractAttrsByStr
(
attr
string
)
[]
string
{
regexpUnit
:=
strings
.
Join
(
getNeedCheckUnit
(),
"|"
)
r
,
_
:=
regexp
.
Compile
(
"(
\\
d+[
\\
/
\\
d. ]*|
\\
d)("
+
regexpUnit
+
")"
+
""
)
res
:=
r
.
FindAllString
(
attr
,
100
)
if
len
(
res
)
<
2
{
return
[]
string
{
attr
}
}
return
res
}
func
getNeedCheckUnit
()
(
unitSlice
[]
string
)
{
unitMapping
:=
common
.
UnitValueMapping
for
unit
,
_
:=
range
unitMapping
{
unitSlice
=
append
(
unitSlice
,
unit
)
}
return
}
//将写法转成正规写法,转换单位,比如有的人喜欢将Ω输成欧姆或者O,所以要统一转成正常的Ω
func
changeKeyword
(
attr
string
)
(
result
string
)
{
regulars
:=
common
.
KeywordRegular
...
...
service/bom_service.go
View file @
818d2023
...
...
@@ -66,7 +66,9 @@ func AutoSpu(goodsName string) []string {
func
getTermQuery
(
goodsName
string
)
(
query
*
elastic
.
BoolQuery
)
{
query
=
elastic
.
NewBoolQuery
()
query
.
Filter
(
elastic
.
NewTermQuery
(
"auto_goods_name"
,
goodsName
))
query
.
Filter
(
elastic
.
NewTermQuery
(
"status"
,
1
))
if
config
.
Get
(
"web.mode"
)
.
String
()
!=
"debug"
{
query
.
Filter
(
elastic
.
NewTermQuery
(
"status"
,
1
))
}
query
.
MustNot
(
elastic
.
NewTermQuery
(
"brand_id"
,
0
))
return
query
}
...
...
@@ -170,7 +172,9 @@ func getBomTermQuery(goodsName, brandName string, number int32, isRawSearch bool
field
:=
"auto_goods_name"
query
=
query
.
Must
(
elastic
.
NewTermQuery
(
field
,
goodsName
))
}
query
=
query
.
Filter
(
elastic
.
NewTermQuery
(
"status"
,
1
))
if
config
.
Get
(
"web.mode"
)
.
String
()
!=
"debug"
{
query
.
Filter
(
elastic
.
NewTermQuery
(
"status"
,
1
))
}
source
:=
elastic
.
NewSearchSource
()
.
Query
(
query
)
source
.
From
(
0
)
if
isRawSearch
{
...
...
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