@meilisearch/instant-meilisearch
Version:
The search client to use Meilisearch with InstantSearch.
21 lines (18 loc) • 481 B
text/typescript
import type { MultiSearchResult } from '../../types'
export function adaptTotalHits(
searchResponse: MultiSearchResult<Record<string, any>>
): number {
const {
hitsPerPage = 0,
totalPages = 0,
estimatedTotalHits,
totalHits,
} = searchResponse
if (estimatedTotalHits != null) {
return estimatedTotalHits
} else if (totalHits != null) {
return totalHits
}
// Should not happen but safeguarding just in case
return hitsPerPage * totalPages
}