Commit 8b77667a by hcy001

BOM4

parent 9793c198
......@@ -9,10 +9,24 @@ import (
"github.com/shopspring/decimal"
"github.com/syyongx/php2go"
"reflect"
"regexp"
"strconv"
"strings"
)
/*
提取字符串的字母数字并去掉空格
@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, ""))
}
/*
定时任务打印输出
@parm jsonStr 需要json输出的内容
*/
......
......@@ -7,7 +7,6 @@ import (
"context"
"encoding/json"
es "gopkg.in/olivere/elastic.v5"
"regexp"
"strings"
)
......@@ -112,11 +111,8 @@ func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool,is
//构建term条件
func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (query *es.BoolQuery) {
query = es.NewBoolQuery()
goodsName := common.DrawLetterNum(bomItem.GoodsName)
if flag {
field := "auto_goods_name.raw"
replace, _ := regexp.Compile("[^A-Za-z0-9]+")
goodsName := replace.ReplaceAllString(bomItem.GoodsName, "")
goodsName = strings.ToUpper(goodsName)
//用于判断下面的miniShould,因为下面的参数里面,如果出现阻值的,用的是should语句
//为了保证所有参数都必须参与搜索,所以要用miniShould去做限制
//var shouldNumber int
......@@ -150,7 +146,10 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
query = query.Must(es.NewTermsQuery("attr_bom", "$_$"))
}
}
query = query.Filter(es.NewTermQuery(field, goodsName))
if goodsName != "" {
query = query.Filter(es.NewTermQuery("auto_goods_name.raw", goodsName))
}
//判断是否存在brandName并且匹配不到对应的标准品牌
if bomItem.BrandName != "" {
......@@ -163,10 +162,10 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
}
//搜索库存
query = query.Should(es.NewRangeQuery("stock").Gte(bomItem.Number * bomItem.Amount))
} else if isAlike{ //todo 推荐型号搜索
query = query.Must(es.NewTermsQuery("alike_spu_name.raw", bomItem.GoodsName))
} else {
query = query.Must(es.NewTermQuery("auto_goods_name", bomItem.GoodsName))
} else if isAlike && goodsName != "" { //todo 推荐型号搜索
query = query.Must(es.NewTermsQuery("alike_spu_name.raw", goodsName))
} else if goodsName != "" {
query = query.Must(es.NewTermQuery("auto_goods_name", goodsName))
}
common.PrintDebug("isalike:",isAlike)
......
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