Skip to content

Commit ea1fdd2

Browse files
authored
Merge pull request #171 from alibaba/fix_group_hot_recall
sort group hot recall items
2 parents 0e74e35 + d778783 commit ea1fdd2

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

module/user_group_hot_recall_featurestore_dao.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package module
22

33
import (
44
"fmt"
5-
"math/rand"
5+
"sort"
66
"strings"
77

88
"github.com/alibaba/pairec/v2/context"
@@ -78,14 +78,6 @@ func (d *UserGroupHotRecallFeatureStoreDao) ListItemsByUser(user *User, context
7878
return
7979
}
8080

81-
if len(itemIds) > d.recallCount {
82-
rand.Shuffle(len(itemIds)/2, func(i, j int) {
83-
itemIds[i], itemIds[j] = itemIds[j], itemIds[i]
84-
})
85-
86-
itemIds = itemIds[:d.recallCount]
87-
}
88-
8981
for _, id := range itemIds {
9082
strs := strings.Split(id, ":")
9183
if len(strs) == 1 {
@@ -117,6 +109,12 @@ func (d *UserGroupHotRecallFeatureStoreDao) ListItemsByUser(user *User, context
117109
}
118110
}
119111

112+
sort.Sort(sort.Reverse(ItemScoreSlice(ret)))
113+
114+
if d.recallCount > 0 && len(ret) > d.recallCount {
115+
return ret[:d.recallCount]
116+
}
117+
120118
return
121119
}
122120

module/user_group_hot_recall_hologres_dao.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package module
33
import (
44
"database/sql"
55
"fmt"
6-
"math/rand"
6+
"sort"
77
"strings"
88
"sync"
99

@@ -99,14 +99,6 @@ func (d *UserGroupHotRecallHologresDao) ListItemsByUser(user *User, context *con
9999
return
100100
}
101101

102-
if len(itemIds) > d.recallCount {
103-
rand.Shuffle(len(itemIds)/2, func(i, j int) {
104-
itemIds[i], itemIds[j] = itemIds[j], itemIds[i]
105-
})
106-
107-
itemIds = itemIds[:d.recallCount]
108-
}
109-
110102
for _, id := range itemIds {
111103
strs := strings.Split(id, ":")
112104
if len(strs) == 1 {
@@ -138,6 +130,12 @@ func (d *UserGroupHotRecallHologresDao) ListItemsByUser(user *User, context *con
138130
}
139131
}
140132

133+
sort.Sort(sort.Reverse(ItemScoreSlice(ret)))
134+
135+
if d.recallCount > 0 && len(ret) > d.recallCount {
136+
return ret[:d.recallCount]
137+
}
138+
141139
return
142140
}
143141

0 commit comments

Comments
 (0)