Commit 0b91b2c2 by hcy001

bom4

parent 28a7cc04
Showing with 20 additions and 11 deletions
...@@ -32,7 +32,7 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor ...@@ -32,7 +32,7 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
paramsRawSearch = true paramsRawSearch = true
} }
//构建一个goods_name对应的bomItems列表 //构建一个goods_name对应的bomItems列表
searchRequest := getSearchParams(index, bom, sort, paramsRawSearch,isAlike) searchRequest := getSearchParams(index, bom, sort, paramsRawSearch,rawSearch,isAlike)
searchFlag = true searchFlag = true
common.PrintDebug("查询es索引",index) common.PrintDebug("查询es索引",index)
...@@ -87,21 +87,21 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor ...@@ -87,21 +87,21 @@ func search(index string, bomId int, bomItems []model.BomItem, deliveryType, sor
} }
//构建请求参数 //构建请求参数
func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool,isAlike bool) (searchRequest *es.SearchRequest) { func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool,rawSearch bool,isAlike bool) (searchRequest *es.SearchRequest) {
//fmt.Println("商品名称 : ", bomItem.GoodsName) //fmt.Println("商品名称 : ", bomItem.GoodsName)
//fmt.Println("参数列表 : ", bomItem.AttrList) //fmt.Println("参数列表 : ", bomItem.AttrList)
bomItem.Encap = TransformEncap(bomItem.Encap) bomItem.Encap = TransformEncap(bomItem.Encap)
//fmt.Println("封装 : ", bomItem.Encap) //fmt.Println("封装 : ", bomItem.Encap)
query := getTermQuery(bomItem, sort, flag,isAlike) query := getTermQuery(bomItem, sort, flag,rawSearch,isAlike)
source := es.NewSearchSource().Query(query) source := es.NewSearchSource().Query(query)
if sort == 1 { if sort == 1 {
source.Sort("_score", false) //source.Sort("_score", false)
//source.Sort("moq", true) source.Sort("moq", true)
} }
//要去判断sort,sort=2是按照价格(价格有问题,目前按起订量)排序 //要去判断sort,sort=2是按照价格(价格有问题,目前按起订量)排序
if sort == 2 { if sort == 2 {
source.Sort("_score", false) //source.Sort("_score", false)
//source.Sort("moq", true) source.Sort("moq", true)
//sort=3是按照库存排序 //sort=3是按照库存排序
} else if sort == 3 { } else if sort == 3 {
//source.Sort("_score", false) //source.Sort("_score", false)
...@@ -114,7 +114,7 @@ func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool,is ...@@ -114,7 +114,7 @@ func getSearchParams(index string, bomItem model.BomItem, sort int, flag bool,is
} }
//构建term条件 //构建term条件
func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (query *es.BoolQuery) { func getTermQuery(bomItem model.BomItem, sort int, flag bool,rawSearch bool,isAlike bool) (query *es.BoolQuery) {
query = es.NewBoolQuery() query = es.NewBoolQuery()
goodsName := common.DrawLetterNum(bomItem.GoodsName) goodsName := common.DrawLetterNum(bomItem.GoodsName)
if flag { if flag {
...@@ -165,8 +165,14 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer ...@@ -165,8 +165,14 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
if bomItem.Encap != "" { if bomItem.Encap != "" {
query = query.Must(es.NewTermQuery("attr_bom", "FZ€"+bomItem.Encap)) query = query.Must(es.NewTermQuery("attr_bom", "FZ€"+bomItem.Encap))
} }
//搜索库存
query = query.Should(es.NewRangeQuery("stock").Gte(bomItem.Number * bomItem.Amount)) //精确匹配
if rawSearch {
query = query.Must(es.NewRangeQuery("stock").Gte(bomItem.Number * bomItem.Amount)) //搜索库存
}else{
query = query.Should(es.NewRangeQuery("stock").Gte(bomItem.Number * bomItem.Amount)) //搜索库存
}
} else if isAlike && goodsName != "" { //todo 推荐型号搜索 } else if isAlike && goodsName != "" { //todo 推荐型号搜索
query = query.Must(es.NewTermsQuery("alike_spu_name.raw", goodsName)) query = query.Must(es.NewTermsQuery("alike_spu_name.raw", goodsName))
} else if goodsName != "" { } else if goodsName != "" {
...@@ -175,7 +181,10 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer ...@@ -175,7 +181,10 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
common.PrintDebug("isalike:",isAlike) common.PrintDebug("isalike:",isAlike)
//只显示库存大于0的数据 //只显示库存大于0的数据
query.Must(es.NewRangeQuery("stock").Gt(0)) if rawSearch == false { //不是精确匹配
query.Must(es.NewRangeQuery("stock").Gt(0))
}
//按价格排序 //按价格排序
//if sort == 2 || sort == 1 { //if sort == 2 || sort == 1 {
// query = query.Filter(es.NewRangeQuery("single_price").Gt(0)) // query = query.Filter(es.NewRangeQuery("single_price").Gt(0))
......
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