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
paramsRawSearch = true
}
//构建一个goods_name对应的bomItems列表
searchRequest := getSearchParams(index, bom, sort, paramsRawSearch,isAlike)
searchRequest := getSearchParams(index, bom, sort, paramsRawSearch,rawSearch,isAlike)
searchFlag = true
common.PrintDebug("查询es索引",index)
......@@ -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.AttrList)
bomItem.Encap = TransformEncap(bomItem.Encap)
//fmt.Println("封装 : ", bomItem.Encap)
query := getTermQuery(bomItem, sort, flag,isAlike)
query := getTermQuery(bomItem, sort, flag,rawSearch,isAlike)
source := es.NewSearchSource().Query(query)
if sort == 1 {
source.Sort("_score", false)
//source.Sort("moq", true)
//source.Sort("_score", false)
source.Sort("moq", true)
}
//要去判断sort,sort=2是按照价格(价格有问题,目前按起订量)排序
if sort == 2 {
source.Sort("_score", false)
//source.Sort("moq", true)
//source.Sort("_score", false)
source.Sort("moq", true)
//sort=3是按照库存排序
} else if sort == 3 {
//source.Sort("_score", false)
......@@ -114,7 +114,7 @@ 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) {
func getTermQuery(bomItem model.BomItem, sort int, flag bool,rawSearch bool,isAlike bool) (query *es.BoolQuery) {
query = es.NewBoolQuery()
goodsName := common.DrawLetterNum(bomItem.GoodsName)
if flag {
......@@ -165,8 +165,14 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
if 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 推荐型号搜索
query = query.Must(es.NewTermsQuery("alike_spu_name.raw", goodsName))
} else if goodsName != "" {
......@@ -175,7 +181,10 @@ func getTermQuery(bomItem model.BomItem, sort int, flag bool,isAlike bool) (quer
common.PrintDebug("isalike:",isAlike)
//只显示库存大于0的数据
query.Must(es.NewRangeQuery("stock").Gt(0))
if rawSearch == false { //不是精确匹配
query.Must(es.NewRangeQuery("stock").Gt(0))
}
//按价格排序
//if sort == 2 || sort == 1 {
// 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