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..399e9fb49 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; + + /** + * 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 fe012604e..e04633187 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; + + /** + * The facet attribute to get recommendations for. + */ + readonly facetName?: string; + + /** + * The value of the target facet. + */ + 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';