Skip to content

Commit 6a72b08

Browse files
authored
Add facetStats type in searchResponse for MS v1.1.0 (#1459)
1 parent 521b7cb commit 6a72b08

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export type SearchResponse<
135135
processingTimeMs: number
136136
facetDistribution?: FacetDistribution
137137
query: string
138+
facetStats?: Record<string, { min?: number; max?: number }>
138139
} & (undefined extends S
139140
? Partial<FinitePagination & InfinitePagination>
140141
: true extends IsFinitePagination<NonNullable<S>>

tests/search.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ describe.each([
147147
expect(response).toHaveProperty('offset', 0)
148148
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
149149
expect(response).toHaveProperty('query', 'prince')
150+
expect(response.facetStats).toBeUndefined()
150151
expect(response.hits.length).toEqual(2)
151152
// @ts-expect-error Not present in the SearchResponse type because neither `page` or `hitsPerPage` is provided in the search params.
152153
expect(response.hitsPerPage).toBeUndefined()
@@ -506,12 +507,17 @@ describe.each([
506507
const client = await getClient(permission)
507508
const response = await client.index(index.uid).search('a', {
508509
filter: ['genre = romance'],
509-
facets: ['genre'],
510+
facets: ['genre', 'id'],
510511
})
511512

512513
expect(response).toHaveProperty('facetDistribution', {
513514
genre: { romance: 2 },
515+
id: { '123': 1, '2': 1 },
514516
})
517+
518+
expect(response).toHaveProperty('facetStats', { id: { min: 2, max: 123 } })
519+
expect(response.facetStats?.['id']?.min).toBe(2)
520+
expect(response.facetStats?.['id']?.max).toBe(123)
515521
expect(response).toHaveProperty('hits', expect.any(Array))
516522
expect(response.hits.length).toEqual(2)
517523
})

0 commit comments

Comments
 (0)