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
4ecfdd6a
authored
Jun 17, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
优化参数查询
parent
faa39dc5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
37 additions
and
27 deletions
cmd/search_http_server.go
conf/config.ini
controller/course_controller.go
controller/course_topic_controller.go
protopb/bom/bom.pb.go
protos/bom.proto
service/attr_service.go
service/bom_service.go
cmd/search_http_server.go
View file @
4ecfdd6a
...
...
@@ -24,7 +24,7 @@ func main() {
port
:=
config
.
Get
(
"web.port"
)
.
String
()
//web改成micro 就是grpc,并直接注册到etcd里面
service
:=
web
.
NewService
(
web
.
Name
(
"go.micro.api.http.
bom
"
),
web
.
Name
(
"go.micro.api.http.
search
"
),
web
.
Handler
(
r
),
web
.
Address
(
":"
+
port
),
)
...
...
conf/config.ini
View file @
4ecfdd6a
[web]
port
=
9000
mode
=
debug
[message]
api_domain
=
http://api.ichunt.com/msg/sendMessageByAuto
...
...
controller/course_controller.go
View file @
4ecfdd6a
...
...
@@ -7,7 +7,7 @@ import (
"search_server/service"
)
func
i
nit
()
{
func
I
nit
()
{
courseService
:=
service
.
NewCourseServiceImpl
()
gin_
.
NewBuilder
()
.
WithService
(
courseService
)
.
WithMiddleware
(
Check_Middleware
())
.
...
...
controller/course_topic_controller.go
View file @
4ecfdd6a
...
...
@@ -7,7 +7,7 @@ import (
"search_server/service"
)
func
init
()
{
func
Init2
()
{
courseService
:=
service
.
NewCourseTopicServiceImpl
()
gin_
.
NewBuilder
()
.
WithService
(
courseService
)
.
WithMiddleware
(
Check_Middleware
())
.
...
...
protopb/bom/bom.pb.go
View file @
4ecfdd6a
This diff is collapsed.
Click to expand it.
protos/bom.proto
View file @
4ecfdd6a
...
...
@@ -22,16 +22,18 @@ message AutoSpuResponse{
message
RecommendRequest
{
// @inject_tag: form:"goods_name"
string
goods_name
=
1
;
// @inject_tag: form:"attrs"
string
attrs
=
2
;
// @inject_tag: form:"encap"
string
encap
=
3
;
// @inject_tag: form:"num"
int32
num
=
2
;
int32
num
=
4
;
// @inject_tag: form:"delivery_type"
int32
delivery_type
=
3
;
int32
delivery_type
=
5
;
// @inject_tag: form:"flag"
int32
flag
=
4
;
// @inject_tag: form:"p"
int32
p
=
5
;
// @inject_tag: form:"offset"
int32
offset
=
6
;
int32
flag
=
6
;
// @inject_tag: form:"brand_name"
string
brand_name
=
7
;
}
message
ResponseData
{
...
...
service/attr_service.go
View file @
4ecfdd6a
...
...
@@ -15,8 +15,7 @@ import (
)
//根据参数去匹配商品
func
SearchAttr
(
attrOrigin
string
)
(
goodsName
string
,
err
error
)
{
//attrOrigin有可能是参数也可能是型号名称
func
SearchAttr
(
attrOrigin
,
encap
string
)
(
goodsName
string
,
err
error
)
{
//先去切割参数得到参数列表
attrs
:=
splitAttrs
(
attrOrigin
)
var
attrsSlice
[]
string
...
...
@@ -25,6 +24,17 @@ func SearchAttr(attrOrigin string) (goodsName string, err error) {
attr
=
TransformESParam
(
attr
)
attrsSlice
=
append
(
attrsSlice
,
attr
)
}
if
encap
!=
""
{
//先提取出纯数字
numberR
,
_
:=
regexp
.
Compile
(
common
.
PureNumberRegular
)
pureNumber
:=
numberR
.
FindString
(
encap
)
//再去找对应属性
attrName
,
_
:=
redis
.
String
(
gredis
.
HGet
(
"sku_map2"
,
pureNumber
))
if
attrName
!=
""
{
attrValue
:=
attrName
+
"€"
+
pureNumber
attrsSlice
=
append
(
attrsSlice
,
attrValue
)
}
}
query
:=
getQuery
(
attrsSlice
)
source
:=
elastic
.
NewSearchSource
()
.
Query
(
query
)
source
.
Sort
(
"brand_sort"
,
true
)
...
...
service/bom_service.go
View file @
4ecfdd6a
...
...
@@ -75,22 +75,25 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) {
//推荐商品搜索
func
Recommend
(
req
*
bom
.
RecommendRequest
)
(
rsp
*
bom
.
ResponseData
)
{
var
err
error
//先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称
goodsNameByAttr
,
err
:=
SearchAttr
(
req
.
GoodsName
)
if
goodsNameByAttr
!=
""
{
req
.
GoodsName
=
goodsNameByAttr
var
goodsName
string
if
req
.
GoodsName
!=
""
{
goodsName
,
err
=
SearchAttr
(
req
.
GoodsName
,
req
.
Encap
)
}
//如果没有型号,但是有参数(参数有可能是型号),那就去匹配参数
if
req
.
GoodsName
==
""
&&
req
.
Attrs
!=
""
{
goodsName
,
err
=
SearchAttr
(
req
.
Attrs
,
req
.
Encap
)
}
if
goodsName
!=
""
{
req
.
GoodsName
=
goodsName
}
//转换请求参数
req
=
changeRecommendReq
(
req
)
//获取需要请求的索引
index
:=
getRecommendSearchIndex
(
req
)
//是否是精确匹配
isRawSearch
:=
false
if
req
.
Flag
==
3
{
isRawSearch
=
true
}
//获取es的请求参数
queryJson
:=
getRecommendSearchParams
(
isRawSearch
,
req
)
queryJson
:=
getRecommendSearchParams
(
true
,
req
)
result
,
err
:=
es
.
CurlES
(
index
,
queryJson
)
if
err
!=
nil
{
log
.
Error
(
err
)
...
...
@@ -120,12 +123,6 @@ func changeRecommendReq(req *bom.RecommendRequest) (res *bom.RecommendRequest) {
if
req
.
Num
==
0
{
req
.
Num
=
1
}
if
req
.
P
==
0
{
req
.
P
=
1
}
if
!
(
req
.
P
>
1
)
{
req
.
Flag
=
3
}
//转换处理商品名称
replace
,
_
:=
regexp
.
Compile
(
"[^A-Za-z0-9]+"
)
req
.
GoodsName
=
replace
.
ReplaceAllString
(
req
.
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