Commit 65243ed5 by mushishixian

Merge branch 'dev'

parents 87b49891 3e5b2333
...@@ -22,6 +22,12 @@ type BomResponse struct { ...@@ -22,6 +22,12 @@ type BomResponse struct {
Data interface{} `json:"data"` Data interface{} `json:"data"`
} }
type RecommendResponse struct {
Flag int `json:"flag"`
Total int `json:"total"`
Data interface{} `json:"data"`
}
func SuccessResponse(errCode int, errMsg string, data interface{}) Response { func SuccessResponse(errCode int, errMsg string, data interface{}) Response {
return Response{ return Response{
ErrCode: errCode, ErrCode: errCode,
......
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp" "regexp"
"search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/es" "search_server/pkg/es"
...@@ -66,7 +65,7 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) { ...@@ -66,7 +65,7 @@ func getTermQuery(goodsName string) (query *elastic.BoolQuery) {
} }
//推荐商品搜索 //推荐商品搜索
func Recommend(ctx *gin.Context,req *common.RecommendRequest) (goodsList []model.ApiGoods) { func Recommend(ctx *gin.Context, req *common.RecommendRequest) (rsp common.RecommendResponse) {
var err error var err error
//先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称 //先去请求参数,看是否是参数,如果是参数的话,需要修改请求的商品名称
var goodsName string var goodsName string
...@@ -92,7 +91,7 @@ func Recommend(ctx *gin.Context,req *common.RecommendRequest) (goodsList []model ...@@ -92,7 +91,7 @@ func Recommend(ctx *gin.Context,req *common.RecommendRequest) (goodsList []model
} }
//获取需要的数据 //获取需要的数据
total := gjson.Get(result, "hits.total").Int() total := gjson.Get(result, "hits.total").Int()
var response common.BomResponse var response common.RecommendResponse
response.Total = int(total) response.Total = int(total)
//获取goods_id列表去商品服务获取商品 //获取goods_id列表去商品服务获取商品
list := gjson.Get(result, "hits.hits.#._source").Array() list := gjson.Get(result, "hits.hits.#._source").Array()
...@@ -103,8 +102,10 @@ func Recommend(ctx *gin.Context,req *common.RecommendRequest) (goodsList []model ...@@ -103,8 +102,10 @@ func Recommend(ctx *gin.Context,req *common.RecommendRequest) (goodsList []model
goodsIdList = append(goodsIdList, goodsId) goodsIdList = append(goodsIdList, goodsId)
} }
goodsIdListStr = strings.Join(goodsIdList, ",") goodsIdListStr = strings.Join(goodsIdList, ",")
goodsList, err = GetGoodsInfoByApi(ctx,goodsIdListStr) goodsList, err := GetGoodsInfoByApi(ctx, goodsIdListStr)
return goodsList response.Data = goodsList
response.Flag = req.Flag
return response
} }
//处理recommend接口的请求参数 //处理recommend接口的请求参数
......
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