You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
707: Introduce finitePagination setting: remove default fetch of 200 documents r=bidoubiwa a=bidoubiwa
Fixes: #569fixes: #521
## Previously
By default instant-meilisearch used to fetch 200 documents on every search request. This was needed to ensure we can provide a finite pagination when the user used the `pagination` widget (with the 1, 2, 3, at the bottom of the screen).
## Issue
This impacted the speed of the search considerably. Indeed meilisearch is designed to retrieve the most relevant documents, but not all the relevant documents. The more you ask, the more the search engine has to process. There is no difference regarding the search time between retrieving 6 or 7 documents, but between 6 and 200 documents to every request, the impact can be huge.
It also impacted users using the `infiniteHits` widget as well while it is not necessary for them. The `infiniteHits` settings does not need to showcase a start and an end to the pagination. It only has to enable the `show more` button whenever there are more hits after the current showcased ones.
## New behavior
This PR introduces a new parameter: `finitePagination`.
`finitePagination` has a default value of `false`, when set to false, each search requests a limit: `(hitsPerPage + 1) * (page + 1)`
- [hitsPerPage](https://github.com/meilisearch/instant-meilisearch#-hitsperpage) (parameter of `instantsearch` and default to `6`) is the number of results on each page, or added on the current page on each `show more` click in case of infiniteHits. In the case if infiniteHits, we need to be able to know if there are more hits to come to enable or disable the `show more` button. Thus we add `1` to `hitsPerPage` so that if Meilisearch returns `hitsPerPage + 1` documents we know it has more.
- page: behind the scene value tracking the current page the user is on. For example `1` if you clicked once on `load more`. Because it starts at `0`, we add `+1` for the multiplication.
The pagination will stop at `paginationTotalHits` (default 200).
When settings `finitePagination` to `true`, one search request will ask for a limit of `paginationTotalHits` as limit. Thus in the default case, one search request will return `200` documents.
This number can be changed with `paginationTotalHits`
The following will make one request of `7` documents as `hitsPerPage` is at 6 by default.
```js
instantMeiliSearch(host, key, {
finitePagination: false // default false
paginationTotalHits: 60 // default 200
})
```
You can [change hitsPerPage](https://github.com/meilisearch/instant-meilisearch#-hitsperpage).
The following will make one request of 200 documents
```js
instantMeiliSearch(host, key, {
finitePagination: true // default false
paginationTotalHits: 60 // default 200
})
```
Co-authored-by: Charlotte Vermandel <[email protected]>
-[`placeholderSearch`](#placeholder-search): Enable or disable placeholder search (default: `true`).
82
82
-[`paginationTotalHits`](#pagination-total-hits): Maximum total number of hits to create a finite pagination (default: `200`).
83
+
-[`finitePagination`](#finite-pagination): Used to work with the [`pagination`](#-pagination) widget (default: `false`) .
83
84
-[`primaryKey`](#primary-key): Specify the primary key of your documents (default `undefined`).
84
85
-[`keepZeroFacets`](#keep-zero-facets): Show the facets value even when they have 0 matches (default `false`).
85
86
@@ -111,17 +112,31 @@ When placeholder search is set to `false`, no results appears when searching on
111
112
112
113
### Pagination total hits
113
114
114
-
The total (and finite) number of hits you can browse during pagination when using the [pagination widget](https://www.algolia.com/doc/api-reference/widgets/pagination/js/). If the pagination widget is not used, `paginationTotalHits` is ignored.<br>
115
+
The total (and finite) number of hits (default: `200`) you can browse during pagination when using the [pagination widget](https://www.algolia.com/doc/api-reference/widgets/pagination/js/) or the [`infiniteHits` widget](#-infinitehits). If none of these widgets are used, `paginationTotalHits` is ignored.<br>
115
116
116
-
Which means that, with a `paginationTotalHits`default value of 200, and `hitsPerPage` default value of 20, you can browse `paginationTotalHits / hitsPerPage` => `200 / 20 = 10` pages during pagination. Each of the 10 pages containing 20 results.<br>
117
+
For example, using the `infiniteHits` widget, and a `paginationTotalHits`of 9. On the first search request 6 hits are shown, by clicking a second time on `load more` only 3 more hits are added. This is because `paginationTotalHits` is `9`.
117
118
118
-
The default value of `hitsPerPage` is set to `20` but it can be changed with [`InsantSearch.configure`](https://www.algolia.com/doc/api-reference/widgets/configure/js/#examples).<br>
119
+
Usage:
119
120
120
121
```js
121
-
{ paginationTotalHits:20 } // default: 200
122
+
{ paginationTotalHits:50 } // default: 200
122
123
```
123
124
124
-
⚠️ Meilisearch is not designed for pagination and this can lead to performances issues, so the usage of the pagination widget is not encouraged. However, the `paginationTotalHits` parameter lets you implement this pagination with less performance issue as possible: depending on your dataset (the size of each document and the number of documents) you might decrease the value of `paginationTotalHits`.<br>
125
+
`hitsPerPage` has a value of `6` by default and can [be customized](#-hitsperpage).
126
+
127
+
### Finite Pagination
128
+
129
+
Finite pagination is used when you want to add a numbered pagination at the bottom of your hits (for example: `< << 1, 2, 3 > >>`).
130
+
To be able to know the amount of page numbers you have, a search is done requesting `paginationTotalHits` documents (default: `200`).
131
+
With the amount of documents returned, instantsearch is able to render the correct amount of numbers in the pagination widget.
132
+
133
+
Example:
134
+
135
+
```js
136
+
{ finitePagination:true } // default: false
137
+
```
138
+
139
+
⚠️ Meilisearch is not designed for pagination and this can lead to performances issues, so the usage `finitePagination` but also of the pagination widgets are not recommended.<br>
125
140
More information about Meilisearch and the pagination [here](https://github.com/meilisearch/documentation/issues/561).
searchContext.hitsPerPage===undefined ? 20 : searchContext.hitsPerPage,// 20 is the Meilisearch's default limit value. `hitsPerPage` can be changed with `InsantSearch.configure`.
37
-
page: searchContext?.page||0,// default page is 0 if none is provided
0 commit comments