Skip to content

Commit 2b604ab

Browse files
bors[bot]bidoubiwa
andauthored
Merge #565
565: Fix ignored paginationTotalHits r=bidoubiwa a=bidoubiwa fixes: #562 Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 75f6239 + 86ecb6a commit 2b604ab

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/client/instant-meilisearch-client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ export function instantMeiliSearch(
3131
): InstantMeiliSearchInstance {
3232
// create search resolver with included cache
3333
const searchResolver = SearchResolver(SearchCache())
34-
34+
// paginationTotalHits can be 0 as it is a valid number
35+
const paginationTotalHits =
36+
options.paginationTotalHits != null ? options.paginationTotalHits : 200
3537
const context: Context = {
3638
primaryKey: options.primaryKey || undefined,
3739
placeholderSearch: options.placeholderSearch !== false, // true by default
38-
paginationTotalHits: options.paginationTotalHits || 200,
40+
paginationTotalHits,
3941
}
4042

4143
return {

tests/pagination.tests.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { instantMeiliSearch } from '../src'
12
import { searchClient, dataset, Movies } from './assets/utils'
23

34
describe('Pagination browser test', () => {
@@ -97,4 +98,55 @@ describe('Pagination browser test', () => {
9798
expect(hits.length).toBe(0)
9899
expect(hits).toEqual([])
99100
})
101+
102+
test('Test pagination total hits ', async () => {
103+
const customClient = instantMeiliSearch(
104+
'http://localhost:7700',
105+
'masterKey',
106+
{
107+
paginationTotalHits: 1,
108+
}
109+
)
110+
const response = await customClient.search<Movies>([
111+
{
112+
indexName: 'movies',
113+
},
114+
])
115+
const hits = response.results[0].hits
116+
expect(hits.length).toBe(1)
117+
})
118+
119+
test('Test zero pagination total hits ', async () => {
120+
const customClient = instantMeiliSearch(
121+
'http://localhost:7700',
122+
'masterKey',
123+
{
124+
paginationTotalHits: 0,
125+
}
126+
)
127+
const response = await customClient.search<Movies>([
128+
{
129+
indexName: 'movies',
130+
},
131+
])
132+
const hits = response.results[0].hits
133+
expect(hits.length).toBe(0)
134+
})
135+
136+
test('Test bigger pagination total hits than nbr hits', async () => {
137+
const customClient = instantMeiliSearch(
138+
'http://localhost:7700',
139+
'masterKey',
140+
{
141+
paginationTotalHits: 1000,
142+
}
143+
)
144+
const response = await customClient.search<Movies>([
145+
{
146+
indexName: 'movies',
147+
},
148+
])
149+
const hits = response.results[0].hits
150+
expect(hits.length).toBe(6)
151+
})
100152
})

0 commit comments

Comments
 (0)