package logic import ( MC "app.yhyue.com/moapp/jybase/common" "context" "jyBXCore/rpc/entity" IC "jyBXCore/rpc/init" "time" "jyBXCore/rpc/internal/svc" "jyBXCore/rpc/type/bxcore" "github.com/zeromicro/go-zero/core/logx" ) type GetSearchListLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewGetSearchListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSearchListLogic { return &GetSearchListLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } // 标讯搜索结果列表数据 func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.SearchResp, error) { defer MC.Catch() //用户身份 是否登录 if in.UserId == "" { return &bxcore.SearchResp{ ErrCode: -1, ErrMsg: "用户信息异常", }, nil } res := &bxcore.SearchData{ Count: 0, List: []*bxcore.SearchList{}, InterceptLimit: int64(MC.IntAllDef(IC.C.KeywordsLimit, 35)), NumberMsg: IC.C.DefaultBidInfo.NumMsg, } //初始化搜索对象 ks := entity.NewKeyWordsSearch() //判断是否是空搜索,如果是空搜索,查缓存数据 if ks.IsEmptySearch(in) { res.List, res.Count = ks.GetBidListByCache(in) return &bxcore.SearchResp{ Data: res, ErrMsg: "", ErrCode: 0, }, nil } //更新关键词搜索历史记录 go ks.SaveKeyWordsToHistory(in) ////判断搜索是否有查询条件 ////判断用户身份 t := time.Now() //// //if in.SelectType == "" { // in.SelectType = "title,content" //} //in.Industry = strings.TrimSpace(in.Industry) //userInfo := util.GetVipState(IC.MainMysql, IC.Mgo, in.UserId) ////付费用户 //if in.UserType != "fType" && !userInfo.IsPayedUser() { // return &bxcore.SearchResp{ // ErrCode: -1, // ErrMsg: "无权限", // }, nil //} //if in.UserType == "fType" { // in.BuyerClass = "" // in.BuyerTel = "" // in.WinnerTel = "" // in.ExclusionWords = "" // in.City = "" //} //in.KeyWords = strings.TrimSpace(in.KeyWords) ////搜索范围 //queryItems := userInfo.GetQueryItems(in.SelectType, IC.C.BidSearchOldUserLimit) //in.SelectType = strings.Join(queryItems, ",") ////b_word, s_word := "", "" //res.IsLimit = 1 ////以后可能会出现 关键词 C++ 等带+的关键词 //if in.KeyWords != "" { // res.InterceptKeywords, res.InterceptWord, in.KeyWords = util.InterceptSearchKW(in.KeyWords, MC.IntAllDef(IC.C.KeywordsLimit, 35), len(in.Industry) == 0) //} ////查询数据 //if in.KeyWords != "" || in.Industry != "" { // //查询数据 // searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ",")) // //全文检索限制 // if searchLimit { // res.IsLimit = util.IsLimited(in.UserId, in.UserType != "fType") // if res.IsLimit == 1 { //没有被限制 // defer util.Limit() // } // } // //无限制 // if res.IsLimit == 1 { // var count int64 // var list = []*bxcore.SearchList{} // //付费用户搜索优化 // publishTime := in.PublishTime // t1 := time.Now() // if b := util.IsOptimize(IC.C, in); b { // count, list = util.GetBidSearchData(in) // count += 1 //避免刚好50条 无法加载下一页数据 // } // logx.Info("1查询耗时", time.Since(t1)) // t2 := time.Now() // //分词后 第二页数据请求 先获取全部数据 再切割 // if in.SplitKeywords != "" && strings.Contains(in.SplitKeywords, "+&&&") && in.PageNum == 2 { // in.KeyWords = strings.ReplaceAll(in.KeyWords, "+&&&", "") // in.PageNum = 1 // } // //不够配置条 走原始查询 // if count < IC.C.PaySearchLimit.PageSize { // in.PublishTime = publishTime // count, list = util.GetBidSearchData(in) // } // logx.Info("2查询耗时:", time.Since(t2)) // res.KeyWords = in.KeyWords // //二次搜索- 一次搜索结果少于一页数据;关键词长度大于三;第一,二页请求;搜索范围包括title;四个条件 // if len([]rune(in.KeyWords)) > 3 && int(count) < util.SearchPageSize && in.PageNum < 3 && strings.Contains(in.SelectType, "title") { // if iksk := util.HttpEs(in.KeyWords, "ik_smart", IC.DB.Es.Addr); iksk != "" { // t3 := time.Now() // iksk_temp := in.KeyWords // in.KeyWords = iksk // in.SelectType = "title" // //最多查两页数据 // in.PageSize = 2 * in.PageSize // _, secondList := util.GetBidSearchData(in) // //数据合并 去重 排序 // list = util.DelRepeatSearchData(list, secondList) // count = int64(len(list)) // switch { // case count > util.SearchPageSize: // count = MC.If(count > int64(util.SearchPageSize*2), int64(util.SearchPageSize*2), count).(int64) // list = list[:util.SearchPageSize] // if in.SplitKeywords != "" { // list = list[util.SearchPageSize:count] // } // case count <= util.SearchPageSize: // list = list[:count] // } // var kbool = map[string]bool{} // var karr = []string{} // for _, v := range strings.Split(fmt.Sprintf("%s+%s", iksk_temp, iksk), "+") { // if kbool[v] { // continue // } // karr = append(karr, v) // kbool[v] = true // } // //+&&& 作为二次搜索第二页数据请求的标识(临时处理) // res.KeyWords = strings.Join(karr, "+") + "+&&&" // logx.Info("3查询耗时:", time.Since(t3)) // } // } // limitCount := MC.If(in.UserType != "fType", int64(util.SearchPageSize*util.SearchMaxPageNum_PAYED), int64(util.SearchPageSize*util.SearchMaxPageNum)).(int64) // if count > limitCount { // count = limitCount // } // //是否收藏 // //util.MakeCollection(in.UserId, list) // res.TotalPage = MC.If(in.PageNum == 1, (count+int64(util.SearchPageSize)-1)/int64(util.SearchPageSize), res.TotalPage).(int64) // res.Count = count // res.List = list // } // logx.Info("关键词 -0- 查询耗时:", time.Since(t).Seconds()) //} else if in.Platform == "PC" { // //} logx.Info("关键词 -全部- 查询耗时:", time.Since(t).Seconds()) return &bxcore.SearchResp{ Data: res, ErrMsg: "", ErrCode: 0, }, nil }