Skip to content
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

Fixes for Meilisearch extra #318

Merged
merged 2 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/extras/meilisearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(...)

Expand Down
8 changes: 4 additions & 4 deletions lib/pagy/extras/meilisearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/mock_helpers/meilisearch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down