diff --git a/docs/extras/meilisearch.md b/docs/extras/meilisearch.md index 2e3537313..2252e0ee5 100644 --- a/docs/extras/meilisearch.md +++ b/docs/extras/meilisearch.md @@ -64,7 +64,7 @@ Extend your model with the Pagy::Meilisearch` micro-moudule: extend Pagy::Meilisearch ``` -The `Pagy::ElasticsearchRails::Search` adds the `pagy_search` class method that you must use in place of the standard `search` method when you want to paginate the search response. +The `Pagy::Meilisearch` adds the `pagy_search` class method that you must use in place of the standard `search` method when you want to paginate the search response. ### pagy_search(...) diff --git a/lib/pagy/extras/meilisearch.rb b/lib/pagy/extras/meilisearch.rb index 66d5b53d8..e2bd15721 100644 --- a/lib/pagy/extras/meilisearch.rb +++ b/lib/pagy/extras/meilisearch.rb @@ -15,9 +15,9 @@ def pagy_meilisearch(term = nil, **vars) # create a Pagy object from a Meilisearch results def self.new_from_meilisearch(results, vars={}) - vars[:items] = results.raw_answer[:limit] - vars[:page] = [results.raw_answer[:offset] / vars[:items], 1].max - vars[:count] = results.raw_answer[:nbHits] + vars[:items] = results.raw_answer['limit'] + vars[:page] = [results.raw_answer['offset'] / vars[:items], 1].max + vars[:count] = results.raw_answer['nbHits'] new(vars) end @@ -32,7 +32,7 @@ def pagy_meilisearch(pagy_search_args, vars = {}) options[:limit] = vars[:items] options[:offset] = (vars[:page] - 1) * vars[:items] results = model.search(term, **options) - vars[:count] = results.raw_answer[:nbHits] + vars[:count] = results.raw_answer['nbHits'] pagy = Pagy.new(vars) # with :last_page overflow we need to re-run the method in order to get the hits diff --git a/test/mock_helpers/meilisearch.rb b/test/mock_helpers/meilisearch.rb index 8716411b7..45ea14e21 100644 --- a/test/mock_helpers/meilisearch.rb +++ b/test/mock_helpers/meilisearch.rb @@ -17,10 +17,10 @@ def initialize(query, params = {}) def raw_answer { - hits: self, - offset: @params[:offset], - limit: @params[:limit], - nbHits: RESULTS[@query].length + 'hits' => self, + 'offset' => @params[:offset], + 'limit' => @params[:limit], + 'nbHits' => RESULTS[@query].length } end end