Skip to content

Total hits incorrect when using pagination backend #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Antsiscool opened this issue Apr 1, 2022 · 3 comments
Closed

Total hits incorrect when using pagination backend #138

Antsiscool opened this issue Apr 1, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@Antsiscool
Copy link

Description
When using a pagination backend, the total hits is capped at 200. I tried this with will_paginate, but it should also happen with kaminari.

When a pagination backend is set, the limit parameter is set to 200 with no option to override in MeiliSearch::Rails::ClassMethods#ms_search.
Later in the method total hits is calculated by total_hits = json['hits'].length. This is capped at 200 due to the limit set earlier.
total_hits should instead be set to the value of nbHits.

Expected behavior
When more than 200 documents match the search, the total hits count should be match the value returned.
What you expected to happen.

Current behavior
Currently the total number of hits is capped at 200.

Environment (please complete the following information):

  • meilisearch-rails version: 0.5.1
@brunoocasali brunoocasali added the bug Something isn't working label Apr 3, 2022
@brunoocasali
Copy link
Member

Hi @Antsiscool thanks for reporting this bug!

I'll be looking into it during this week, or if you want to, you can open a PR :)

@curquiza
Copy link
Member

curquiza commented Jun 2, 2022

Hello @Antsiscool sorry for the huge delay

This 200 fetch is currently expected to ensure we know the total number of matches, so know that total number of pages. Currently, there is no other way with Meilisearch (the core engine) to provide a "finite" pagination (e.g. being able to access another page other than the next one).

Here is some resources regarding this

We know some of our users would love to use efficient finite pagination with Meilisearch and that's why we are currently thinking about adding this feature in a future version. Once it's implemented, the issue you raise will be definitely fixed!

Thanks again for your report, and sorry for this!

@brunoocasali
Copy link
Member

brunoocasali commented Dec 15, 2022

Hey @Antsiscool, this issue is fixed in the new version of Meilisearch v0.30!

To use it, you must update your rails gem and your Meilisearch instance. If you use pagy you'll have to wait a little bit, because the finite pagination will only be available in the next major version.

Check this #214 for more info regarding the implementation of finite pagination.

Also: https://github.com/meilisearch/meilisearch-rails/releases/tag/v0.8.0
And https://github.com/meilisearch/meilisearch/releases/tag/v0.30.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants