Browse Source

feat:二次分词查询

wangshan 3 years ago
parent
commit
3463e358f6

+ 5 - 4
jyBXBase/rpc/internal/logic/newestbiddinglogic.go

@@ -54,15 +54,13 @@ func (l *NewestBiddingLogic) NewestBidding(in *bxbase.NewestBiddingReq) (*bxbase
 		//登录用户
 		if in.UserId != "" {
 			//获取订阅信息
-			userMap, ok := IC.Mgo.FindById("user", rks, `{"o_jy":1,"o_vipjy":1,"i_vip_status":1}`)
+			userMap, ok := IC.Mgo.FindById("user", rks, `{"o_jy":1,"o_vipjy":1,"i_vip_status":1,"o_member_jy":1,"i_member_status":1}`)
 			if !ok || userMap == nil || len(*userMap) == 0 {
 				//查询出错
 				res.ErrCode = -1
 				res.ErrMsg = fmt.Errorf("未查询到用户信息").Error()
 				return res
 			}
-			res.Data.History = strings.Split(redis.GetStr("other", "s_"+in.UserId), ",")
-			//根据订阅词获取查询语句
 			vipStatus := MC.IntAll((*userMap)["i_vip_status"])
 			//vip用户
 			if vipStatus > 0 {
@@ -89,8 +87,11 @@ func (l *NewestBiddingLogic) NewestBidding(in *bxbase.NewestBiddingReq) (*bxbase
 				return res
 			}
 			//搜索历史-关键词
-			hKeys := redis.GetStr("other", fmt.Sprintf("s_%", in.UserId))
+			hKeys := redis.GetStr("other", fmt.Sprintf("s_%", in.UserId, in.UserId))
 			if hKeys != "" && len(strings.Split(hKeys, ",")) > 0 {
+				//历史搜索
+				res.Data.History = strings.Split(hKeys, ",")
+				//根据订阅词获取查询语句
 				query := model.NewestQuery("", hKeys)
 				result := model.NewestES(query)
 				res.Data.IsVip = false

+ 21 - 5
jyBXCore/rpc/internal/logic/getsearchlistlogic.go

@@ -62,8 +62,6 @@ func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.Search
 			ErrMsg:  "无权限",
 		}, nil
 	}
-	//搜索范围
-	queryItems := userInfo.GetQueryItems(in.SelectType, IC.C.BidSearchOldUserLimit)
 	if in.UserType == "fType" {
 		in.BuyerClass = ""
 		in.BuyerTel = ""
@@ -72,7 +70,8 @@ func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.Search
 		in.City = ""
 	}
 	in.KeyWords = strings.TrimSpace(in.KeyWords)
-	searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
+	//搜索范围
+	queryItems := userInfo.GetQueryItems(in.SelectType, IC.C.BidSearchOldUserLimit)
 	in.SelectType = strings.Join(queryItems, ",")
 	//b_word, s_word := "", ""
 	res.IsLimit = 1
@@ -82,6 +81,7 @@ func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.Search
 	//查询数据
 	if in.KeyWords != "" || in.Industry != "" {
 		//查询数据
+		searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
 		//全文检索限制
 		if searchLimit {
 			res.IsLimit = util.IsLimited(in.UserId, in.UserType != "fType")
@@ -98,9 +98,25 @@ func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.Search
 			}
 			//二次搜索- 一次搜索结果少于一页数据;关键词长度大于三;第一,二页请求;搜索范围包括title;四个条件
 			if len([]rune(in.KeyWords)) > 3 && int(count) < util.SearchPageSize && in.PageNum < 3 && strings.Contains(in.SelectType, "title") {
-				if in.KeyWords = util.HttpEs(in.KeyWords, "ik_smart", IC.DB.Es.Addr); in.KeyWords != "" {
+				if iksk := util.HttpEs(in.KeyWords, "ik_smart", IC.DB.Es.Addr); iksk != "" {
+					//log.Println("分词:", iksk) 分词后查询数据量有可能小于不分词查询数据量  -- 原因:未分词前是全文查询 分词后是标题查询;
+					iksk = fmt.Sprintf("%s+%s", in.KeyWords, iksk)
+					var kbool = map[string]bool{}
+					var karr = []string{}
+					for _, v := range strings.Split(iksk, "+") {
+						if kbool[v] {
+							continue
+						}
+						karr = append(karr, v)
+						kbool[v] = true
+					}
+					in.KeyWords = strings.Join(karr, "+")
 					in.SelectType = "title"
-					count, list = util.GetBidSearchData(in)
+					_count, _list := util.GetBidSearchData(in)
+					if count < _count {
+						count = _count
+						list = _list
+					}
 					//最多两页数据
 					if count > util.SearchPageSize*2 {
 						count = util.SearchPageSize * 2

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

@@ -367,6 +367,7 @@ func GetSearchQuery(in *bxcore.SearchReq, mustquery string) (qstr string) {
 		}
 		shoulds := []string{}
 		var switchBool = strings.Contains(findfields, "detail") && strings.Contains(findfields, "title") && IC.C.SearchTypeSwitch
+		log.Println("in.KeyWords:", in.KeyWords)
 		for _, v := range strings.Split(in.KeyWords, "+") {
 			//标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
 			if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {

+ 3 - 3
jyBXSubscribe/rpc/util/push.go

@@ -31,7 +31,7 @@ const (
 	SubVipFlag   = "vType"
 	MemberFlag   = "mType"
 	EntnicheFlag = "eType"
-	threeDay     = 172800
+	oneDay       = 24 * 60 * 60
 )
 
 var aboutDbMsg map[string]*AboutDbMsg = map[string]*AboutDbMsg{
@@ -119,7 +119,7 @@ func (h *subscribePush) GetTodayCache(userId string) (*SubPush, error) {
 
 //往pushcache_2_a中放
 func (h *subscribePush) PutTodayCache(userId string, pc_a *SubPush) {
-	redis.Put("pushcache_2_b", h.todayKey(userId), pc_a, threeDay)
+	redis.Put("pushcache_2_b", h.todayKey(userId), pc_a, oneDay)
 }
 
 //获取redis key
@@ -557,7 +557,7 @@ func (s *subscribePush) GetJyPushs(datas []map[string]interface{}) (pushCas []*P
 
 //查看全部列表缓存
 func (s *subscribePush) PutAllCache(userId string, datas *SubPush) {
-	redis.Put("pushcache_2_a", s.allKey(userId), datas, threeDay)
+	redis.Put("pushcache_2_a", s.allKey(userId), datas, oneDay)
 }
 
 func (s *subscribePush) GetAllCache(userId string) (*SubPush, error) {