Skip to content

Commit 913443f

Browse files
authored
fix(recommend): update trending facets query props (RECO-1184) (#1434)
* fix: update trending facets query props * fix: add more descriptive docs for parameters
1 parent ffbfc05 commit 913443f

File tree

5 files changed

+66
-55
lines changed

5 files changed

+66
-55
lines changed

packages/recommend/src/methods/getRecommendations.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ import { MethodEnum } from '@algolia/requester-common';
33
import {
44
BaseRecommendClient,
55
RecommendationsQuery,
6-
TrendingQuery,
6+
TrendingFacetsQuery,
7+
TrendingItemsQuery,
8+
TrendingModel,
79
WithRecommendMethods,
810
} from '../types';
911

1012
type GetRecommendations = (
1113
base: BaseRecommendClient
1214
) => WithRecommendMethods<BaseRecommendClient>['getRecommendations'];
1315

16+
type TrendingQuery =
17+
| (TrendingItemsQuery & { readonly model: TrendingModel })
18+
| (TrendingFacetsQuery & { readonly model: TrendingModel });
19+
1420
export const getRecommendations: GetRecommendations = base => {
1521
return (queries: ReadonlyArray<RecommendationsQuery | TrendingQuery>, requestOptions) => {
1622
const requests: ReadonlyArray<RecommendationsQuery | TrendingQuery> = queries.map(query => ({
Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
import { TrendingQuery } from './TrendingQuery';
1+
export type TrendingFacetsQuery = {
2+
/**
3+
* The name of the target index.
4+
*/
5+
readonly indexName: string;
26

3-
export type TrendingFacetsQuery = Omit<
4-
TrendingQuery,
5-
'model' | 'facetValue' | 'fallbackParameters' | 'queryParameters'
6-
>;
7+
/**
8+
* Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.
9+
*/
10+
readonly threshold?: number;
11+
12+
/**
13+
* How many recommendations to retrieve.
14+
*/
15+
readonly maxRecommendations?: number;
16+
17+
/**
18+
* The facet attribute to get recommendations for.
19+
*/
20+
readonly facetName: string;
21+
};
Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1-
import { TrendingQuery } from './TrendingQuery';
1+
import { RecommendSearchOptions } from '@algolia/recommend';
22

3-
export type TrendingItemsQuery = Omit<TrendingQuery, 'model'>;
3+
export type TrendingItemsQuery = {
4+
/**
5+
* The name of the target index.
6+
*/
7+
readonly indexName: string;
8+
9+
/**
10+
* Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned.
11+
*/
12+
readonly threshold?: number;
13+
14+
/**
15+
* How many recommendations to retrieve.
16+
*/
17+
readonly maxRecommendations?: number;
18+
19+
/**
20+
* List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send.
21+
*/
22+
readonly queryParameters?: RecommendSearchOptions;
23+
24+
/**
25+
* List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send.
26+
*
27+
* Additional filters to use as fallback when there aren’t enough recommendations.
28+
*/
29+
readonly fallbackParameters?: RecommendSearchOptions;
30+
31+
/**
32+
* The facet attribute to get recommendations for.
33+
*/
34+
readonly facetName?: string;
35+
36+
/**
37+
* The value of the target facet.
38+
*/
39+
readonly facetValue?: string;
40+
};

packages/recommend/src/types/TrendingQuery.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

packages/recommend/src/types/index.ts

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

0 commit comments

Comments
 (0)