From f65322d42229bc6dd8bef60d37c9cadf2d0a3764 Mon Sep 17 00:00:00 2001 From: Charlotte Vermandel Date: Wed, 15 Mar 2023 15:11:50 +0100 Subject: [PATCH] Add facetStats type in searchResponse for MS v1.1.0 --- src/types/types.ts | 1 + tests/search.test.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/types/types.ts b/src/types/types.ts index 25aa90c67..3063897ab 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -131,6 +131,7 @@ export type SearchResponse< processingTimeMs: number facetDistribution?: FacetDistribution query: string + facetStats?: Record } & (undefined extends S ? Partial : true extends IsFinitePagination> diff --git a/tests/search.test.ts b/tests/search.test.ts index 81cb6b320..fc7207c32 100644 --- a/tests/search.test.ts +++ b/tests/search.test.ts @@ -94,6 +94,7 @@ describe.each([ expect(response).toHaveProperty('offset', 0) expect(response).toHaveProperty('processingTimeMs', expect.any(Number)) expect(response).toHaveProperty('query', 'prince') + expect(response.facetStats).toBeUndefined() expect(response.hits.length).toEqual(2) // @ts-expect-error Not present in the SearchResponse type because neither `page` or `hitsPerPage` is provided in the search params. expect(response.hitsPerPage).toBeUndefined() @@ -453,12 +454,17 @@ describe.each([ const client = await getClient(permission) const response = await client.index(index.uid).search('a', { filter: ['genre = romance'], - facets: ['genre'], + facets: ['genre', 'id'], }) expect(response).toHaveProperty('facetDistribution', { genre: { romance: 2 }, + id: { '123': 1, '2': 1 }, }) + + expect(response).toHaveProperty('facetStats', { id: { min: 2, max: 123 } }) + expect(response.facetStats?.['id']?.min).toBe(2) + expect(response.facetStats?.['id']?.max).toBe(123) expect(response).toHaveProperty('hits', expect.any(Array)) expect(response.hits.length).toEqual(2) })