Commit 47163d07 by 孙龙
parents 7e638973 fbd773ab
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
func main() { func main() {
var path string var path string
flag.StringVar(&path, "config", "../conf/config.ini", "配置文件") flag.StringVar(&path, "config", "conf/config.ini", "配置文件")
flag.Parse() flag.Parse()
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
panic(err) panic(err)
......
[web] [web]
port = 9000 port = 20001
mode = release mode = release
cors_domain = bom.ichunt.com cors_domain = bom.ichunt.com
...@@ -12,7 +12,7 @@ api_url = http://47.106.60.211:60004 ...@@ -12,7 +12,7 @@ api_url = http://47.106.60.211:60004
[es] [es]
url = http://172.18.137.29:9211 url = http://172.18.137.29:9211
urls = http://172.18.137.29:9211,172.18.137.30:9211 urls = http://172.18.137.29:9211,http://172.18.137.30:9211
index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
search_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin,zhuanmai search_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin,zhuanmai
hk_delivery_type_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin hk_delivery_type_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin
......
...@@ -26,7 +26,7 @@ func Cors_Middleware() gin_.Middleware { ...@@ -26,7 +26,7 @@ func Cors_Middleware() gin_.Middleware {
for _, domain := range corsDomains { for _, domain := range corsDomains {
c.Header("Access-Control-Allow-Origin", domain) c.Header("Access-Control-Allow-Origin", domain)
} }
c.Header("Access-Control-Allow-Origin", "http://bom.liexin.com") c.Header("Access-Control-Allow-Origin", "https://bom.ichunt.com")
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token") c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS") c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type") c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
......
##bom_service 实现了bom的搜索
...@@ -16,7 +16,9 @@ require ( ...@@ -16,7 +16,9 @@ require (
github.com/ichunt2019/logger v1.0.5 github.com/ichunt2019/logger v1.0.5
github.com/imroc/req v0.3.0 github.com/imroc/req v0.3.0
github.com/jinzhu/gorm v1.9.12 github.com/jinzhu/gorm v1.9.12
github.com/micro/go-micro/v2 v2.5.0 github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1 // indirect
github.com/mholt/certmagic v0.9.3 // indirect
github.com/micro/go-micro/v2 v2.9.0
github.com/prometheus/client_golang v1.5.1 // indirect github.com/prometheus/client_golang v1.5.1 // indirect
github.com/prometheus/common v0.10.0 github.com/prometheus/common v0.10.0
github.com/prometheus/procfs v0.0.11 // indirect github.com/prometheus/procfs v0.0.11 // indirect
...@@ -33,6 +35,7 @@ require ( ...@@ -33,6 +35,7 @@ require (
gopkg.in/ini.v1 v1.51.0 // indirect gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85 gopkg.in/olivere/elastic.v5 v5.0.85
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect
) )
......
...@@ -68,48 +68,82 @@ message LadderPrice { ...@@ -68,48 +68,82 @@ message LadderPrice {
} }
message GoodsModel { message GoodsModel {
// @inject_tag: json:"other_attrs"
OtherAttrs other_attrs = 1; OtherAttrs other_attrs = 1;
// @inject_tag: json:"pick_type"
int64 pick_type = 2; int64 pick_type = 2;
// @inject_tag: json:"barcode"
string barcode = 3; string barcode = 3;
// @inject_tag: json:"goods_id"
string goods_id = 4; string goods_id = 4;
// @inject_tag: json:"goods_type
int64 goods_type = 5; int64 goods_type = 5;
// @inject_tag: json:"supplier_id"
int64 supplier_id = 6; int64 supplier_id = 6;
// @inject_tag: json:"brand_id"
int64 brand_id = 7; int64 brand_id = 7;
// @inject_tag: json:"class_id1"
int64 class_id1 = 8; int64 class_id1 = 8;
// @inject_tag: json:"class_id2"
int64 class_id2 = 9; int64 class_id2 = 9;
// @inject_tag: json:"goods_name"
string goods_name = 10; string goods_name = 10;
// @inject_tag: json:"status"
int64 status = 11; int64 status = 11;
// @inject_tag: json:"encoded"
string encoded = 12; string encoded = 12;
// @inject_tag: json:"encap"
string encap = 13; string encap = 13;
// @inject_tag: json:"packing"
int64 packing = 14; int64 packing = 14;
// @inject_tag: json:"goods_unit"
int64 goods_unit = 15; int64 goods_unit = 15;
// @inject_tag: json:"goods_images"
bool goods_images = 16; bool goods_images = 16;
// @inject_tag: json:"pdf"
string pdf = 17; string pdf = 17;
// @inject_tag: json:"goods_brief"
string goods_brief = 18; string goods_brief = 18;
// @inject_tag: json:"moq"
int64 moq = 19; int64 moq = 19;
// @inject_tag: json:"mpq"
int64 mpq = 20; int64 mpq = 20;
// @inject_tag: json:"ladder_price" // @inject_tag: json:"ladder_price"
repeated LadderPrice ladder_price = 21; repeated LadderPrice ladder_price = 21;
// @inject_tag: json:"update_time"
int64 update_time = 22; int64 update_time = 22;
// @inject_tag: json:"sku_name"
string sku_name = 23; string sku_name = 23;
// @inject_tag: json:"mpl"
int64 mpl = 24; int64 mpl = 24;
// @inject_tag: json:"stock"
int64 stock = 25; int64 stock = 25;
// @inject_tag: json:"attrs"
string attrs = 26; string attrs = 26;
// @inject_tag: json:"cost"
string cost = 27; string cost = 27;
// @inject_tag: json:"new_cost"
string new_cost = 28; string new_cost = 28;
// @inject_tag: json:"supplier_stock"
int64 supplier_stock = 29; int64 supplier_stock = 29;
// @inject_tag: json:"self_supplier_type"
int64 self_supplier_type = 30; int64 self_supplier_type = 30;
// @inject_tag: json:"cn_delivery_time" // @inject_tag: json:"cn_delivery_time"
string cn_delivery_time = 31; string cn_delivery_time = 31;
// @inject_tag: json:"brand_name"
string brand_name = 32; string brand_name = 32;
// @inject_tag: json:"supplier_name"
string supplier_name = 33; string supplier_name = 33;
string goods_unit_name = 34; string goods_unit_name = 34;
string packing_name = 35; string packing_name = 35;
string mpq_unit_name = 36; string mpq_unit_name = 36;
// @inject_tag: json:"ac_type"
int64 ac_type = 37; int64 ac_type = 37;
int64 allow_coupon = 38; int64 allow_coupon = 38;
string class_id1_name = 39; string class_id1_name = 39;
string class_id2_name = 40; string class_id2_name = 40;
// @inject_tag: json:"otheis_buyr_attrs"
int64 is_buy = 41; int64 is_buy = 41;
// @inject_tag: json:"hk_delivery_type"
string hk_delivery_type = 42; string hk_delivery_type = 42;
} }
\ No newline at end of file
...@@ -18,6 +18,23 @@ import ( ...@@ -18,6 +18,23 @@ import (
func SearchAttr(attrOrigin, encap string) (goodsName string, err error) { func SearchAttr(attrOrigin, encap string) (goodsName string, err error) {
//先去切割参数得到参数列表 //先去切割参数得到参数列表
attrs := splitAttrs(attrOrigin) attrs := splitAttrs(attrOrigin)
//当切割出来的参数大于1个的时候,就要去针对每个参数进行里面再一次提纯
if len(attrs) > 1 {
for key, attr := range attrs {
attrs[key] = changeKeyword(attr)
//切割完以后,还要去对切割后的参数提取值,因为有可能参数没有分隔符
extractRes := extractAttr(attrs[key])
for ek, eAttr := range extractRes {
if ek == 0 {
attrs[key] = extractRes[0]
} else {
attrs = append(attrs, eAttr)
}
}
}
} else {
attrs = extractAttrsByStr(attrs[0])
}
var attrsSlice []string var attrsSlice []string
//去转换每一个参数,得到去查询es的标准格式 //去转换每一个参数,得到去查询es的标准格式
for _, attr := range attrs { for _, attr := range attrs {
...@@ -44,6 +61,10 @@ func SearchAttr(attrOrigin, encap string) (goodsName string, err error) { ...@@ -44,6 +61,10 @@ func SearchAttr(attrOrigin, encap string) (goodsName string, err error) {
index := config.Get("es.attr_index").String() index := config.Get("es.attr_index").String()
result, err := es.CurlES(index, body) result, err := es.CurlES(index, body)
goodsName = gjson.Get(result, "hits.hits.0._source.goods_name").String() goodsName = gjson.Get(result, "hits.hits.0._source.goods_name").String()
//匹配参数不成功,要变回原来的值
if goodsName == "" {
goodsName = attrOrigin
}
return return
} }
...@@ -72,6 +93,33 @@ func splitAttrs(attrs string) (result []string) { ...@@ -72,6 +93,33 @@ func splitAttrs(attrs string) (result []string) {
return return
} }
//提取参数
func extractAttr(attr string) []string {
regexpUnit := strings.Join(getNeedCheckUnit(), "|")
r, _ := regexp.Compile("(\\d+[\\/\\d. ]*|\\d)(" + regexpUnit + ")" + "")
res := r.FindAllString(attr, 100)
return res
}
//提取参数,从一个字符串里面,注意要提取出两个参数才当作是
func extractAttrsByStr(attr string) []string {
regexpUnit := strings.Join(getNeedCheckUnit(), "|")
r, _ := regexp.Compile("(\\d+[\\/\\d. ]*|\\d)(" + regexpUnit + ")" + "")
res := r.FindAllString(attr, 100)
if len(res) < 2 {
return []string{attr}
}
return res
}
func getNeedCheckUnit() (unitSlice []string) {
unitMapping := common.UnitValueMapping
for unit, _ := range unitMapping {
unitSlice = append(unitSlice, unit)
}
return
}
//将写法转成正规写法,转换单位,比如有的人喜欢将Ω输成欧姆或者O,所以要统一转成正常的Ω //将写法转成正规写法,转换单位,比如有的人喜欢将Ω输成欧姆或者O,所以要统一转成正常的Ω
func changeKeyword(attr string) (result string) { func changeKeyword(attr string) (result string) {
regulars := common.KeywordRegular regulars := common.KeywordRegular
......
...@@ -25,7 +25,7 @@ func (bs *BomServiceImpl) AutoSpu(ctx context.Context, req *bom.AutoSpuRequest, ...@@ -25,7 +25,7 @@ func (bs *BomServiceImpl) AutoSpu(ctx context.Context, req *bom.AutoSpuRequest,
} }
func (bs *BomServiceImpl) Recommend(ctx context.Context, req *bom.RecommendRequest, rsp *bom.RecommendResponse) error { func (bs *BomServiceImpl) Recommend(ctx context.Context, req *bom.RecommendRequest, rsp *bom.RecommendResponse) error {
if req.GoodsName == "" || req.Flag == 0 { if req.Flag == 0 {
rsp.ErrorCode = 101 rsp.ErrorCode = 101
rsp.ErrorMessage = "参数不全" rsp.ErrorMessage = "参数不全"
return nil return nil
...@@ -66,7 +66,9 @@ func AutoSpu(goodsName string) []string { ...@@ -66,7 +66,9 @@ func AutoSpu(goodsName string) []string {
func getTermQuery(goodsName string) (query *elastic.BoolQuery) { func getTermQuery(goodsName string) (query *elastic.BoolQuery) {
query = elastic.NewBoolQuery() query = elastic.NewBoolQuery()
query.Filter(elastic.NewTermQuery("auto_goods_name", goodsName)) query.Filter(elastic.NewTermQuery("auto_goods_name", goodsName))
query.Filter(elastic.NewTermQuery("status", 1)) if config.Get("web.mode").String() != "debug" {
query.Filter(elastic.NewTermQuery("status", 1))
}
query.MustNot(elastic.NewTermQuery("brand_id", 0)) query.MustNot(elastic.NewTermQuery("brand_id", 0))
return query return query
} }
...@@ -91,7 +93,7 @@ func Recommend(req *bom.RecommendRequest) (rsp *bom.ResponseData) { ...@@ -91,7 +93,7 @@ func Recommend(req *bom.RecommendRequest) (rsp *bom.ResponseData) {
//获取需要请求的索引 //获取需要请求的索引
index := getRecommendSearchIndex(req) index := getRecommendSearchIndex(req)
//获取es的请求参数 //获取es的请求参数
queryJson := getRecommendSearchParams(true, req) queryJson := getRecommendSearchParams(false, req)
result, err := es.CurlES(index, queryJson) result, err := es.CurlES(index, queryJson)
if err != nil { if err != nil {
log.Error(err) log.Error(err)
...@@ -170,7 +172,9 @@ func getBomTermQuery(goodsName, brandName string, number int32, isRawSearch bool ...@@ -170,7 +172,9 @@ func getBomTermQuery(goodsName, brandName string, number int32, isRawSearch bool
field := "auto_goods_name" field := "auto_goods_name"
query = query.Must(elastic.NewTermQuery(field, goodsName)) query = query.Must(elastic.NewTermQuery(field, goodsName))
} }
//query = query.Filter(elastic.NewTermQuery("status", 1)) if config.Get("web.mode").String() != "debug" {
query.Filter(elastic.NewTermQuery("status", 1))
}
source := elastic.NewSearchSource().Query(query) source := elastic.NewSearchSource().Query(query)
source.From(0) source.From(0)
if isRawSearch { if isRawSearch {
......
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