Skip to content

Commit

Permalink
fix: get item latest with category url (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlongdev authored Mar 25, 2024
1 parent 8fa52f0 commit 3cfb6b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *GorseClient) GetItemLatest(ctx context.Context, userid string, n, offse
}

func (c *GorseClient) GetItemLatestWithCategory(ctx context.Context, userid, category string, n, offset int) ([]Score, error) {
return request[[]Score, any](ctx, c, "GET", c.entryPoint+fmt.Sprintf("/api/latest?user-id=%s&category=%s&n=%d&offset=%d", userid, category, n, offset), nil)
return request[[]Score, any](ctx, c, "GET", c.entryPoint+fmt.Sprintf("/api/latest/%s?user-id=%s&n=%d&offset=%d", category, userid, n, offset), nil)
}

func (c *GorseClient) GetItemPopular(ctx context.Context, userid string, n, offset int) ([]Score, error) {
Expand Down
28 changes: 18 additions & 10 deletions server/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,24 +594,32 @@ func (s *RestServer) searchDocuments(collection, subset, category string, isItem
}
userId = request.QueryParameter("user-id")

// Get the sorted list
items, err := s.CacheClient.SearchDocuments(ctx, collection, subset, []string{category}, offset, offset+n)
if err != nil {
InternalServerError(response, err)
return
}

// Remove read items
readItems := mapset.NewSet[string]()
if userId != "" {
feedback, err := s.DataClient.GetUserFeedback(ctx, userId, s.Config.Now())
if err != nil {
InternalServerError(response, err)
return
}
readItems := mapset.NewSet[string]()
for _, f := range feedback {
readItems.Add(f.ItemId)
}
}

end := offset + n
if end > 0 && readItems.Cardinality() > 0 {
end += readItems.Cardinality()
}

// Get the sorted list
items, err := s.CacheClient.SearchDocuments(ctx, collection, subset, []string{category}, offset, end)
if err != nil {
InternalServerError(response, err)
return
}

// Remove read items
if userId != "" {
prunedItems := make([]cache.Document, 0, len(items))
for _, item := range items {
if !readItems.Contains(item.Id) {
Expand Down Expand Up @@ -1088,7 +1096,7 @@ func (s *RestServer) sessionRecommend(request *restful.Request, response *restfu
return
}
// add unseen items
//similarItems = s.FilterOutHiddenScores(response, similarItems, "")
// similarItems = s.FilterOutHiddenScores(response, similarItems, "")
for _, item := range similarItems {
if !excludeSet.Contains(item.Id) {
candidates[item.Id] += item.Score
Expand Down

0 comments on commit 3cfb6b2

Please sign in to comment.