getsearchlistlogic.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package logic
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
  5. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/service"
  6. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/util"
  7. "context"
  8. <<<<<<< HEAD
  9. =======
  10. "jyBXCore/rpc/entity"
  11. IC "jyBXCore/rpc/init"
  12. "jyBXCore/rpc/service"
  13. "jyBXCore/rpc/util"
  14. >>>>>>> master
  15. "strings"
  16. "time"
  17. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/internal/svc"
  18. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/type/bxcore"
  19. "github.com/zeromicro/go-zero/core/logx"
  20. "log"
  21. )
  22. type GetSearchListLogic struct {
  23. ctx context.Context
  24. svcCtx *svc.ServiceContext
  25. logx.Logger
  26. }
  27. func NewGetSearchListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSearchListLogic {
  28. return &GetSearchListLogic{
  29. ctx: ctx,
  30. svcCtx: svcCtx,
  31. Logger: logx.WithContext(ctx),
  32. }
  33. }
  34. // GetSearchList 标讯搜索结果列表数据
  35. func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.SearchResp, error) {
  36. defer MC.Catch()
  37. res := &bxcore.SearchData{
  38. Count: 0,
  39. List: []*bxcore.SearchList{},
  40. InterceptLimit: int64(MC.IntAllDef(IC.C.KeywordsLimit, 35)),
  41. }
  42. //初始化搜索对象
  43. ks := service.NewKeyWordsSearch()
  44. // 未登录用户只允许翻页和筛选搜索范围 其他参数无效
  45. if in.UserId == "" {
  46. in = &bxcore.SearchReq{
  47. AppId: in.AppId,
  48. PageNum: in.PageNum,
  49. PageSize: in.PageSize,
  50. SelectType: in.SelectType,
  51. KeyWords: in.KeyWords,
  52. Platform: in.Platform,
  53. UserType: in.UserType,
  54. SearchGroup: in.SearchGroup,
  55. Subtype: in.Subtype,
  56. TopType: in.TopType,
  57. }
  58. // 搜索范围只允许筛选 标题和正文 其他的过滤掉
  59. var selectType []string
  60. selectTypeSplit := strings.Split(in.SelectType, ",")
  61. // 未登录用户只能搜标题和正文
  62. for i := 0; i < len(selectTypeSplit); i++ {
  63. if selectTypeSplit[i] == "title" || selectTypeSplit[i] == "content" {
  64. selectType = append(selectType, selectTypeSplit[i])
  65. }
  66. }
  67. if len(selectType) == 0 {
  68. selectType = []string{"title", "content"}
  69. }
  70. //
  71. in.SelectType = strings.Join(selectType, ",")
  72. }
  73. <<<<<<< HEAD
  74. isWhite, _ := service.IsOnTheWhitelist(in.UserId)
  75. =======
  76. //模糊检索数重新格式化
  77. nin := &bxcore.SearchReq{
  78. AppId: in.AppId,
  79. UserId: in.UserId,
  80. Phone: in.Phone,
  81. NewUserId: in.NewUserId,
  82. EntId: in.EntId,
  83. EntUserId: in.EntUserId,
  84. PageNum: in.PageNum,
  85. PageSize: in.PageSize,
  86. Province: in.Province,
  87. City: in.City,
  88. Subtype: in.Subtype,
  89. TopType: in.TopType,
  90. PublishTime: in.PublishTime,
  91. SelectType: in.SelectType,
  92. Price: in.Price,
  93. Industry: in.Industry,
  94. BuyerClass: in.BuyerClass,
  95. BuyerTel: in.BuyerTel,
  96. WinnerTel: in.WinnerTel,
  97. FileExists: in.FileExists,
  98. SearchGroup: in.SearchGroup,
  99. SearchMode: 1,
  100. WordsMode: in.WordsMode,
  101. KeyWords: in.KeyWords,
  102. AdditionalWords: in.AdditionalWords,
  103. ExclusionWords: in.ExclusionWords,
  104. UserType: in.UserType,
  105. Platform: in.Platform,
  106. BidField: in.BidField,
  107. PositionType: in.PositionType,
  108. PositionId: in.PositionId,
  109. AccountId: in.AccountId,
  110. MgoUserId: in.MgoUserId,
  111. LimitFlag: in.LimitFlag,
  112. IsNew: in.IsNew,
  113. District: in.District,
  114. Buyer: in.Buyer,
  115. Winner: in.Winner,
  116. Agency: in.Agency,
  117. IsFuzzyNumber: true,
  118. }
  119. >>>>>>> master
  120. //处理搜索条件
  121. heightWords := ks.SearchParamsHandle(in, isWhite)
  122. if (in.PageNum < 0 && in.PageSize < 0) || ks.IsSearch == "F" { //没有权限
  123. return &bxcore.SearchResp{
  124. Data: res,
  125. ErrMsg: "",
  126. ErrCode: 0,
  127. }, nil
  128. }
  129. //判断是否是空搜索,如果是空搜索,查缓存数据
  130. if ks.IsEmptySearch(in, isWhite) {
  131. log.Println("空查询分组", in.SearchGroup)
  132. res.List, res.Count, res.Total = ks.GetBidSearchListByCache(in)
  133. return &bxcore.SearchResp{
  134. Data: res,
  135. ErrMsg: "",
  136. ErrCode: 0,
  137. }, nil
  138. }
  139. //异常付费用户 参数不是免费fType,但是又不是付费用户;还有一种是未登录用户 稍后处理
  140. if in.UserType != "fType" && !in.IsPay {
  141. return &bxcore.SearchResp{
  142. ErrCode: -1,
  143. ErrMsg: "无权限",
  144. }, nil
  145. }
  146. t := time.Now()
  147. //招标信息有效查询
  148. res.IsLimit = 1
  149. //查询数据
  150. searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
  151. //全文检索限制
  152. if searchLimit {
  153. res.IsLimit = util.IsLimited(in.LimitFlag, in.UserId, in.UserType != "fType", in.IsNew)
  154. if res.IsLimit == 1 { //没有被限制
  155. defer util.Limit()
  156. }
  157. }
  158. //无限制
  159. if res.IsLimit == 1 {
  160. //付费用户搜索优化--默认搜索5年数据,数据量太多,接口反应太慢,前两页数据 时间范围根据配置缩小查询以达到快速查询的目的。
  161. publishTime := in.PublishTime
  162. if b := util.IsOptimize(IC.C, in); b {
  163. t1 := time.Now()
  164. res.Count, res.Total, res.List = ks.GetBidSearchList(in) // util.GetBidSearchData(in)
  165. log.Println("1查询耗时:", time.Since(t1))
  166. }
  167. //如果优化查询数据量太少,和配置数据量作比较,不够的话走原始查询
  168. if res.Count < IC.C.PaySearchLimit.PageSize {
  169. t2 := time.Now()
  170. in.PublishTime = publishTime
  171. res.Count, res.Total, res.List = ks.GetBidSearchList(in)
  172. log.Println("2查询耗时:", time.Since(t2))
  173. }
  174. // 精准模式不足50条的非空标讯查询 匹配模糊查询数
  175. if res.Count < IC.C.PaySearchLimit.PrecisionNum && in.SearchMode == 0 && in.KeyWords != "" {
  176. ks.SearchParamsHandle(nin)
  177. res.BCount = service.GetBidSearchCount(nin)
  178. log.Println("精准查询数据不足 匹配模糊查询数:", res.BCount)
  179. }
  180. res.KeyWords = strings.Join(heightWords, " ")
  181. res.InterceptOtherWords = in.InterceptOtherWords
  182. res.InterceptKeyWords = in.InterceptKeyWords
  183. }
  184. log.Println("关键词 -全部- 查询耗时:", time.Since(t).Seconds())
  185. return &bxcore.SearchResp{
  186. Data: res,
  187. ErrMsg: "",
  188. ErrCode: 0,
  189. }, nil
  190. }