package searchser import ( "context" "hkdj-web-server/app/api/proto" "hkdj-web-server/app/service/configser" "hkdj-web-server/app/service/translationser" "hkdj-web-server/pub/pubdef" "time" "github.com/patrickmn/go-cache" ) var ( Cache *cache.Cache ) func init() { Cache = cache.New(5*time.Minute, 5*time.Minute) } func Search(ctx context.Context, title string, mediaType int64, page int64, sort string) *proto.SearchResp { resp := &proto.SearchResp{ TotalSize: 0, Sort: make([]proto.SearchSortItem, 0), SearchRecommend: make([]string, 0), PageNum: page, PageSize: pubdef.PageSize, } resp.InTitle = title resp.InType = mediaType resp.Sort = getSearchSort() resp.SearchRecommend = getSearchRecommend(title) resp.Config = configser.GetConfigInfo() resp.Translations = translationser.GetTranslationData() resp.BottonTranslations = translationser.GetTranslationBottomList() resp.TotalSize = pubdef.GetTotalPage(resp.TotalSize, pubdef.PageSize) return resp } func getSearchRecommend(title string) []string { return make([]string, 0) } func getSearchSort() []proto.SearchSortItem { resp := make([]proto.SearchSortItem, 0) resp = append(resp, proto.SearchSortItem{ Key: string(proto.SearchSortTypeDefault), Title: "相关度", }) resp = append(resp, proto.SearchSortItem{ Key: string(proto.SearchSortTypeHot), Title: "热度最高", }) resp = append(resp, proto.SearchSortItem{ Key: string(proto.SearchSortTypeNew), Title: "最新发布", }) return resp }