Commit 3d04f1db by huangchengyi

1.0

parent 849bd436
......@@ -11,6 +11,7 @@ require (
github.com/go-playground/validator/v10 v10.4.0 // indirect
github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9
github.com/gogf/gf v1.14.2
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.3
github.com/gomodule/redigo v2.0.1-0.20180401191855-9352ab68be13+incompatible
......
......@@ -8,6 +8,7 @@ import (
"regexp"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/config"
"search_server/pkg/es"
"search_server/service/query"
"strconv"
......@@ -20,14 +21,21 @@ type AlikeService struct {}
返回供应商详情
*/
func (qs *AlikeService) AlikeSearchInfo(ctx *gin.Context) (results model.LyResponse) {
target := ctx.Request.FormValue("target") //搜索目标: 1 国产 2 所有sku
index := "zhuanmai" //搜索国产替代 索引
if target == "2" { //搜索所有
index = config.Get("es.index_name").String()
}
//索引字典
queryString, err := query.GetDemeQuery(ctx)
queryString, err := query.GetDemeQuery(ctx,target)
if err != nil {
results.ErrorCode = 1001;
results.ErrorMsg = err.Error()
return
}
esResult, err := es.CurlES("zhuanmai", queryString)
esResult, err := es.CurlES(index, queryString)
if err != nil {
results.ErrorCode = 0;
results.ErrorMsg = err.Error()
......
......@@ -10,16 +10,21 @@ import (
/*
获取国产查询es语句
@param string target 搜索目标: 1 国产 2 所有sku
*/
func GetDemeQuery(ctx *gin.Context) (param string, err error){
func GetDemeQuery(ctx *gin.Context,target string) (param string, err error){
query := elastic.NewBoolQuery()
goods_name := ctx.Request.FormValue("alike_goods_en/eq") //国外型号
if target == "1" {
query.Must(elastic.NewTermQuery("supplier_type",1))
}
goods_name := ctx.Request.FormValue("alike_spu_name/eq") //国外型号
if goods_name != "" { //型号搜索
replace, _ := regexp.Compile("[^A-Za-z0-9]+")
goods_name = replace.ReplaceAllString(goods_name, "")
goods_name = strings.ToUpper(goods_name)
query.Must(elastic.NewTermQuery("alike_goods_en.raw",goods_name))
query.Must(elastic.NewTermQuery("alike_spu_name.raw",goods_name))
}
alike_spu_id := ctx.Request.FormValue("alike_spu_id/eq") //国外型号spu_id
if alike_spu_id != "" {
......
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