Commit e9e8acda by huangchengyi

1.0

parent abfb4adc
...@@ -2,11 +2,9 @@ package controller ...@@ -2,11 +2,9 @@ package controller
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"regexp"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/requests" "search_server/requests"
"search_server/service" "search_server/service"
"strings"
) )
//查询联营型号是否有库存 //查询联营型号是否有库存
...@@ -25,9 +23,7 @@ func CheckHasStock(ctx *gin.Context) { ...@@ -25,9 +23,7 @@ func CheckHasStock(ctx *gin.Context) {
common.Output(ctx,1001, "型号不存在", nil) common.Output(ctx,1001, "型号不存在", nil)
return return
} }
replace, _ := regexp.Compile("[^A-Za-z0-9]+") goodsName = common.DrawLetterNum(goodsName)
goodsName = replace.ReplaceAllString(goodsName, "")
goodsName = strings.ToUpper(goodsName)
otherService := service.OtherService{} otherService := service.OtherService{}
hasStock, err := otherService.CheckHasStock(goodsName) hasStock, err := otherService.CheckHasStock(goodsName)
if err != nil { if err != nil {
......
...@@ -26,6 +26,19 @@ import ( ...@@ -26,6 +26,19 @@ import (
) )
/* /*
提取字符串的字母数字并去掉空格
@param string target_str 目标字符串
@return 返回格式化后字符串
*/
func DrawLetterNum(target_str string) (str string) {
if target_str == "" {
return ""
}
replace, _ := regexp.Compile("[^A-Za-z0-9]+")
return strings.ToUpper(replace.ReplaceAllString(target_str, ""))
}
/*
gjson 判断某值是否存在 map gjson 判断某值是否存在 map
@param json string 分析json字符串 @param json string 分析json字符串
@param arrk string 分析的json键值转成map @param arrk string 分析的json键值转成map
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"github.com/iancoleman/orderedmap" "github.com/iancoleman/orderedmap"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model" "search_server/model"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
...@@ -113,9 +112,7 @@ func (qs *AlikeService) ThinkGoods(ctx *gin.Context) (results model.LyResponse) ...@@ -113,9 +112,7 @@ func (qs *AlikeService) ThinkGoods(ctx *gin.Context) (results model.LyResponse)
return return
} }
//字符过滤 //字符过滤
replace, _ := regexp.Compile("[^A-Za-z0-9]+") goodsName = common.DrawLetterNum(goodsName)
goodsName = replace.ReplaceAllString(goodsName, "")
goodsName = strings.ToUpper(goodsName)
//查询es //查询es
query := elastic.NewBoolQuery() query := elastic.NewBoolQuery()
query.Filter(elastic.NewTermQuery("auto_goods_name", goodsName)) query.Filter(elastic.NewTermQuery("auto_goods_name", goodsName))
......
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"github.com/prometheus/common/log" "github.com/prometheus/common/log"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/es" "search_server/pkg/es"
...@@ -31,9 +30,7 @@ func NewBomServiceImpl() *BomServiceImpl { ...@@ -31,9 +30,7 @@ func NewBomServiceImpl() *BomServiceImpl {
//构建请求参数 //构建请求参数
func AutoSpu(goodsName string) []string { func AutoSpu(goodsName string) []string {
replace, _ := regexp.Compile("[^A-Za-z0-9]+") goodsName = common.DrawLetterNum(goodsName)
goodsName = replace.ReplaceAllString(goodsName, "")
goodsName = strings.ToUpper(goodsName)
query := getTermQuery(goodsName) query := getTermQuery(goodsName)
source := elastic.NewSearchSource().Query(query) source := elastic.NewSearchSource().Query(query)
...@@ -115,10 +112,7 @@ func changeRecommendReq(req *common.RecommendRequest) (res *common.RecommendRequ ...@@ -115,10 +112,7 @@ func changeRecommendReq(req *common.RecommendRequest) (res *common.RecommendRequ
req.Num = 1 req.Num = 1
} }
//转换处理商品名称 //转换处理商品名称
replace, _ := regexp.Compile("[^A-Za-z0-9]+") req.GoodsName = common.DrawLetterNum(req.GoodsName)
req.GoodsName = replace.ReplaceAllString(req.GoodsName, "")
req.GoodsName = strings.ToUpper(req.GoodsName)
if req.Flag == 2 { if req.Flag == 2 {
//截取字符后再精确匹配 //截取字符后再精确匹配
req.GoodsName = common.SubKeyWordStr(req.GoodsName) req.GoodsName = common.SubKeyWordStr(req.GoodsName)
...@@ -147,9 +141,8 @@ func getBomTermQuery(goodsName, brandName string, number int, isRawSearch bool) ...@@ -147,9 +141,8 @@ func getBomTermQuery(goodsName, brandName string, number int, isRawSearch bool)
query := elastic.NewBoolQuery() query := elastic.NewBoolQuery()
if isRawSearch { if isRawSearch {
field := "auto_goods_name.raw" field := "auto_goods_name.raw"
replace, _ := regexp.Compile("[^A-Za-z0-9]+")
goodsName := replace.ReplaceAllString(goodsName, "") goodsName = common.DrawLetterNum(goodsName)
goodsName = strings.ToUpper(goodsName)
//搜索商品名称 //搜索商品名称
query = query.Filter(elastic.NewTermQuery(field, goodsName)) query = query.Filter(elastic.NewTermQuery(field, goodsName))
//判断是否存在brandName,存在就去搜索brandName //判断是否存在brandName,存在就去搜索brandName
......
...@@ -4,8 +4,8 @@ import ( ...@@ -4,8 +4,8 @@ import (
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/uniplaces/carbon" "github.com/uniplaces/carbon"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/model" "search_server/model"
"search_server/pkg/common"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"strings" "strings"
) )
...@@ -16,9 +16,7 @@ type GetDataService struct { ...@@ -16,9 +16,7 @@ type GetDataService struct {
func (gs *GetDataService) GetQuery(originKeyword, supplierName, brandId, goodsNameEq string, stock int) (string, error) { func (gs *GetDataService) GetQuery(originKeyword, supplierName, brandId, goodsNameEq string, stock int) (string, error) {
query := elastic.NewBoolQuery() query := elastic.NewBoolQuery()
rex, _ := regexp.Compile(`/[^A-Za-z0-9]+/`) keyword := common.DrawLetterNum(originKeyword)
keyword := rex.ReplaceAllString(originKeyword, "")
keyword = strings.ToUpper(keyword)
//只显示更新时间在一个月内的数据 //只显示更新时间在一个月内的数据
oneMonthTimeStamp := carbon.Now().SubMonth().Timestamp() oneMonthTimeStamp := carbon.Now().SubMonth().Timestamp()
query.Must(elastic.NewRangeQuery("update_time").Gte(oneMonthTimeStamp)) query.Must(elastic.NewRangeQuery("update_time").Gte(oneMonthTimeStamp))
......
...@@ -3,9 +3,7 @@ package query ...@@ -3,9 +3,7 @@ package query
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/pkg/common" "search_server/pkg/common"
"strings"
) )
/* /*
...@@ -19,11 +17,8 @@ func GetDemeQuery(ctx *gin.Context,target string) (param string, err error){ ...@@ -19,11 +17,8 @@ func GetDemeQuery(ctx *gin.Context,target string) (param string, err error){
query.Must(elastic.NewTermQuery("supplier_type",1)) query.Must(elastic.NewTermQuery("supplier_type",1))
} }
goods_name := ctx.Request.FormValue("alike_spu_name/eq") //国外型号 goods_name := common.DrawLetterNum(ctx.Request.FormValue("alike_spu_name/eq")) //国外型号
if goods_name != "" { //型号搜索 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_spu_name.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 alike_spu_id := ctx.Request.FormValue("alike_spu_id/eq") //国外型号spu_id
......
...@@ -4,11 +4,9 @@ import ( ...@@ -4,11 +4,9 @@ import (
"errors" "errors"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"gopkg.in/olivere/elastic.v5" "gopkg.in/olivere/elastic.v5"
"regexp"
"search_server/pkg/common" "search_server/pkg/common"
"search_server/pkg/config" "search_server/pkg/config"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"strings"
) )
/* /*
...@@ -33,11 +31,8 @@ func GetOptimumAttrQuery(ctx *gin.Context,REQUEST_ATTR *map[string][]string,type ...@@ -33,11 +31,8 @@ func GetOptimumAttrQuery(ctx *gin.Context,REQUEST_ATTR *map[string][]string,type
if ctx.Request.FormValue("avail_rank") == "1" { //只显示有货 if ctx.Request.FormValue("avail_rank") == "1" { //只显示有货
query.Must(elastic.NewRangeQuery("stock").Gt(0)) query.Must(elastic.NewRangeQuery("stock").Gt(0))
} }
goods_name := ctx.Request.FormValue("goods_name/condition") goods_name := common.DrawLetterNum(ctx.Request.FormValue("goods_name/condition"))
if goods_name != "" { //型号搜索 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("goods_name",goods_name)) query.Must(elastic.NewTermQuery("goods_name",goods_name))
} }
......
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