来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83 项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet 测试目录 /server/hkdj_net,App/Web API 30331/30332 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
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
|
|
}
|