Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match JS library - Fetch Recommendations Using an Array of Object ID's #836

Open
jgallantgs opened this issue Sep 11, 2023 · 0 comments
Open

Comments

@jgallantgs
Copy link

Is your feature request related to a problem? Please describe 🙏

We have an array of ObjectIds ( a cart of items ), for which we would like to get recommended/related products for. We can only provide a single object Id to FrequentlyBoughtTogetherOptions/RelatedProductsOptions, which means we need to generate an array of these. The result is that we get multiple arrays of items, which have no context of each other:

  @discardableResult func getFrequentlyBoughtTogether(options: [FrequentlyBoughtTogetherOptions],
                                                      requestOptions: RequestOptions? = nil,
                                                      completion: @escaping ResultCallback<SearchesResponse>) -> Operation {
    return getRecommendations(options: options.map(\.recommendationsOptions),
                              requestOptions: requestOptions,
                              completion: completion)
  }

Describe the solution you'd like 🤔
Looking in your javascript library, we noticed this solution has already been implemented:

https://github.com/algolia/recommend/blob/cfaf111b592e102f851f2216336a2fe566b2b6c2/packages/recommend-core/src/getRecommendations.ts#L4
https://github.com/algolia/recommend/blob/next/packages/recommend-core/src/utils/mapToRecommendations.ts
https://github.com/algolia/recommend/blob/cfaf111b592e102f851f2216336a2fe566b2b6c2/packages/recommend-core/src/utils/computeAverageIndices.ts#L4

You can provide a list of object id's, it fetches the arrays, and based off the index positions in each array and the number of object occurrences, it weighs, sorts, and filters the objects then returns them into a single array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant