Browse Source

feat:付费用户搜索优化

wangshan 3 năm trước cách đây
mục cha
commit
dc658e7e83

+ 6 - 0
jyBXCore/rpc/etc/bxcore.yaml

@@ -24,3 +24,9 @@ LimitSearchText:
   LimitKey: mobile_limit_%s
 SearchTypeSwitch: true
 FileSignBool: true
+PaySearchLimit:
+  Switch: true
+  Time: 1
+  WordSize: 7
+  PageNum: 1
+  BiddingId: 6354dsew2342424wer3242423we2344

+ 7 - 0
jyBXCore/rpc/internal/config/config.go

@@ -26,6 +26,13 @@ type Config struct {
 	}
 	SearchTypeSwitch bool
 	FileSignBool     bool
+	PaySearchLimit   struct {
+		Switch    bool
+		Time      int
+		WordSize  int
+		PageNum   int64
+		BiddingId string
+	}
 }
 
 type Db struct {

+ 14 - 1
jyBXCore/rpc/internal/logic/getsearchlistlogic.go

@@ -8,6 +8,7 @@ import (
 	"fmt"
 	IC "jyBXCore/rpc/init"
 	"jyBXCore/rpc/util"
+	"log"
 	"strings"
 	"time"
 
@@ -92,12 +93,24 @@ func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.Search
 		}
 		//无限制
 		if res.IsLimit == 1 {
+			var count int64
+			var list = []*bxcore.SearchList{}
+			//付费用户搜索优化
+			publishTime := in.PublishTime
+			if b := util.IsOptimize(IC.C, in); b {
+				log.Println(in.PublishTime, "----b:", b)
+				count, list = util.GetBidSearchData(in)
+			}
 			//分词后 第二页数据请求 先获取全部数据 再切割
 			if in.SplitKeywords != "" && strings.Contains(in.SplitKeywords, "+&&&") && in.PageNum == 2 {
 				in.KeyWords = strings.ReplaceAll(in.KeyWords, "+&&&", "")
 				in.PageNum = 1
 			}
-			count, list := util.GetBidSearchData(in)
+			//不够五十条 走原始查询
+			if count < util.SearchPageSize {
+				in.PublishTime = publishTime
+				count, list = util.GetBidSearchData(in)
+			}
 			res.KeyWords = in.KeyWords
 			//二次搜索- 一次搜索结果少于一页数据;关键词长度大于三;第一,二页请求;搜索范围包括title;四个条件
 			if len([]rune(in.KeyWords)) > 3 && int(count) < util.SearchPageSize && in.PageNum < 3 && strings.Contains(in.SelectType, "title") {

+ 34 - 0
jyBXCore/rpc/util/search.go

@@ -10,7 +10,9 @@ import (
 	"github.com/zeromicro/go-zero/core/logx"
 	"io/ioutil"
 	IC "jyBXCore/rpc/init"
+	"jyBXCore/rpc/internal/config"
 	"jyBXCore/rpc/type/bxcore"
+	"log"
 	"math/big"
 	"net/http"
 	"net/url"
@@ -655,3 +657,35 @@ func DelRepeatSearchData(resOne, resTwo []*bxcore.SearchList) []*bxcore.SearchLi
 	//})
 	return resOne
 }
+
+//付费用户搜索优化
+func IsOptimize(cc config.Config, in *bxcore.SearchReq) bool {
+	if cc.PaySearchLimit.Switch && in.UserType != "fType" {
+		//首页----字数(<7)
+		if in.PageNum <= cc.PaySearchLimit.PageNum && len([]rune(in.KeyWords)) < cc.PaySearchLimit.WordSize {
+			//时间超过一年----
+			if pTime := GetPublishTime(cc.PaySearchLimit.Time, in.PublishTime); pTime != "" {
+				in.PublishTime = pTime
+				return true
+			}
+		}
+	}
+	return false
+}
+
+//
+func GetPublishTime(tt int, publishTime string) string {
+	//发布时间
+	if publishTime != "" && len(strings.Split(publishTime, "-")) > 1 {
+		now := time.Now()
+		startTime, _ := strconv.ParseInt(strings.Split(publishTime, "-")[0], 10, 64)
+		endTime, _ := strconv.ParseInt(strings.Split(publishTime, "-")[1], 10, 64)
+		pTime := time.Date(now.Year()-tt, now.Month(), now.Day(), 0, 0, 0, 0, time.Local).Unix()
+		log.Println(pTime, "---", endTime)
+		//超过一年
+		if endTime > startTime && pTime > startTime {
+			return fmt.Sprint(pTime) + "-" + fmt.Sprint(endTime)
+		}
+	}
+	return publishTime
+}