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

feat(recommend): Add trending types and methods #1396

Merged
merged 9 commits into from
Mar 14, 2022

Conversation

SophieManley03
Copy link
Contributor

@SophieManley03 SophieManley03 commented Feb 25, 2022

What?

Prepare typing and methods for the new recommend model named trending.

Why?

We want to release trending model in beta on March, 10th. In order to have a successful release we would like to update the recommend library so that use can use trending with it.

How?

Here are the specs for trending. It will give a better idea of what is implemented in the search.

We have 3 types of trending:

  • trending items: Return trending items for a given index.
  • trending items for a facet: Return trending items given a facetName and a facetValue.
  • trending facet: Return trending facetValue given a facetName

We don't want to break the current implementation of recommend for our customers.

@@ -15,7 +15,7 @@ export type RecommendationsQuery = {
/**
* The `objectID` of the item to get recommendations for.
*/
readonly objectID: string;
readonly objectID?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to break the existing implementation for related-products and bought-together. So I put it optional but it is still mandatory for these models :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be required, but omitted from the new items then probably, as how facetName is omitted for fbt

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is omitted actually, how come it's still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem if I do that is with getRecommendations . getRecommendation is used for every get method of Recommend and the objectID will be mandatory even for trends

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we still remodel the code so that types are accurate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So after a third thought, I wanted to try to make it optional here but required for RP and FBT using Required in their own Query type.
I did that to be able to use getRecommendations for all models.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which bring me to a question after a discussion with @PLNech:
What is the purpose of getRecommendation? Does it make sense to make it retrieve recommendations for all kind of model? @francoischalifour maybe you'll know?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put differently: was getRecommendation a hack while we defined the actual model names before GA, or is it a feature designed to allow using not-yet-public new models?

  • If the former, then it might be time we drop this generic method (which brings subpar "common denominator" DX compared to specialized methods) and only implement Trending as a new, fully-typed method
  • If the latter, we'll need to find a generic implementation that is least disruptive to current users.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRecommendations() is useful for the situation we're in right now: users can already use the trending model, without it being officially supported with a method in the client.

We didn't have a team to maintain this Recommend client initially so we provided it as an "escape hatch" if we're not reactive to support new models in the client.

getRecommendations() was just the very initial implementation that satisfied us at the time, feel free to change it as you need. And if it's not helpful for the new model, don't feel like you need to use it. (In the future, we can also deprecate it.)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll ask the opposite question then: what's the purpose of having a specialized method for each model rather than just using getRecommendations()? It's basically a multi-query endpoint, and I think it has its uses (like making a single call to retrieve both trending items and trending facets for example). While calling getRelatedProducts() as a multi-query is strange IMO.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Feb 25, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit cfe8fc5:

Sandbox Source
algolia/create-instantsearch-app Configuration

jojva
jojva previously approved these changes Feb 25, 2022
Copy link

@jojva jojva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@@ -15,7 +15,7 @@ export type RecommendationsQuery = {
/**
* The `objectID` of the item to get recommendations for.
*/
readonly objectID: string;
readonly objectID?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be required, but omitted from the new items then probably, as how facetName is omitted for fbt

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

shortcuts
shortcuts previously approved these changes Mar 10, 2022
Copy link
Member

@shortcuts shortcuts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me!

Only one non-blocking comment if @francoischalifour have nothing agains it

@shortcuts shortcuts enabled auto-merge (squash) March 10, 2022 16:52
…earch-client-javascript into feat/recommend-trending
Copy link
Member

@PLNech PLNech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Let's see how it goes once implemented in @algolia/recommend 🙃

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

Comment on lines +1 to +2
export type RecommendModel = 'related-products' | 'bought-together' | TrendingModel;
export type TrendingModel = 'trending-items' | 'trending-facets';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type RecommendModel = 'related-products' | 'bought-together' | TrendingModel;
export type TrendingModel = 'trending-items' | 'trending-facets';
export type TrendingModel = 'trending-items' | 'trending-facets';
export type RecommendModel = 'related-products' | 'bought-together' | TrendingModel;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry D: #1399

@shortcuts shortcuts merged commit 6882ec8 into master Mar 14, 2022
@shortcuts shortcuts deleted the feat/recommend-trending branch March 14, 2022 11:02
@SophieManley03
Copy link
Contributor Author

Thank you all for the reviews 🙇‍♀️

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

Successfully merging this pull request may close these issues.

None yet

6 participants