-
Notifications
You must be signed in to change notification settings - Fork 6
/
user_recall_service.go
47 lines (38 loc) · 1.11 KB
/
user_recall_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package service
import (
"fmt"
"github.com/alibaba/pairec/v2/context"
"github.com/alibaba/pairec/v2/log"
"github.com/alibaba/pairec/v2/module"
"github.com/alibaba/pairec/v2/service/hook"
"github.com/alibaba/pairec/v2/service/rank"
)
type UserRecallService struct {
RecommendService
recallService *RecallService
rankService *rank.RankService
}
func NewUserRecallService() *UserRecallService {
service := UserRecallService{
recallService: &RecallService{},
}
return &service
}
func (r *UserRecallService) Recommend(context *context.RecommendContext) []*module.Item {
userId := r.GetUID(context)
user := module.NewUserWithContext(userId, context)
items := r.recallService.GetItems(user, context)
// filter
items = r.Filter(user, items, context)
size := context.Size
if len(items) < size {
log.Info(fmt.Sprintf("requestId=%s\tmodule=recommend\tevent=filter\tmsg=length of items less than size\tcount=%d", context.RecommendId, len(items)))
return items
}
items = items[:size]
// asynchronous clean hook func
for _, hf := range hook.RecommendCleanHooks {
go hf(context, user, items)
}
return items
}