Commit ed0c545a by mushishixian

品牌映射

parent 2b9184b3
......@@ -22,7 +22,7 @@ func init() {
// "amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
//}
//
//str := `{"bom_id":599,"delivery_type":1,"sort":1}`
//str := `{"bom_id":616,"delivery_type":1,"sort":1}`
//rabbitmq.Send(queueExchange, str)
}
......
......@@ -109,7 +109,7 @@ func searchAttr(bomItem model.BomItem, search *es.MultiSearchService) (result *e
}
}
query := getQuery(attrsSlice)
//如果ZyBrandId不为空,则代表匹配到了映射id,可以直接用must去查询
//如果ZyBrandId不为空,则代表匹配到了映射id
if bomItem.ZyBrandId != "" && len(attrsSlice) > 0 {
query.Should(es.NewTermQuery("brand_name", bomItem.ZyBrandName))
} else {
......@@ -185,6 +185,9 @@ func extractAttrsByStr(attr string) []string {
func changeKeyword(attr string) (result string) {
regulars := mapping.KeywordRegular
for regexpStr, regular := range regulars {
if strings.Contains(attr, "Ω") {
break
}
compile, _ := regexp.Compile(regexpStr)
attr = compile.ReplaceAllString(attr, regular)
}
......
......@@ -85,6 +85,8 @@ func UpdateBomItem(bomId, bomItemId int) (err error) {
return err
}
defer client.Stop()
//先去查询品牌映射,有映射关系的,就用映射关系得到的brand_id进行查询
bomItems, err = GetBrandMap(bomItems)
//匹配之前,去遍历bom_item,把没有型号名称但是有参数的bom_item进行型号补充
bomItems, err = MatchGoodsNameByAttrs(bomItems)
//直接模糊匹配
......
......@@ -69,14 +69,14 @@ func getBrandMapQuery(bomItem model.BomItem) (query *es.BoolQuery) {
brandName = strings.ToUpper(brandName)
//提取出纯中文
r, _ := regexp.Compile("[\u4e00-\u9fa5]+")
chineseBrandName := r.FindString(brandName)
if chineseBrandName != "" {
query.Should(es.NewMatchQuery("brand_name_cn", chineseBrandName))
brandNameCn := r.FindString(brandName)
if brandNameCn != "" {
query.Should(es.NewMatchQuery("brand_name_cn", brandNameCn))
}
//提取出纯英文
re, _ := regexp.Compile("[A-Za-z0-9]+")
englishBrandName := re.FindString(brandName)
subQuery = es.NewTermQuery("attrs.attr_brand_name", englishBrandName)
brandNameEn := re.FindString(brandName)
subQuery = es.NewTermQuery("attrs.attr_brand_name", brandNameEn)
nestedQuery = es.NewNestedQuery("attrs", subQuery)
query.Should(nestedQuery)
query.MinimumNumberShouldMatch(1)
......
......@@ -4,7 +4,6 @@ import (
"bom_server/configs"
"bom_server/internal/model"
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"strings"
......@@ -30,7 +29,6 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
goodsIds = append(goodsIds, goodsMap.GoodsId)
}
goodsIdsStr := strings.Join(goodsIds, ",")
fmt.Println(goodsIdsStr)
goodsList, err := GetGoodsInfo(goodsIdsStr)
if len(goodsMapList) != 0 {
bomId = goodsMapList[0].BomId
......
......@@ -7,7 +7,6 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"regexp"
"strings"
......@@ -19,7 +18,7 @@ import (
/**
1.先去数据库查出所有需要匹配的数据
2.然后开协程去针对每个bom里的goods_name去请求搜索接口
2.然后开协程去针对每个bom里的goods_name去请求搜索接口(匹配品牌映射,匹配参数)
3.搜索匹配到以后,用goods_id去请求商品服务
4.得到具体的商品数据以后,针对对应的商品进行修改
**/
......@@ -241,7 +240,7 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
bom.GoodsName = bom.Attrs
}
//构建一个goods_name对应的bomItems列表
searchRequest := getSearchParams(bom, sort, rawSearch)
searchRequest := getSearchParams(index, bom, sort, rawSearch)
searchFlag = true
search.Add(searchRequest)
}
......@@ -286,8 +285,8 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
}
//构建请求参数
func getSearchParams(bomItem model.BomItem, sort int, flag bool) (searchRequest *es.SearchRequest) {
query := getTermQuery(bomItem, sort, flag)
func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool) (searchRequest *es.SearchRequest) {
query := getTermQuery(index, bomItem, sort, flag)
source := es.NewSearchSource().Query(query)
if sort == 1 {
source.Sort("_score", false)
......@@ -306,12 +305,12 @@ func getSearchParams(bomItem model.BomItem, sort int, flag bool) (searchRequest
}
source = source.From(0).Size(1)
searchRequest = es.NewSearchRequest().Source(source)
fmt.Println(searchRequest.Body())
//fmt.Println(searchRequest.Body())
return searchRequest
}
//构建term条件
func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQuery) {
func getTermQuery(index string, bomItem model.BomItem, sort int, flag bool) (query *es.BoolQuery) {
query = es.NewBoolQuery()
if flag {
field := "auto_goods_name.raw"
......@@ -332,8 +331,11 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool) (query *es.BoolQue
query = query.Must(es.NewTermQuery(field, bomItem.GoodsName))
}
//对品牌进行判断搜索,如果能匹配到对应的自营标准品牌(那么同时也有对应的联营品牌)
if bomItem.ZyBrandId != "" {
//还要去判断当前索引是否包含自营,不包含,直接跳过自营的brand_id
if strings.Contains(index, "liexin_ziying") {
query.Should(es.NewTermQuery("brand_id", bomItem.ZyBrandId))
}
if bomItem.ZyBrandId != "" {
for _, id := range bomItem.LyBrandIds {
query.Should(es.NewTermQuery("brand_id", 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