Skip to content

Pagination with hits_per_page to limit per page but got error #183

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
mech opened this issue Aug 13, 2022 · 7 comments · Fixed by #184
Closed

Pagination with hits_per_page to limit per page but got error #183

mech opened this issue Aug 13, 2022 · 7 comments · Fixed by #184
Assignees
Labels
bug Something isn't working

Comments

@mech
Copy link

mech commented Aug 13, 2022

I am trying to limit the pagination using hits_per_page with Kaminari:

Candidate.search("", page: 1, hits_per_page: 5, sort: ["name:asc"])

But was given this error:

MeiliSearch::ApiError: 400 Bad Request - Json deserialize error: unknown field `hitsPerPage`, expected one of `q`, `offset`, `limit`, `attributesToRetrieve`, `attributesToCrop`, `cropLength`, `attributesToHighlight`, `showMatchesPosition`, `filter`, `sort`, `facets`, `highlightPreTag`, `highlightPostTag`, `cropMarker` at line 1 column 21. See https://docs.meilisearch.com/errors#bad_request.

Removing the hits_per_page and I got back the first 20 records of the first page.

I even replace it with limit, but no luck:

# Replacing to limit don't work also
Candidate.search("", page: 1, limit: 5, sort: ["name:asc"])

Is there any special options we are not aware of? Or is pagination not working and need to wait for v0.29

  • OS: macOS 12.5
  • Meilisearch server version: v0.28.1
  • meilisearch-rails version: v0.7.1
  • Rails version: v7.0.3.1
@brunoocasali
Copy link
Member

Hi @mech I found what happened, I'll provide a fix soon!

@brunoocasali
Copy link
Member

@mech I created a branch with the fix, I need to have my PR approved to release a new version.

So while I wait for the approval, you have some options:

  • You can reference this branch directly in your Gemfile
  • You can change from hits_per_page to hitsPerPage

Thanks for using Meilisearch ❤️

@mech
Copy link
Author

mech commented Aug 18, 2022

Wow tks, hitsPerPage does work. I will use this temporarily.

@brunoocasali
Copy link
Member

It will be released soon as 0.7.2!

@mech
Copy link
Author

mech commented Aug 19, 2022

I am puzzle, when I do a search, it appear it is querying all 200 records no matter which page I am on.

Doing Candidate.ms_search("", page: 2, hitsPerPage: 3) will result in such SQL:

SELECT * FROM "candidates" WHERE id IN ($1, $2, ...... $200)

Is this normal?

@brunoocasali
Copy link
Member

brunoocasali commented Aug 19, 2022

Yes, it is normal because Meilisearch does not provide a way to know the total hits yet.
@curquiza explained this here: #138 (comment)

It is something we plan to improve in the future, in fact, we already have a prototype for this meilisearch/meilisearch#2635 feel free to give your thoughts there :)

@mech
Copy link
Author

mech commented Aug 19, 2022

Tks for clarification, will play with the new prototype 👍

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

Successfully merging a pull request may close this issue.

2 participants