Commit 7250594f by huangchengyi

1.0

parent 619cd36c
Showing with 19 additions and 23 deletions
......@@ -18,40 +18,36 @@ https://ichunt.com/optimum-9987_1.html?ev=brand_12042^2660_128036||128037
*/
func GetOptimumAttrQuery(ctx *gin.Context,REQUEST_ATTR *map[string][]string,types int) (param string, err error){
query := elastic.NewBoolQuery()
query1 := elastic.NewBoolQuery()
query2 := elastic.NewBoolQuery()
//query1 := elastic.NewBoolQuery()
//query2 := elastic.NewBoolQuery()
//二级分类查询
class_id2 := ctx.Request.FormValue("class_id2")
if class_id2 == "" {
return "",errors.New("二级分类不得为空")
}else{
query1.Must(elastic.NewTermQuery("class_id2",class_id2))
query.Must(elastic.NewTermQuery("class_id2",class_id2))
}
if ctx.Request.FormValue("avail_rank") == "1" { //只显示有货
query.Must(elastic.NewRangeQuery("stock").Gt(0))
}
if ctx.Request.FormValue("goods_name/condition") != "" { //型号搜索
query1.Must(elastic.NewTermQuery("goods_name",ctx.Request.FormValue("goods_name/condition")))
query.Must(elastic.NewTermQuery("goods_name",ctx.Request.FormValue("goods_name/condition")))
}
//存在属性查询
isClassAttr := 0 //存在其他属性搜索
if len(*REQUEST_ATTR) >0 { //存在属性搜索
redisr := gredis.Conn("search_r")
for attr_name_id, attr_value_ids := range *REQUEST_ATTR {
print(attr_name_id)
if attr_name_id == "brand" {
for _,attr_value_id := range attr_value_ids{
query1.Should(elastic.NewTermQuery("brand_id",attr_value_id))
query.Must(elastic.NewTermQuery("brand_id",attr_value_id))
}
}else{
isClassAttr = 1
for _,attr_value_id := range attr_value_ids{
attr_name,_ := gredis.String(redisr.Do("HGET",config.Get("redis_all.class_attr_by_id").String(),attr_name_id)) //查询唯一值,反查sku_id
attr_value_name,_ := gredis.String(redisr.Do("HGET",config.Get("redis_all.class_attr_value_by_id").String(),attr_value_id)) //查询唯一值,反查sku_id
query2.Should(elastic.NewNestedQuery("attrs",elastic.NewBoolQuery().Must(elastic.NewTermQuery("attrs.attr_name",attr_name),elastic.NewTermQuery("attrs.attr_value",attr_value_name))))
query.Must(elastic.NewNestedQuery("attrs",elastic.NewBoolQuery().Must(elastic.NewTermQuery("attrs.attr_name",attr_name),elastic.NewTermQuery("attrs.attr_value",attr_value_name))))
}
}
}
......@@ -86,26 +82,26 @@ func GetOptimumAttrQuery(ctx *gin.Context,REQUEST_ATTR *map[string][]string,type
source.Size(common.MyInt(page_size))
source.From(page_from)
source.Sort("supplier_name",true) //true asc,自营数据在前
source.Sort("sort",false) //true asc,可购买在前
//排序
if ctx.Request.FormValue("stock_rank") == "2" {
source.Sort("stock",true) //true asc
}else{
source.Sort("stock",false) //true asc
if ctx.Request.FormValue("stock_rank") == "1" { //库存排序,最多库存最前
source.Sort("stock",false) //true asc
}
if ctx.Request.FormValue("single_rank") == "2" {
source.Sort("lower_price",true) //true asc
}else{
source.Sort("lower_price",false) //true asc
if ctx.Request.FormValue("stock_rank") == "2" { //库存排序,最少库存最前
source.Sort("stock",true) //true asc
}
}
if ctx.Request.FormValue("single_rank") == "1" { //价格最高在前
source.Sort("lower_price",false) //true asc
}
if ctx.Request.FormValue("single_rank") == "2" { //价格最高在后
source.Sort("lower_price",true) //true asc
}
query.Must(query1)
if isClassAttr == 1 { //存在nested 参数搜索
query.Must(query2)
}
source.Query(query)
searchRequest := elastic.NewSearchRequest().Source(source)
param, _ = searchRequest.Body()
......
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