Skip to content

Commit 017bc9b

Browse files
Merge #1459
1459: Add facetStats type in searchResponse for MS v1.1.0 r=bidoubiwa a=bidoubiwa As per [the specification](meilisearch/specifications#224) SDK requirements: meilisearch/integration-guides#251 A new response field, `facetStats` is returned when `facets` is used in the search parameters. It contains the min max value of facets that contain numeric values. I added some test `@brunoocasali` to ensure my typing is correct Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 4e10856 + f65322d commit 017bc9b

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
@@ -131,6 +131,7 @@ export type SearchResponse<
131131
processingTimeMs: number
132132
facetDistribution?: FacetDistribution
133133
query: string
134+
facetStats?: Record<string, { min?: number; max?: number }>
134135
} & (undefined extends S
135136
? Partial<FinitePagination & InfinitePagination>
136137
: true extends IsFinitePagination<NonNullable<S>>

tests/search.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe.each([
9494
expect(response).toHaveProperty('offset', 0)
9595
expect(response).toHaveProperty('processingTimeMs', expect.any(Number))
9696
expect(response).toHaveProperty('query', 'prince')
97+
expect(response.facetStats).toBeUndefined()
9798
expect(response.hits.length).toEqual(2)
9899
// @ts-expect-error Not present in the SearchResponse type because neither `page` or `hitsPerPage` is provided in the search params.
99100
expect(response.hitsPerPage).toBeUndefined()
@@ -453,12 +454,17 @@ describe.each([
453454
const client = await getClient(permission)
454455
const response = await client.index(index.uid).search('a', {
455456
filter: ['genre = romance'],
456-
facets: ['genre'],
457+
facets: ['genre', 'id'],
457458
})
458459

459460
expect(response).toHaveProperty('facetDistribution', {
460461
genre: { romance: 2 },
462+
id: { '123': 1, '2': 1 },
461463
})
464+
465+
expect(response).toHaveProperty('facetStats', { id: { min: 2, max: 123 } })
466+
expect(response.facetStats?.['id']?.min).toBe(2)
467+
expect(response.facetStats?.['id']?.max).toBe(123)
462468
expect(response).toHaveProperty('hits', expect.any(Array))
463469
expect(response.hits.length).toEqual(2)
464470
})

0 commit comments

Comments
 (0)