Skip to content

Commit a1d7636

Browse files
fix: reintroduce trendingQuery
1 parent 0d304e6 commit a1d7636

8 files changed

+63
-27
lines changed

packages/recommend/src/methods/getRecommendations.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { MethodEnum } from '@algolia/requester-common';
22

3-
import { BaseRecommendClient, RecommendationsQuery, WithRecommendMethods } from '../types';
3+
import {
4+
BaseRecommendClient,
5+
RecommendationsQuery,
6+
TrendingQuery,
7+
WithRecommendMethods,
8+
} from '../types';
49

510
type GetRecommendations = (
611
base: BaseRecommendClient
712
) => WithRecommendMethods<BaseRecommendClient>['getRecommendations'];
813

914
export const getRecommendations: GetRecommendations = base => {
10-
return (queries: readonly RecommendationsQuery[], requestOptions) => {
11-
const requests: readonly RecommendationsQuery[] = queries.map(query => ({
15+
return (queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>, requestOptions) => {
16+
const requests: ReadonlyArray<RecommendationsQuery | TrendingQuery> = queries.map(query => ({
1217
...query,
1318
// The `threshold` param is required by the endpoint to make it easier
1419
// to provide a default value later, so we default it in the client

packages/recommend/src/types/FrequentlyBoughtTogetherQuery.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ import { RecommendationsQuery } from './RecommendationsQuery';
22

33
export type FrequentlyBoughtTogetherQuery = Omit<
44
RecommendationsQuery,
5-
'model' | 'fallbackParameters' | 'facetName' | 'facetValue'
6-
> &
7-
Required<Pick<RecommendationsQuery, 'objectID'>>;
5+
'model' | 'fallbackParameters'
6+
>;

packages/recommend/src/types/RecommendationsQuery.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type RecommendationsQuery = {
1515
/**
1616
* The `objectID` of the item to get recommendations for.
1717
*/
18-
readonly objectID?: string;
18+
readonly objectID: string;
1919

2020
/**
2121
* Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.
@@ -38,14 +38,4 @@ export type RecommendationsQuery = {
3838
* Additional filters to use as fallback when there aren’t enough recommendations.
3939
*/
4040
readonly fallbackParameters?: RecommendSearchOptions;
41-
42-
/**
43-
* Used for trending model
44-
*/
45-
readonly facetName?: string;
46-
47-
/**
48-
* Used for trending model
49-
*/
50-
readonly facetValue?: string;
5141
};
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
import { RecommendationsQuery } from './RecommendationsQuery';
22

3-
export type RelatedProductsQuery = Omit<
4-
RecommendationsQuery,
5-
'model' | 'facetName' | 'facetValue'
6-
> &
7-
Required<Pick<RecommendationsQuery, 'objectID'>>;
3+
export type RelatedProductsQuery = Omit<RecommendationsQuery, 'model'>;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { RecommendationsQuery } from './RecommendationsQuery';
1+
import { TrendingQuery } from './TrendingQuery';
22

3-
export type TrendingFacetsQuery = Omit<RecommendationsQuery, 'model' | 'facetValue' | 'objectID'> &
4-
Required<Pick<RecommendationsQuery, 'facetName'>>;
3+
export type TrendingFacetsQuery = Omit<TrendingQuery, 'model' | 'facetValue' | 'objectID'>;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { RecommendationsQuery } from './RecommendationsQuery';
1+
import { TrendingQuery } from './TrendingQuery';
22

3-
export type TrendingItemsQuery = Omit<RecommendationsQuery, 'model' | 'objectID'>;
3+
export type TrendingItemsQuery = Omit<TrendingQuery, 'model' | 'objectID'>;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { TrendingModel } from './RecommendModel';
2+
import { RecommendSearchOptions } from './RecommendSearchOptions';
3+
4+
export type TrendingQuery = {
5+
/**
6+
* The name of the target index.
7+
*/
8+
readonly indexName: string;
9+
10+
/**
11+
* The name of the Recommendation model to use.
12+
*/
13+
readonly model: TrendingModel;
14+
15+
/**
16+
* Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.
17+
*/
18+
readonly threshold?: number;
19+
20+
/**
21+
* How many recommendations to retrieve.
22+
*/
23+
readonly maxRecommendations?: number;
24+
25+
/**
26+
* List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send.
27+
*/
28+
readonly queryParameters?: RecommendSearchOptions;
29+
30+
/**
31+
* List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send.
32+
*
33+
* Additional filters to use as fallback when there aren’t enough recommendations.
34+
*/
35+
readonly fallbackParameters?: RecommendSearchOptions;
36+
37+
/**
38+
* Used for trending model
39+
*/
40+
readonly facetName?: string;
41+
42+
/**
43+
* Used for trending model
44+
*/
45+
readonly facetValue?: string;
46+
};

packages/recommend/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ export * from './RecommendSearchOptions';
1111
export * from './RecommendationsQuery';
1212
export * from './RelatedProductsQuery';
1313
export * from './TrendingFacetsQuery';
14+
export * from './TrendingQuery';
1415
export * from './TrendingItemsQuery';
1516
export * from './WithRecommendMethods';

0 commit comments

Comments
 (0)