From 81e34277c4c222a0053e3ffea30b06bc51df6690 Mon Sep 17 00:00:00 2001 From: Molfar Date: Wed, 23 Jun 2021 16:31:39 +0300 Subject: [PATCH 1/2] Fix Meilisearch raw response format --- lib/pagy/extras/meilisearch.rb | 8 ++++---- test/mock_helpers/meilisearch.rb | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) 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 From b48c8f624f040136b45293c82ab1d7c8d106d68b Mon Sep 17 00:00:00 2001 From: Molfar Date: Wed, 23 Jun 2021 16:31:48 +0300 Subject: [PATCH 2/2] Fix Meilisearch extra docs typo --- docs/extras/meilisearch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(...)