@@ -0,0 +1,40 @@
|
||||
package vidpcountsearcher
|
||||
|
||||
import "91porn-server/app/service/searcher"
|
||||
|
||||
type VideoRes = searcher.VideoRes
|
||||
|
||||
type RichVidRes = searcher.RichVidRes
|
||||
|
||||
type ResultType = int
|
||||
|
||||
const (
|
||||
Video ResultType = iota
|
||||
RichVido
|
||||
)
|
||||
|
||||
type Result struct {
|
||||
dat []VideoRes
|
||||
richDat []RichVidRes
|
||||
typ ResultType
|
||||
hasNext bool
|
||||
}
|
||||
|
||||
func (*Result) Types() searcher.ResultTypes {
|
||||
return searcher.VidPCountSearchResult
|
||||
}
|
||||
|
||||
func (r *Result) Data() interface{} {
|
||||
if r.typ == Video {
|
||||
return r.dat
|
||||
}
|
||||
return r.richDat
|
||||
}
|
||||
|
||||
func (r *Result) Count() int64 {
|
||||
return int64(len(r.dat))
|
||||
}
|
||||
|
||||
func (r *Result) HasNext() bool {
|
||||
return r.hasNext
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package vidpcountsearcher
|
||||
|
||||
import (
|
||||
"91porn-server/app/service/searcher"
|
||||
"91porn-server/models/v/vidmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type ObjectID = primitive.ObjectID
|
||||
|
||||
// VidPlayCountSearcher VidPlayCountSearcher
|
||||
type VidPlayCountSearcher struct {
|
||||
uid uint64
|
||||
typ ResultType
|
||||
}
|
||||
|
||||
// NewVidPlayCountSearcher NewVidPlayCountSearcher
|
||||
func NewVidPlayCountSearcher(uid uint64) searcher.Searcher {
|
||||
return &VidPlayCountSearcher{
|
||||
uid: uid,
|
||||
typ: Video,
|
||||
}
|
||||
}
|
||||
|
||||
// NewRichVidPlayCountSearcher NewRichVidPlayCountSearcher
|
||||
func NewRichVidPlayCountSearcher(uid uint64) searcher.Searcher {
|
||||
return &VidPlayCountSearcher{
|
||||
uid: uid,
|
||||
typ: RichVido,
|
||||
}
|
||||
}
|
||||
|
||||
// Search Search
|
||||
func (v *VidPlayCountSearcher) Search(unuse searcher.KeyWorder, opt searcher.Opter) (result searcher.Resulter, err error) {
|
||||
limitEx := opt.Limit() + 1
|
||||
vidList, err := vidmod.VIDListByFakePlayCount(opt.Skip(), limitEx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(vidList) == 0 {
|
||||
return &Result{
|
||||
typ: v.typ,
|
||||
dat: []VideoRes{},
|
||||
richDat: []RichVidRes{},
|
||||
}, nil
|
||||
}
|
||||
hasNext := false
|
||||
if len(vidList) > int(opt.Limit()) {
|
||||
hasNext = true
|
||||
vidList = vidList[:opt.Limit()]
|
||||
}
|
||||
if v.typ == Video {
|
||||
videoResList, err := searcher.GetVideoResList(v.uid, vidList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Result{
|
||||
dat: videoResList,
|
||||
typ: v.typ,
|
||||
hasNext: hasNext,
|
||||
}, nil
|
||||
}
|
||||
richVideoResList, err := searcher.GetRichVideoResList(v.uid, vidList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Result{
|
||||
richDat: richVideoResList,
|
||||
typ: v.typ,
|
||||
hasNext: hasNext,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user