|
@@ -1,6 +1,9 @@
|
|
|
package model
|
|
|
|
|
|
import (
|
|
|
+ "app.yhyue.com/moapp/jyInfo/rpc/model"
|
|
|
+ mc "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/redis"
|
|
|
"fmt"
|
|
|
"log"
|
|
|
"strconv"
|
|
@@ -8,7 +11,6 @@ import (
|
|
|
"time"
|
|
|
|
|
|
"app.yhyue.com/moapp/jyInfo/rpc/consumer/consumerinfo"
|
|
|
-
|
|
|
"app.yhyue.com/moapp/jybase/esv1"
|
|
|
)
|
|
|
|
|
@@ -32,6 +34,13 @@ func GetSupplyInfoList(in *consumerinfo.SupplyInfoSearchReq, b bool) (list *[]ma
|
|
|
} else {
|
|
|
in.SearchType = `"title"`
|
|
|
}
|
|
|
+
|
|
|
+ //默认信息查询redis
|
|
|
+ if in.Keywords == "" && in.City == "" && in.SearchType == "title" && in.Province == "" && in.Time == "" && in.Status == "0" && in.PageIndex <= 10 {
|
|
|
+ total, list = SupplyRedis(in)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
qstr := GetSearchQuery(in)
|
|
|
if in.PageIndex == 1 {
|
|
|
total = elastic.Count(INDEX, TYPE, qstr)
|
|
@@ -46,7 +55,45 @@ func GetSupplyInfoList(in *consumerinfo.SupplyInfoSearchReq, b bool) (list *[]ma
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//
|
|
|
+//SupplyRedis 默认搜索时添加redis
|
|
|
+func SupplyRedis(in *consumerinfo.SupplyInfoSearchReq) (int64, *[]map[string]interface{}) {
|
|
|
+ var (
|
|
|
+ listData []map[string]interface{}
|
|
|
+ total int64
|
|
|
+ list []map[string]interface{}
|
|
|
+ )
|
|
|
+ supplyData := redis.Get("other", "supply_search_key")
|
|
|
+ if supplyData == nil {
|
|
|
+ qstr := GetSearchQuery(in)
|
|
|
+ if in.PageIndex == 1 {
|
|
|
+ total = elastic.Count(INDEX, TYPE, qstr)
|
|
|
+ }
|
|
|
+ lists := elastic.GetAllByNgram(INDEX, TYPE, qstr, ``, Search_sort, Search_field, 0, 500, 0, false)
|
|
|
+ if lists == nil || len(*lists) == 0 {
|
|
|
+ return total, &list
|
|
|
+ }
|
|
|
+ listData = *lists
|
|
|
+ redisData := map[string]interface{}{
|
|
|
+ "total": total,
|
|
|
+ "list": listData,
|
|
|
+ }
|
|
|
+ redis.Put("other", "supply_search_key", redisData, model.SupplyRedDay)
|
|
|
+ } else {
|
|
|
+ data, _ := supplyData.(map[string]interface{})
|
|
|
+ if in.PageIndex == 1 {
|
|
|
+ total = mc.Int64All(data["total"])
|
|
|
+ }
|
|
|
+ listData = data["list"].([]map[string]interface{})
|
|
|
+ }
|
|
|
+ if in.PageSize*in.PageIndex <= mc.Int64All(len(listData)) {
|
|
|
+ list = listData[(in.PageSize-1)*in.PageIndex : in.PageSize*in.PageIndex]
|
|
|
+ } else if (in.PageSize-1)*in.PageIndex <= mc.Int64All(len(listData)) {
|
|
|
+ list = listData[(in.PageSize-1)*in.PageIndex:]
|
|
|
+ }
|
|
|
+
|
|
|
+ return total, &list
|
|
|
+}
|
|
|
+
|
|
|
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]}}`
|