Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
62 lines
1.5 KiB
Go
62 lines
1.5 KiB
Go
package searchser
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
"videoweb/app/api/proto"
|
|
"videoweb/app/service/configser"
|
|
"videoweb/app/service/translationser"
|
|
"videoweb/pub/pubdef"
|
|
|
|
"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
|
|
}
|