From d57ad8f0ee08c00f6f8c417d2de1168832c57c9e Mon Sep 17 00:00:00 2001 From: Ana Maria Gabriela Lungu Date: Fri, 16 Dec 2022 17:01:25 +0100 Subject: [PATCH 1/2] fix: update trending facets query props --- .../src/methods/getRecommendations.ts | 8 +++- .../src/types/TrendingFacetsQuery.ts | 25 ++++++++-- .../recommend/src/types/TrendingItemsQuery.ts | 41 ++++++++++++++++- packages/recommend/src/types/TrendingQuery.ts | 46 ------------------- packages/recommend/src/types/index.ts | 1 - 5 files changed, 66 insertions(+), 55 deletions(-) delete mode 100644 packages/recommend/src/types/TrendingQuery.ts diff --git a/packages/recommend/src/methods/getRecommendations.ts b/packages/recommend/src/methods/getRecommendations.ts index 8fda3aa2a..c2b8c51a9 100644 --- a/packages/recommend/src/methods/getRecommendations.ts +++ b/packages/recommend/src/methods/getRecommendations.ts @@ -3,7 +3,9 @@ import { MethodEnum } from '@algolia/requester-common'; import { BaseRecommendClient, RecommendationsQuery, - TrendingQuery, + TrendingFacetsQuery, + TrendingItemsQuery, + TrendingModel, WithRecommendMethods, } from '../types'; @@ -11,6 +13,10 @@ type GetRecommendations = ( base: BaseRecommendClient ) => WithRecommendMethods['getRecommendations']; +type TrendingQuery = + | (TrendingItemsQuery & { readonly model: TrendingModel }) + | (TrendingFacetsQuery & { readonly model: TrendingModel }); + export const getRecommendations: GetRecommendations = base => { return (queries: ReadonlyArray, requestOptions) => { const requests: ReadonlyArray = queries.map(query => ({ diff --git a/packages/recommend/src/types/TrendingFacetsQuery.ts b/packages/recommend/src/types/TrendingFacetsQuery.ts index 6d58164dd..85c4f6855 100644 --- a/packages/recommend/src/types/TrendingFacetsQuery.ts +++ b/packages/recommend/src/types/TrendingFacetsQuery.ts @@ -1,6 +1,21 @@ -import { TrendingQuery } from './TrendingQuery'; +export type TrendingFacetsQuery = { + /** + * The name of the target index. + */ + readonly indexName: string; -export type TrendingFacetsQuery = Omit< - TrendingQuery, - 'model' | 'facetValue' | 'fallbackParameters' | 'queryParameters' ->; + /** + * Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned. + */ + readonly threshold?: number; + + /** + * How many recommendations to retrieve. + */ + readonly maxRecommendations?: number; + + /** + * Used for trending model + */ + readonly facetName: string; +}; diff --git a/packages/recommend/src/types/TrendingItemsQuery.ts b/packages/recommend/src/types/TrendingItemsQuery.ts index fe012604e..e851c68f5 100644 --- a/packages/recommend/src/types/TrendingItemsQuery.ts +++ b/packages/recommend/src/types/TrendingItemsQuery.ts @@ -1,3 +1,40 @@ -import { TrendingQuery } from './TrendingQuery'; +import { RecommendSearchOptions } from '@algolia/recommend'; -export type TrendingItemsQuery = Omit; +export type TrendingItemsQuery = { + /** + * The name of the target index. + */ + readonly indexName: string; + + /** + * Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned. + */ + readonly threshold?: number; + + /** + * How many recommendations to retrieve. + */ + readonly maxRecommendations?: number; + + /** + * List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send. + */ + readonly queryParameters?: RecommendSearchOptions; + + /** + * List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send. + * + * Additional filters to use as fallback when there aren’t enough recommendations. + */ + readonly fallbackParameters?: RecommendSearchOptions; + + /** + * Used for trending model + */ + readonly facetName?: string; + + /** + * Used for trending model + */ + readonly facetValue?: string; +}; diff --git a/packages/recommend/src/types/TrendingQuery.ts b/packages/recommend/src/types/TrendingQuery.ts deleted file mode 100644 index bce65655e..000000000 --- a/packages/recommend/src/types/TrendingQuery.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { TrendingModel } from './RecommendModel'; -import { RecommendSearchOptions } from './RecommendSearchOptions'; - -export type TrendingQuery = { - /** - * The name of the target index. - */ - readonly indexName: string; - - /** - * The name of the Recommendation model to use. - */ - readonly model: TrendingModel; - - /** - * Threshold for the recommendations confidence score (between 0 and 100). Only recommendations with a greater score are returned. - */ - readonly threshold?: number; - - /** - * How many recommendations to retrieve. - */ - readonly maxRecommendations?: number; - - /** - * List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send. - */ - readonly queryParameters?: RecommendSearchOptions; - - /** - * List of [search parameters](https://www.algolia.com/doc/api-reference/search-api-parameters/) to send. - * - * Additional filters to use as fallback when there aren’t enough recommendations. - */ - readonly fallbackParameters?: RecommendSearchOptions; - - /** - * Used for trending model - */ - readonly facetName?: string; - - /** - * Used for trending model - */ - readonly facetValue?: string; -}; diff --git a/packages/recommend/src/types/index.ts b/packages/recommend/src/types/index.ts index 19b2cd086..c5a779f30 100644 --- a/packages/recommend/src/types/index.ts +++ b/packages/recommend/src/types/index.ts @@ -11,6 +11,5 @@ export * from './RecommendSearchOptions'; export * from './RecommendationsQuery'; export * from './RelatedProductsQuery'; export * from './TrendingFacetsQuery'; -export * from './TrendingQuery'; export * from './TrendingItemsQuery'; export * from './WithRecommendMethods'; From 41fe1447e04a22db51e447da1063108899716566 Mon Sep 17 00:00:00 2001 From: Ana Maria Gabriela Lungu Date: Mon, 19 Dec 2022 16:08:37 +0100 Subject: [PATCH 2/2] fix: add more descriptive docs for parameters --- packages/recommend/src/types/TrendingFacetsQuery.ts | 2 +- packages/recommend/src/types/TrendingItemsQuery.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/recommend/src/types/TrendingFacetsQuery.ts b/packages/recommend/src/types/TrendingFacetsQuery.ts index 85c4f6855..399e9fb49 100644 --- a/packages/recommend/src/types/TrendingFacetsQuery.ts +++ b/packages/recommend/src/types/TrendingFacetsQuery.ts @@ -15,7 +15,7 @@ export type TrendingFacetsQuery = { readonly maxRecommendations?: number; /** - * Used for trending model + * The facet attribute to get recommendations for. */ readonly facetName: string; }; diff --git a/packages/recommend/src/types/TrendingItemsQuery.ts b/packages/recommend/src/types/TrendingItemsQuery.ts index e851c68f5..e04633187 100644 --- a/packages/recommend/src/types/TrendingItemsQuery.ts +++ b/packages/recommend/src/types/TrendingItemsQuery.ts @@ -29,12 +29,12 @@ export type TrendingItemsQuery = { readonly fallbackParameters?: RecommendSearchOptions; /** - * Used for trending model + * The facet attribute to get recommendations for. */ readonly facetName?: string; /** - * Used for trending model + * The value of the target facet. */ readonly facetValue?: string; };