Skip to content

Commit

Permalink
Add facetStats type in searchResponse for MS v1.1.0 (#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
bidoubiwa authored Mar 15, 2023
1 parent 521b7cb commit 6a72b08
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 @@ -135,6 +135,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 @@ -147,6 +147,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 @@ -506,12 +507,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 6a72b08

Please sign in to comment.