Skip to content

Commit

Permalink
Fixes for Meilisearch extra (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
molfar authored Jun 24, 2021
1 parent 755c9f1 commit ec748c2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
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

0 comments on commit ec748c2

Please sign in to comment.