getsearchlistlogic.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. package logic
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "jyBXCore/rpc/entity"
  6. IC "jyBXCore/rpc/init"
  7. "time"
  8. "jyBXCore/rpc/internal/svc"
  9. "jyBXCore/rpc/type/bxcore"
  10. "github.com/zeromicro/go-zero/core/logx"
  11. )
  12. type GetSearchListLogic struct {
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. logx.Logger
  16. }
  17. func NewGetSearchListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSearchListLogic {
  18. return &GetSearchListLogic{
  19. ctx: ctx,
  20. svcCtx: svcCtx,
  21. Logger: logx.WithContext(ctx),
  22. }
  23. }
  24. // 标讯搜索结果列表数据
  25. func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.SearchResp, error) {
  26. defer MC.Catch()
  27. //用户身份 是否登录
  28. if in.UserId == "" {
  29. return &bxcore.SearchResp{
  30. ErrCode: -1,
  31. ErrMsg: "用户信息异常",
  32. }, nil
  33. }
  34. res := &bxcore.SearchData{
  35. Count: 0,
  36. List: []*bxcore.SearchList{},
  37. InterceptLimit: int64(MC.IntAllDef(IC.C.KeywordsLimit, 35)),
  38. NumberMsg: IC.C.DefaultBidInfo.NumMsg,
  39. }
  40. //初始化搜索对象
  41. ks := entity.NewKeyWordsSearch()
  42. //判断是否是空搜索,如果是空搜索,查缓存数据
  43. if ks.IsEmptySearch(in) {
  44. res.List, res.Count = ks.GetBidListByCache(in)
  45. return &bxcore.SearchResp{
  46. Data: res,
  47. ErrMsg: "",
  48. ErrCode: 0,
  49. }, nil
  50. }
  51. //更新关键词搜索历史记录
  52. go ks.SaveKeyWordsToHistory(in)
  53. ////判断搜索是否有查询条件
  54. ////判断用户身份
  55. t := time.Now()
  56. ////
  57. //if in.SelectType == "" {
  58. // in.SelectType = "title,content"
  59. //}
  60. //in.Industry = strings.TrimSpace(in.Industry)
  61. //userInfo := util.GetVipState(IC.MainMysql, IC.Mgo, in.UserId)
  62. ////付费用户
  63. //if in.UserType != "fType" && !userInfo.IsPayedUser() {
  64. // return &bxcore.SearchResp{
  65. // ErrCode: -1,
  66. // ErrMsg: "无权限",
  67. // }, nil
  68. //}
  69. //if in.UserType == "fType" {
  70. // in.BuyerClass = ""
  71. // in.BuyerTel = ""
  72. // in.WinnerTel = ""
  73. // in.ExclusionWords = ""
  74. // in.City = ""
  75. //}
  76. //in.KeyWords = strings.TrimSpace(in.KeyWords)
  77. ////搜索范围
  78. //queryItems := userInfo.GetQueryItems(in.SelectType, IC.C.BidSearchOldUserLimit)
  79. //in.SelectType = strings.Join(queryItems, ",")
  80. ////b_word, s_word := "", ""
  81. //res.IsLimit = 1
  82. ////以后可能会出现 关键词 C++ 等带+的关键词
  83. //if in.KeyWords != "" {
  84. // res.InterceptKeywords, res.InterceptWord, in.KeyWords = util.InterceptSearchKW(in.KeyWords, MC.IntAllDef(IC.C.KeywordsLimit, 35), len(in.Industry) == 0)
  85. //}
  86. ////查询数据
  87. //if in.KeyWords != "" || in.Industry != "" {
  88. // //查询数据
  89. // searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
  90. // //全文检索限制
  91. // if searchLimit {
  92. // res.IsLimit = util.IsLimited(in.UserId, in.UserType != "fType")
  93. // if res.IsLimit == 1 { //没有被限制
  94. // defer util.Limit()
  95. // }
  96. // }
  97. // //无限制
  98. // if res.IsLimit == 1 {
  99. // var count int64
  100. // var list = []*bxcore.SearchList{}
  101. // //付费用户搜索优化
  102. // publishTime := in.PublishTime
  103. // t1 := time.Now()
  104. // if b := util.IsOptimize(IC.C, in); b {
  105. // count, list = util.GetBidSearchData(in)
  106. // count += 1 //避免刚好50条 无法加载下一页数据
  107. // }
  108. // logx.Info("1查询耗时", time.Since(t1))
  109. // t2 := time.Now()
  110. // //分词后 第二页数据请求 先获取全部数据 再切割
  111. // if in.SplitKeywords != "" && strings.Contains(in.SplitKeywords, "+&&&") && in.PageNum == 2 {
  112. // in.KeyWords = strings.ReplaceAll(in.KeyWords, "+&&&", "")
  113. // in.PageNum = 1
  114. // }
  115. // //不够配置条 走原始查询
  116. // if count < IC.C.PaySearchLimit.PageSize {
  117. // in.PublishTime = publishTime
  118. // count, list = util.GetBidSearchData(in)
  119. // }
  120. // logx.Info("2查询耗时:", time.Since(t2))
  121. // res.KeyWords = in.KeyWords
  122. // //二次搜索- 一次搜索结果少于一页数据;关键词长度大于三;第一,二页请求;搜索范围包括title;四个条件
  123. // if len([]rune(in.KeyWords)) > 3 && int(count) < util.SearchPageSize && in.PageNum < 3 && strings.Contains(in.SelectType, "title") {
  124. // if iksk := util.HttpEs(in.KeyWords, "ik_smart", IC.DB.Es.Addr); iksk != "" {
  125. // t3 := time.Now()
  126. // iksk_temp := in.KeyWords
  127. // in.KeyWords = iksk
  128. // in.SelectType = "title"
  129. // //最多查两页数据
  130. // in.PageSize = 2 * in.PageSize
  131. // _, secondList := util.GetBidSearchData(in)
  132. // //数据合并 去重 排序
  133. // list = util.DelRepeatSearchData(list, secondList)
  134. // count = int64(len(list))
  135. // switch {
  136. // case count > util.SearchPageSize:
  137. // count = MC.If(count > int64(util.SearchPageSize*2), int64(util.SearchPageSize*2), count).(int64)
  138. // list = list[:util.SearchPageSize]
  139. // if in.SplitKeywords != "" {
  140. // list = list[util.SearchPageSize:count]
  141. // }
  142. // case count <= util.SearchPageSize:
  143. // list = list[:count]
  144. // }
  145. // var kbool = map[string]bool{}
  146. // var karr = []string{}
  147. // for _, v := range strings.Split(fmt.Sprintf("%s+%s", iksk_temp, iksk), "+") {
  148. // if kbool[v] {
  149. // continue
  150. // }
  151. // karr = append(karr, v)
  152. // kbool[v] = true
  153. // }
  154. // //+&&& 作为二次搜索第二页数据请求的标识(临时处理)
  155. // res.KeyWords = strings.Join(karr, "+") + "+&&&"
  156. // logx.Info("3查询耗时:", time.Since(t3))
  157. // }
  158. // }
  159. // limitCount := MC.If(in.UserType != "fType", int64(util.SearchPageSize*util.SearchMaxPageNum_PAYED), int64(util.SearchPageSize*util.SearchMaxPageNum)).(int64)
  160. // if count > limitCount {
  161. // count = limitCount
  162. // }
  163. // //是否收藏
  164. // //util.MakeCollection(in.UserId, list)
  165. // res.TotalPage = MC.If(in.PageNum == 1, (count+int64(util.SearchPageSize)-1)/int64(util.SearchPageSize), res.TotalPage).(int64)
  166. // res.Count = count
  167. // res.List = list
  168. // }
  169. // logx.Info("关键词 -0- 查询耗时:", time.Since(t).Seconds())
  170. //} else if in.Platform == "PC" {
  171. //
  172. //}
  173. logx.Info("关键词 -全部- 查询耗时:", time.Since(t).Seconds())
  174. return &bxcore.SearchResp{
  175. Data: res,
  176. ErrMsg: "",
  177. ErrCode: 0,
  178. }, nil
  179. }