Commit 4ecfdd6a by mushishixian

优化参数查询

parent faa39dc5
...@@ -24,7 +24,7 @@ func main() { ...@@ -24,7 +24,7 @@ func main() {
port := config.Get("web.port").String() port := config.Get("web.port").String()
//web改成micro 就是grpc,并直接注册到etcd里面 //web改成micro 就是grpc,并直接注册到etcd里面
service := web.NewService( service := web.NewService(
web.Name("go.micro.api.http.bom"), web.Name("go.micro.api.http.search"),
web.Handler(r), web.Handler(r),
web.Address(":"+port), web.Address(":"+port),
) )
......
[web] [web]
port = 9000 port = 9000
mode = debug
[message] [message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto api_domain = http://api.ichunt.com/msg/sendMessageByAuto
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"search_server/service" "search_server/service"
) )
func init() { func Init() {
courseService := service.NewCourseServiceImpl() courseService := service.NewCourseServiceImpl()
gin_.NewBuilder().WithService(courseService). gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()). WithMiddleware(Check_Middleware()).
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"search_server/service" "search_server/service"
) )
func init() { func Init2() {
courseService:=service.NewCourseTopicServiceImpl() courseService:=service.NewCourseTopicServiceImpl()
gin_.NewBuilder().WithService(courseService). gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()). WithMiddleware(Check_Middleware()).
......
...@@ -22,16 +22,18 @@ message AutoSpuResponse{ ...@@ -22,16 +22,18 @@ message AutoSpuResponse{
message RecommendRequest{ message RecommendRequest{
// @inject_tag: form:"goods_name" // @inject_tag: form:"goods_name"
string goods_name = 1; string goods_name = 1;
// @inject_tag: form:"attrs"
string attrs = 2;
// @inject_tag: form:"encap"
string encap = 3;
// @inject_tag: form:"num" // @inject_tag: form:"num"
int32 num = 2; int32 num = 4;
// @inject_tag: form:"delivery_type" // @inject_tag: form:"delivery_type"
int32 delivery_type = 3; int32 delivery_type = 5;
// @inject_tag: form:"flag" // @inject_tag: form:"flag"
int32 flag = 4; int32 flag = 6;
// @inject_tag: form:"p" // @inject_tag: form:"brand_name"
int32 p = 5; string brand_name = 7;
// @inject_tag: form:"offset"
int32 offset = 6;
} }
message ResponseData{ message ResponseData{
......
...@@ -15,8 +15,7 @@ import ( ...@@ -15,8 +15,7 @@ import (
) )
//根据参数去匹配商品 //根据参数去匹配商品
func SearchAttr(attrOrigin string) (goodsName string, err error) { func SearchAttr(attrOrigin, encap string) (goodsName string, err error) {
//attrOrigin有可能是参数也可能是型号名称
//先去切割参数得到参数列表 //先去切割参数得到参数列表
attrs := splitAttrs(attrOrigin) attrs := splitAttrs(attrOrigin)
var attrsSlice []string var attrsSlice []string
...@@ -25,6 +24,17 @@ func SearchAttr(attrOrigin string) (goodsName string, err error) { ...@@ -25,6 +24,17 @@ func SearchAttr(attrOrigin string) (goodsName string, err error) {
attr = TransformESParam(attr) attr = TransformESParam(attr)
attrsSlice = append(attrsSlice, 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) query := getQuery(attrsSlice)
source := elastic.NewSearchSource().Query(query) source := elastic.NewSearchSource().Query(query)
source.Sort("brand_sort", true) source.Sort("brand_sort", true)
......
...@@ -75,22 +75,25 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) { ...@@ -75,22 +75,25 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) {
//推荐商品搜索 //推荐商品搜索
func Recommend(req *bom.RecommendRequest) (rsp *bom.ResponseData) { func Recommend(req *bom.RecommendRequest) (rsp *bom.ResponseData) {
var err error
//先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称 //先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称
goodsNameByAttr, err := SearchAttr(req.GoodsName) var goodsName string
if goodsNameByAttr != "" { if req.GoodsName != "" {
req.GoodsName = goodsNameByAttr 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) req = changeRecommendReq(req)
//获取需要请求的索引 //获取需要请求的索引
index := getRecommendSearchIndex(req) index := getRecommendSearchIndex(req)
//是否是精确匹配
isRawSearch := false
if req.Flag == 3 {
isRawSearch = true
}
//获取es的请求参数 //获取es的请求参数
queryJson := getRecommendSearchParams(isRawSearch, req) queryJson := getRecommendSearchParams(true, req)
result, err := es.CurlES(index, queryJson) result, err := es.CurlES(index, queryJson)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
...@@ -120,12 +123,6 @@ func changeRecommendReq(req *bom.RecommendRequest) (res *bom.RecommendRequest) { ...@@ -120,12 +123,6 @@ func changeRecommendReq(req *bom.RecommendRequest) (res *bom.RecommendRequest) {
if req.Num == 0 { if req.Num == 0 {
req.Num = 1 req.Num = 1
} }
if req.P == 0 {
req.P = 1
}
if !(req.P > 1) {
req.Flag = 3
}
//转换处理商品名称 //转换处理商品名称
replace, _ := regexp.Compile("[^A-Za-z0-9]+") replace, _ := regexp.Compile("[^A-Za-z0-9]+")
req.GoodsName = replace.ReplaceAllString(req.GoodsName, "") req.GoodsName = replace.ReplaceAllString(req.GoodsName, "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment