|
@@ -43,7 +43,7 @@ func GetSupplyInfoList(in *consumerinfo.SupplyInfoSearchReq, b bool) (list *[]ma
|
|
|
}
|
|
|
|
|
|
qstr := GetSearchQuery(in)
|
|
|
- log.Println("=======", qstr)
|
|
|
+ log.Println("===qstr====:", qstr)
|
|
|
if in.PageIndex == 1 {
|
|
|
total = elastic.Count(INDEX, TYPE, qstr)
|
|
|
}
|
|
@@ -97,8 +97,9 @@ func SupplyRedis(in *consumerinfo.SupplyInfoSearchReq) (int64, *[]map[string]int
|
|
|
}
|
|
|
|
|
|
func GetSearchQuery(in *consumerinfo.SupplyInfoSearchReq) (qstr string) {
|
|
|
- query := `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
|
|
|
- multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
|
|
|
+ query := `{"query":{"bool":{"filter":[%s],"must_not":[%s]}}}`
|
|
|
+ multiMatch := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
|
|
|
+ boolShould := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
|
|
|
province := `{"terms":{"province":[%s]}}`
|
|
|
city := `{"terms":{"city":[%s]}}`
|
|
|
publishTime := `{"range":{"publish_time":{"gte":%d,"lt":%d}}}`
|
|
@@ -107,13 +108,14 @@ func GetSearchQuery(in *consumerinfo.SupplyInfoSearchReq) (qstr string) {
|
|
|
|
|
|
//关键词
|
|
|
if in.Keywords != "" {
|
|
|
- keyword_multi_match := fmt.Sprintf(multi_match, "%s", in.SearchType)
|
|
|
+ keyword_multi_match := fmt.Sprintf(multiMatch, "%s", in.SearchType)
|
|
|
shoulds := []string{}
|
|
|
for _, v := range strings.Split(in.Keywords, "+") {
|
|
|
shoulds = append(shoulds, fmt.Sprintf(keyword_multi_match, elastic.ReplaceYH(v)))
|
|
|
}
|
|
|
musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))
|
|
|
}
|
|
|
+ areas := []string{}
|
|
|
//省份
|
|
|
if in.Province != "" {
|
|
|
pv := ``
|
|
@@ -123,7 +125,7 @@ func GetSearchQuery(in *consumerinfo.SupplyInfoSearchReq) (qstr string) {
|
|
|
}
|
|
|
pv += `"` + v + `"`
|
|
|
}
|
|
|
- musts = append(musts, fmt.Sprintf(province, pv))
|
|
|
+ areas = append(areas, fmt.Sprintf(province, pv))
|
|
|
}
|
|
|
//城市
|
|
|
if in.City != "" {
|
|
@@ -134,7 +136,10 @@ func GetSearchQuery(in *consumerinfo.SupplyInfoSearchReq) (qstr string) {
|
|
|
}
|
|
|
cv += `"` + v + `"`
|
|
|
}
|
|
|
- musts = append(musts, fmt.Sprintf(city, cv))
|
|
|
+ areas = append(areas, fmt.Sprintf(city, cv))
|
|
|
+ }
|
|
|
+ if len(areas) > 0 {
|
|
|
+ musts = append(musts, fmt.Sprintf(boolShould, strings.Join(areas, ",")))
|
|
|
}
|
|
|
//发布时间
|
|
|
if in.Time != "" && strings.Contains(in.Time, "-") {
|
|
@@ -157,7 +162,6 @@ func GetSearchQuery(in *consumerinfo.SupplyInfoSearchReq) (qstr string) {
|
|
|
}
|
|
|
|
|
|
qstr = fmt.Sprintf(query, strings.Join(musts, ","), "")
|
|
|
- log.Println("qstr", qstr)
|
|
|
return
|
|
|
}
|
|
|
|