Commit 849bd436 by huangchengyi

1.0

parent a1078193
......@@ -20,3 +20,18 @@ func AlikeSearch(ctx *gin.Context) {
common.Output(ctx,apiData.ErrorCode, apiData.ErrorMsg, apiData.Data)
common.PrintDebugHtml(ctx,"-----执行结束----") //debug
}
/*
联想词搜索
@param source 来源:1国产 2普通
@param goods_name_en 国外类似型号名称
*/
func ThinkSearch(ctx *gin.Context) {
common.PrintDebugHeader(ctx) //debug
service := service.AlikeService{}
apiData := service.ThinkGoods(ctx)
common.Output(ctx,apiData.ErrorCode, apiData.ErrorMsg, apiData.Data)
common.PrintDebugHtml(ctx,"-----执行结束----") //debug
}
......@@ -24,6 +24,8 @@ func InitRouter() *gin.Engine {
{
v2.POST("alike", controller.AlikeSearch)
v2.GET("alike", controller.AlikeSearch)
v2.GET("think", controller.ThinkSearch)
v2.POST("think", controller.ThinkSearch)
}
//商品分类
v3 := r.Group("/optimum/")
......
......@@ -4,6 +4,8 @@ import (
"github.com/gin-gonic/gin"
"github.com/iancoleman/orderedmap"
"github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model"
"search_server/pkg/common"
"search_server/pkg/es"
......@@ -89,3 +91,47 @@ func (qs *AlikeService) AlikeSearchInfo(ctx *gin.Context) (results model.LyRespo
results.Data = A;
return
}
/*
联想词
*/
func (qs *AlikeService) ThinkGoods(ctx *gin.Context) (results model.LyResponse) {
goodsName := ctx.Request.FormValue("k");
if goodsName == "" {
results.ErrorCode = 0;
results.ErrorMsg = ""
return
}
//字符过滤
replace, _ := regexp.Compile("[^A-Za-z0-9]+")
goodsName = replace.ReplaceAllString(goodsName, "")
goodsName = strings.ToUpper(goodsName)
//查询es
query := elastic.NewBoolQuery()
query.Filter(elastic.NewTermQuery("auto_goods_name", goodsName))
source := elastic.NewSearchSource().Query(query)
source = source.From(0).Size(10)
searchRequestStr, _ := elastic.NewSearchRequest().Source(source).Body()
common.PrintDebugHtml(ctx,searchRequestStr)
result, err := es.CurlES("digikey", searchRequestStr)
if err != nil {
results.ErrorCode = 0;
results.ErrorMsg = err.Error()
return
}
goodsNameList := make([]string, 0)
goodsList := gjson.Get(result, "hits.hits.#._source").Array()
for _, goods := range goodsList {
goodsName := gjson.Get(goods.String(), "auto_goods_name").String()
goodsNameList = append(goodsNameList, goodsName)
}
results.ErrorCode = 0;
results.ErrorMsg = "查询成功"
results.Data = goodsNameList
return
}
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