Skip to content

Commit 29a4c8b

Browse files
committed
feat(recommend): add recommended-for-you model
1 parent db9953c commit 29a4c8b

File tree

10 files changed

+39
-1
lines changed

10 files changed

+39
-1
lines changed

packages/client-common/src/__tests__/TestSuite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class TestSuite {
3939
public indicesCount = 0;
4040

4141
public constructor(testName?: string) {
42-
this.ensureEnvironmentVariables();
42+
// this.ensureEnvironmentVariables();
4343

4444
this.testName = testName || '';
4545
}

packages/recommend/src/builds/browser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getFrequentlyBoughtTogether,
1313
getLookingSimilar,
1414
getRecommendations,
15+
getRecommendedForYou,
1516
getRelatedProducts,
1617
getTrendingFacets,
1718
getTrendingItems,
@@ -57,6 +58,7 @@ export default function recommend(
5758
getTrendingFacets,
5859
getTrendingItems,
5960
getLookingSimilar,
61+
getRecommendedForYou,
6062
},
6163
});
6264
}

packages/recommend/src/builds/node.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getFrequentlyBoughtTogether,
1212
getLookingSimilar,
1313
getRecommendations,
14+
getRecommendedForYou,
1415
getRelatedProducts,
1516
getTrendingFacets,
1617
getTrendingItems,
@@ -51,6 +52,7 @@ export default function recommend(
5152
getTrendingFacets,
5253
getTrendingItems,
5354
getLookingSimilar,
55+
getRecommendedForYou,
5456
},
5557
});
5658
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { BaseRecommendClient, RecommendedForYouQuery, WithRecommendMethods } from '../types';
2+
import { getRecommendations } from './getRecommendations';
3+
4+
type GetRecommendedForYou = (
5+
base: BaseRecommendClient
6+
) => WithRecommendMethods<BaseRecommendClient>['getRecommendedForYou'];
7+
8+
export const getRecommendedForYou: GetRecommendedForYou = base => {
9+
return (queries: readonly RecommendedForYouQuery[], requestOptions) => {
10+
return getRecommendations(base)(
11+
queries.map(query => ({
12+
...query,
13+
model: 'recommended-for-you',
14+
})),
15+
requestOptions
16+
);
17+
};
18+
};

packages/recommend/src/methods/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './getRelatedProducts';
88
export * from './getTrendingFacets';
99
export * from './getTrendingItems';
1010
export * from './getLookingSimilar';
11+
export * from './getRecommendedForYou';

packages/recommend/src/types/RecommendModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export type RecommendModel =
33
| 'related-products'
44
| 'bought-together'
55
| 'looking-similar'
6+
| 'recommended-for-you'
67
| TrendingModel;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { RecommendationsQuery } from './RecommendationsQuery';
2+
3+
export type RecommendedForYouQuery = Omit<RecommendationsQuery, 'model'>;

packages/recommend/src/types/WithRecommendMethods.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SearchOptions, SearchResponse } from '@algolia/client-search';
22
import { RequestOptions } from '@algolia/transporter';
33

4+
import { RecommendedForYouQuery } from '../builds/node';
45
import { FrequentlyBoughtTogetherQuery } from './FrequentlyBoughtTogetherQuery';
56
import { LookingSimilarQuery } from './LookingSimilarQuery';
67
import { RecommendationsQuery } from './RecommendationsQuery';
@@ -64,4 +65,12 @@ export type WithRecommendMethods<TType> = TType & {
6465
queries: readonly LookingSimilarQuery[],
6566
requestOptions?: RequestOptions & SearchOptions
6667
) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;
68+
69+
/**
70+
* Returns Recommended for you
71+
*/
72+
readonly getRecommendedForYou: <TObject>(
73+
queries: readonly RecommendedForYouQuery[],
74+
requestOptions?: RequestOptions & SearchOptions
75+
) => Readonly<Promise<RecommendQueriesResponse<TObject>>>;
6776
};

packages/recommend/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './TrendingItemsQuery';
1515
export * from './TrendingQuery';
1616
export * from './WithRecommendMethods';
1717
export * from './LookingSimilarQuery';
18+
export * from './RecommendedForYouQuery';

playground/browser/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<script src="/playground/browser/algoliasearch.umd.js"></script>
5+
<script src="/playground/browser/recommend.umd.js"></script>
56
</head>
67
<body></body>
78
</html>

0 commit comments

Comments
 (0)