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
f6058c6f
authored
Jun 11, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复es的should的问题
parent
01ee5f70
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
8 deletions
internal/logic/attr.go
internal/logic/attr.go
View file @
f6058c6f
...
@@ -55,8 +55,9 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
...
@@ -55,8 +55,9 @@ func MatchGoodsNameByAttrs(bomItems []model.BomItem) (result []model.BomItem, er
if
responses
.
Hits
!=
nil
{
if
responses
.
Hits
!=
nil
{
for
_
,
hit
:=
range
responses
.
Hits
.
Hits
{
for
_
,
hit
:=
range
responses
.
Hits
.
Hits
{
res
,
_
:=
hit
.
Source
.
MarshalJSON
()
res
,
_
:=
hit
.
Source
.
MarshalJSON
()
//还要去判断至少符合特定数量参数匹配的结果,比如最小匹配参数为2,那就是要有两个参数匹配到才正确
bomItems
[
key
]
.
GoodsName
=
gjson
.
Get
(
string
(
res
),
"goods_name"
)
.
String
()
bomItems
[
key
]
.
GoodsName
=
gjson
.
Get
(
string
(
res
),
"goods_name"
)
.
String
()
fmt
.
Println
(
gjson
.
Get
(
string
(
res
),
"goods_name"
)
.
String
(
))
fmt
.
Println
(
string
(
res
))
}
}
}
}
}
}
...
@@ -114,7 +115,6 @@ func changeKeyword(attr string) (result string) {
...
@@ -114,7 +115,6 @@ func changeKeyword(attr string) (result string) {
compile
,
_
:=
regexp
.
Compile
(
regexpStr
)
compile
,
_
:=
regexp
.
Compile
(
regexpStr
)
attr
=
compile
.
ReplaceAllString
(
attr
,
regular
)
attr
=
compile
.
ReplaceAllString
(
attr
,
regular
)
}
}
fmt
.
Println
(
attr
)
return
attr
return
attr
}
}
...
@@ -198,21 +198,24 @@ func getAttrValueByAttr(attr string) (attrValue string) {
...
@@ -198,21 +198,24 @@ func getAttrValueByAttr(attr string) (attrValue string) {
//获取匹配的条件
//获取匹配的条件
func
getQuery
(
attrs
[]
string
)
(
query
*
es
.
BoolQuery
)
{
func
getQuery
(
attrs
[]
string
)
(
query
*
es
.
BoolQuery
)
{
subQuery
:=
es
.
NewBoolQuery
()
var
subQuery
*
es
.
TermQuery
query
=
es
.
NewBoolQuery
()
for
_
,
attr
:=
range
attrs
{
for
_
,
attr
:=
range
attrs
{
//还要判断是不是一个单位对应多个属性的
if
strings
.
Contains
(
attr
,
"|"
)
{
if
strings
.
Contains
(
attr
,
"|"
)
{
name
:=
strings
.
Split
(
attr
,
"€"
)[
0
]
name
:=
strings
.
Split
(
attr
,
"€"
)[
0
]
value
:=
strings
.
Split
(
attr
,
"€"
)[
1
]
value
:=
strings
.
Split
(
attr
,
"€"
)[
1
]
multiAttr
:=
strings
.
Split
(
name
,
"|"
)
multiAttr
:=
strings
.
Split
(
name
,
"|"
)
for
_
,
temp
:=
range
multiAttr
{
for
_
,
temp
:=
range
multiAttr
{
subQuery
=
subQuery
.
Should
(
es
.
NewTermQuery
(
"attrs.attr_value"
,
temp
+
"€"
+
value
)
)
subQuery
=
es
.
NewTermQuery
(
"attrs.attr_value"
,
temp
+
"€"
+
value
)
}
}
}
else
{
}
else
{
subQuery
=
subQuery
.
Should
(
es
.
NewTermQuery
(
"attrs.attr_value"
,
attr
))
subQuery
=
es
.
NewTermQuery
(
"attrs.attr_value"
,
attr
)
}
}
}
nestedQuery
:=
es
.
NewNestedQuery
(
"attrs"
,
subQuery
)
nestedQuery
:=
es
.
NewNestedQuery
(
"attrs"
,
subQuery
)
query
=
es
.
NewBoolQuery
()
query
.
Should
(
nestedQuery
)
query
=
query
.
Filter
(
nestedQuery
)
query
.
MinimumNumberShouldMatch
(
2
)
}
return
query
return
query
}
}
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