Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
},
{
"path": "packages/recommend/dist/recommend.umd.js",
"maxSize": "4.3KB"
"maxSize": "4.4KB"
}
]
}
2 changes: 2 additions & 0 deletions packages/recommend/src/builds/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
getFrequentlyBoughtTogether,
getLookingSimilar,
getRecommendations,
getRecommendedForYou,
getRelatedProducts,
getTrendingFacets,
getTrendingItems,
Expand Down Expand Up @@ -57,6 +58,7 @@ export default function recommend(
getTrendingFacets,
getTrendingItems,
getLookingSimilar,
getRecommendedForYou,
},
});
}
Expand Down
2 changes: 2 additions & 0 deletions packages/recommend/src/builds/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getFrequentlyBoughtTogether,
getLookingSimilar,
getRecommendations,
getRecommendedForYou,
getRelatedProducts,
getTrendingFacets,
getTrendingItems,
Expand Down Expand Up @@ -51,6 +52,7 @@ export default function recommend(
getTrendingFacets,
getTrendingItems,
getLookingSimilar,
getRecommendedForYou,
},
});
}
Expand Down
11 changes: 9 additions & 2 deletions packages/recommend/src/methods/getRecommendations.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { MethodEnum } from '@algolia/requester-common';

import { BaseRecommendClient, RecommendationsQuery, WithRecommendMethods } from '../types';
import {
BaseRecommendClient,
RecommendationsQuery,
RecommendedForYouQuery,
WithRecommendMethods,
} from '../types';
import { TrendingQuery } from '../types/TrendingQuery';

type GetRecommendations = (
Expand All @@ -9,7 +14,9 @@ type GetRecommendations = (

export const getRecommendations: GetRecommendations = base => {
return (queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>, requestOptions) => {
const requests: ReadonlyArray<RecommendationsQuery | TrendingQuery> = queries.map(query => ({
const requests: ReadonlyArray<
RecommendationsQuery | TrendingQuery | RecommendedForYouQuery
> = queries.map(query => ({
...query,
// The `threshold` param is required by the endpoint to make it easier
// to provide a default value later, so we default it in the client
Expand Down
29 changes: 29 additions & 0 deletions packages/recommend/src/methods/getRecommendedForYou.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { MethodEnum } from '@algolia/requester-common';

import { BaseRecommendClient, RecommendedForYouQuery, WithRecommendMethods } from '../types';

type GetRecommendedForYou = (
base: BaseRecommendClient
) => WithRecommendMethods<BaseRecommendClient>['getRecommendedForYou'];

export const getRecommendedForYou: GetRecommendedForYou = base => {
return (queries: readonly RecommendedForYouQuery[], requestOptions) => {
const requests: readonly RecommendedForYouQuery[] = queries.map(query => ({
...query,
model: 'recommended-for-you',
threshold: query.threshold || 0,
}));

return base.transporter.read(
{
method: MethodEnum.Post,
path: '1/indexes/*/recommendations',
data: {
requests,
},
cacheable: true,
},
requestOptions
);
};
};
1 change: 1 addition & 0 deletions packages/recommend/src/methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './getRelatedProducts';
export * from './getTrendingFacets';
export * from './getTrendingItems';
export * from './getLookingSimilar';
export * from './getRecommendedForYou';
1 change: 1 addition & 0 deletions packages/recommend/src/types/RecommendModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export type RecommendModel =
| 'related-products'
| 'bought-together'
| 'looking-similar'
| 'recommended-for-you'
| TrendingModel;
3 changes: 3 additions & 0 deletions packages/recommend/src/types/RecommendedForYouQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { RecommendationsQuery } from './RecommendationsQuery';

export type RecommendedForYouQuery = Omit<RecommendationsQuery, 'model' | 'objectID'>;
9 changes: 9 additions & 0 deletions packages/recommend/src/types/WithRecommendMethods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SearchOptions, SearchResponse } from '@algolia/client-search';
import { RequestOptions } from '@algolia/transporter';

import { RecommendedForYouQuery } from '../builds/node';
import { FrequentlyBoughtTogetherQuery } from './FrequentlyBoughtTogetherQuery';
import { LookingSimilarQuery } from './LookingSimilarQuery';
import { RecommendationsQuery } from './RecommendationsQuery';
Expand Down Expand Up @@ -72,4 +73,12 @@ export type WithRecommendMethods<TType> = TType & {
queries: readonly LookingSimilarQuery[],
requestOptions?: RequestOptions & SearchOptions
) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;

/**
* Returns Recommended for you
*/
readonly getRecommendedForYou: <TObject>(
queries: readonly RecommendedForYouQuery[],
requestOptions?: RequestOptions & SearchOptions
) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;
};
1 change: 1 addition & 0 deletions packages/recommend/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export * from './TrendingItemsQuery';
export * from './TrendingQuery';
export * from './WithRecommendMethods';
export * from './LookingSimilarQuery';
export * from './RecommendedForYouQuery';
export * from './TrendingFacetHit';
export * from './TrendingFacetsResponse';
1 change: 1 addition & 0 deletions playground/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<script src="/playground/browser/algoliasearch.umd.js"></script>
<script src="/playground/browser/recommend.umd.js"></script>
</head>
<body></body>
</html>
1 change: 1 addition & 0 deletions scripts/prepare-playground.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cp -a packages/algoliasearch/dist/algoliasearch-lite.umd* playground/browser-lite/.
cp -a packages/algoliasearch/dist/algoliasearch.umd* playground/browser/.
cp -a packages/recommend/dist/recommend.umd* playground/browser/.