Skip to content

Commit

Permalink
Merge #1459
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
meili-bors[bot] and bidoubiwa authored Mar 15, 2023
2 parents 4e10856 + f65322d commit 017bc9b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export type SearchResponse<
processingTimeMs: number
facetDistribution?: FacetDistribution
query: string
facetStats?: Record<string, { min?: number; max?: number }>
} & (undefined extends S
? Partial<FinitePagination & InfinitePagination>
: true extends IsFinitePagination<NonNullable<S>>
Expand Down
8 changes: 7 additions & 1 deletion tests/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
})
Expand Down

0 comments on commit 017bc9b

Please sign in to comment.