Commit 4ecfdd6a by mushishixian

优化参数查询

parent faa39dc5
......@@ -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),
)
......
[web]
port = 9000
mode = debug
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
......
......@@ -7,7 +7,7 @@ import (
"search_server/service"
)
func init() {
func Init() {
courseService := service.NewCourseServiceImpl()
gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()).
......
......@@ -7,7 +7,7 @@ import (
"search_server/service"
)
func init() {
func Init2() {
courseService:=service.NewCourseTopicServiceImpl()
gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()).
......
......@@ -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{
......
......@@ -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)
......
......@@ -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, "")
......
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