Commit ad35df08 by 孙龙

up

parent ac67a6be
Showing with 47 additions and 5 deletions
...@@ -161,19 +161,17 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL ...@@ -161,19 +161,17 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
query := elastic.NewBoolQuery() query := elastic.NewBoolQuery()
if(len(req) > 0){ if(len(req) > 0){
for k,v:=range req{ for k,v:=range req{
k_temp := make([]string,0) k_temp := make([]string,0)
if strings.Contains(k,"/") { if strings.Contains(k,"/") {
k_temp = strings.Split(k,"/") k_temp = strings.Split(k,"/")
if len(k_temp) == 2 { if len(k_temp) == 2 {
isok := makeQuery(query,k_temp,&goods_temp_status,&v,&keyword) isok := makeQuery(query,source,k_temp,&goods_temp_status,&v,&keyword)
if !isok { if !isok {
continue; continue;
} }
} }
} }
} }
} }
source.Query(query) source.Query(query)
...@@ -181,7 +179,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL ...@@ -181,7 +179,7 @@ func searchZiYingGoods( req map[string]string,zy bool,classList *model.ZhyClassL
fmt.Println(res) fmt.Println(res)
} }
func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *int,searchValue *string,keyword *string) bool{ func makeQuery(query *elastic.BoolQuery,source *elastic.SearchSource,conditions []string,goods_temp_status *int,searchValue *string,keyword *string) bool{
var ( var (
err error err error
...@@ -202,6 +200,9 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i ...@@ -202,6 +200,9 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i
redisConn.Close() redisConn.Close()
}() }()
searchKey = strings.TrimSpace(searchKey)
searchCondition = strings.TrimSpace(searchCondition)
*searchValue = strings.TrimSpace(*searchValue)
switch searchCondition{ switch searchCondition{
case "condition": case "condition":
if searchKey != "status" && searchCondition == ""{ if searchKey != "status" && searchCondition == ""{
...@@ -322,9 +323,50 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i ...@@ -322,9 +323,50 @@ func makeQuery(query *elastic.BoolQuery,conditions []string,goods_temp_status *i
query.Must(elastic.NewTermsQuery(searchKey,term_v_interface)) query.Must(elastic.NewTermsQuery(searchKey,term_v_interface))
} }
case "order": case "order":
orderSort := false
if strings.ToLower(*searchValue) == "asc"{
orderSort =true
}else if strings.ToLower(*searchValue) == "desc"{
orderSort =false
}
source.Sort(searchKey,orderSort)
case "range": case "range":
paramsRange := make([]int64,2)
term_v := make([]string,0)
term_v = strings.Split(*searchValue,",")
if len(term_v) > 0{
for i:=0;i<=len(term_v)-1;i++{
if term_v[i] != "" {
if rangeGte,err := strconv.ParseInt(term_v[i], 10, 64);err == nil{
paramsRange[i] = rangeGte
}
}
}
}
query.Must(elastic.NewRangeQuery(searchKey).Gte(paramsRange[0]).Lte(paramsRange[1]))
case "sr": case "sr":
term_v := make([]string,0)
term_v = strings.Split(*searchValue,",")
if len(term_v) == 2{
term_v0 := strings.ToLower(strings.TrimSpace(term_v[0]))
term_v1 := strings.TrimSpace(term_v[1])
if term_v1_int,err := strconv.ParseInt(term_v1, 10, 64);err == nil{
if php2go.InArray(term_v0,[]string{"gt","lt","gte","lte"}){
rangequery := elastic.NewRangeQuery(searchKey)
if term_v0 == "gt"{
rangequery.Gt(term_v1_int)
}else if(term_v0 == "lt"){
rangequery.Lt(term_v1_int)
}else if(term_v0 == "gte"){
rangequery.Gte(term_v1_int)
}else if(term_v0 == "lte"){
rangequery.Lte(term_v1_int)
}
query.Must(rangequery)
}
}
}
case "nested": case "nested":
case "eq": case "eq":
} }
......
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