Commit 232bb276 by mushishixian

优化

parent eed93a88
......@@ -75,7 +75,7 @@ func GetStandardAttrs(bomItems []model.BomItem) []model.BomItem {
if !strings.Contains(attr, "€") {
attr = strings.ToUpper(attr)
attrName, _ := redis.String(gredis.HGet("sku_map2", attr))
if attrName!="" {
if attrName != "" {
attrsSlice[key] = attrName + "€" + attr
}
}
......
......@@ -113,10 +113,14 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
replace, _ := regexp.Compile("[^A-Za-z0-9]+")
goodsName := replace.ReplaceAllString(bomItem.GoodsName, "")
goodsName = strings.ToUpper(goodsName)
//用于判断下面的miniShould,因为下面的参数里面,如果出现阻值的,用的是should语句
//为了保证所有参数都必须参与搜索,所以要用miniShould去做限制
//var shouldNumber int
//商品名称太短的或者没有商品名称的,去搜索参数
if len(goodsName) <= 3 {
if len(bomItem.AttrList) > 0 {
//var params []interface{}
q := es.NewBoolQuery()
q.MinimumNumberShouldMatch(1)
for _, attr := range bomItem.AttrList {
if !strings.Contains(attr, "€") {
continue
......@@ -127,11 +131,13 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
}
//需要注意的点 : 因为0.158Ω可以对应 电阻 或者 直流电阻 ,所以当识别出来是电阻 或者 直流电阻 的时候,就不能用must,要用should
if strings.Contains(attr, "ZLNZ€") || strings.Contains(attr, "OM€") {
query.Should(es.NewTermQuery("attr_bom", attr))
//query.Should(es.NewTermQuery("attr_bom", attr))
q.Should(es.NewTermQuery("attr_bom", attr))
} else {
query.Must(es.NewTermQuery("attr_bom", attr))
}
}
query.Must(q)
} else {
query = query.Must(es.NewTermsQuery("attr_bom", "$_$"))
}
......@@ -141,7 +147,7 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
//判断是否存在brandName并且匹配不到对应的标准品牌
if bomItem.BrandName != "" {
bomItem.BrandName = strings.ToUpper(bomItem.BrandName)
query = query.Should(es.NewConstantScoreQuery(es.NewTermQuery("brand_name", bomItem.BrandName)).Boost(2))
query = query.Should(es.NewTermQuery("brand_name", bomItem.BrandName))
}
//判断封装是否有,有的话,直接去搜索封装
if bomItem.Encap != "" {
......@@ -149,7 +155,7 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
}
//搜索库存
//fmt.Println("总数量:", bomItem.Number, bomItem.Amount)
query = query.Should(es.NewConstantScoreQuery(es.NewRangeQuery("stock").Gte(bomItem.Number * bomItem.Amount)))
query = query.Should(es.NewRangeQuery("stock").Gte(bomItem.Number * bomItem.Amount))
} else {
query = query.Must(es.NewTermQuery("auto_goods_name", bomItem.GoodsName))
}
......
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