README.md in meilisearch-rails-0.7.3 vs README.md in meilisearch-rails-0.8.0

- old
+ new

@@ -21,22 +21,24 @@ <p align="center">⚡ The Meilisearch integration for Ruby on Rails 💎</p> **Meilisearch Rails** is the Meilisearch integration for Ruby on Rails developers. -**Meilisearch** is an open-source search engine. [Discover what Meilisearch is!](https://github.com/meilisearch/meilisearch) +**Meilisearch** is an open-source search engine. [Learn more about Meilisearch.](https://github.com/meilisearch/meilisearch) ## Table of Contents <!-- omit in toc --> - [📖 Documentation](#-documentation) - [🤖 Compatibility with Meilisearch](#-compatibility-with-meilisearch) -- [🚀 Getting Started](#-getting-started) +- [🚀 Getting started](#-getting-started) - [Compatibility](#-compatibility) - [⚙️ Settings](#️-settings) - [🔍 Custom search](#-custom-search) - [🪛 Options](#-options) - [Meilisearch configuration & environment](#meilisearch-configuration--environment) + - [Pagination with `kaminari` or `will_paginate`](#backend-pagination-with-kaminari-or-will_paginate-) + - [Pagination with `pagy`](#backend-pagination-with-pagy-) - [Index configuration](#index-configuration) - [Custom attribute definition](#custom-attribute-definition) - [Custom primary key](#custom-primary-key) - [Conditional indexing](#conditional-indexing) - [Share a single index](#share-a-single-index) @@ -58,11 +60,11 @@ To learn more about Meilisearch, check out our [Documentation](https://docs.meilisearch.com/learn/tutorials/getting_started.html) or our [API References](https://docs.meilisearch.com/reference/api/). ## 🤖 Compatibility with Meilisearch -This package only guarantees the compatibility with the [version v0.28.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.28.0). +This package only guarantees the compatibility with the [version v0.30.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.30.0). ## 🔧 Installation <!-- omit in toc --> This package requires Ruby version 2.6.0 or later and Rails 5.2 or later. @@ -89,19 +91,19 @@ docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey ``` NB: you can also download Meilisearch from **Homebrew** or **APT**. -## 🚀 Getting Started +## 🚀 Getting started #### Configuration <!-- omit in toc --> Create a new file `config/initializers/meilisearch.rb` to setup your `MEILISEARCH_HOST` and `MEILISEARCH_API_KEY` ```ruby MeiliSearch::Rails.configuration = { - meilisearch_host: 'YourMeilisearchHost', # example: http://localhost:7700 + meilisearch_url: 'YourMeilisearchUrl', # example: http://localhost:7700 meilisearch_api_key: 'YourMeilisearchAPIKey', } ``` The gem is compatible with [ActiveRecord](https://github.com/rails/rails/tree/master/activerecord), [Mongoid](https://github.com/mongoid/mongoid) and [Sequel](https://github.com/jeremyevans/sequel). @@ -136,58 +138,18 @@ puts hit.title puts hit.author end ``` -#### Backend Pagination <!-- omit in toc --> - -This gem supports: -- [kaminari](https://github.com/amatsuda/kaminari) -- [pagy](https://github.com/ddnexus/pagy) -- [will_paginate](https://github.com/mislav/will_paginate). - -Specify the `:pagination_backend` in the configuration file: - -```ruby -MeiliSearch::Rails.configuration = { - meilisearch_host: 'YourMeilisearchHost', - meilisearch_api_key: 'YourMeilisearchAPIKey', - pagination_backend: :kaminari #:will_paginate -} -``` - -Then, as soon as you use the `search` method, the returning results will be paginated: - -```ruby -# controller -@hits = Book.search('harry potter') - -# views -<% @hits.each do |hit| %> - <%= hit.title %> - <%= hit.author %> -<% end %> - -<%= paginate @hits %> # if using kaminari - -<%= will_paginate @hits %> # if using will_paginate -``` - -The **number of hits per page defaults to 20**, you can customize it by adding the `hits_per_page` parameter to your search: - -```ruby -Book.search('harry potter', hits_per_page: 10) -``` - #### Extra Configuration <!-- omit in toc --> Requests made to Meilisearch may timeout and retry. To adapt the behavior to your needs, you can change the parameters during configuration: ```ruby MeiliSearch::Rails.configuration = { - meilisearch_host: 'YourMeilisearchHost', + meilisearch_url: 'YourMeilisearchUrl', meilisearch_api_key: 'YourMeilisearchAPIKey', timeout: 2, max_retries: 1, } ``` @@ -221,10 +183,11 @@ # The following parameters are applied when calling the search() method: attributes_to_highlight ['*'] attributes_to_crop [:description] crop_length 10 + pagination max_total_hits: 1000 end end ``` Check the dedicated section of the documentation, for more information on the [settings](https://docs.meilisearch.com/reference/features/settings.html). @@ -252,20 +215,103 @@ ## 🪛 Options ### Meilisearch configuration & environment +### Backend Pagination with `kaminari` or `will_paginate` <!-- omit in toc --> + +This gem supports: +- [kaminari](https://github.com/amatsuda/kaminari) +- [will_paginate](https://github.com/mislav/will_paginate) + +Specify the `:pagination_backend` in the configuration file: + +```ruby +MeiliSearch::Rails.configuration = { + meilisearch_url: 'YourMeilisearchUrl', + meilisearch_api_key: 'YourMeilisearchAPIKey', + pagination_backend: :kaminari # :will_paginate +} +``` + +Then, as soon as you use the `search` method, the returning results will be paginated: + +```ruby +# controller +@hits = Book.search('harry potter') + +# views +<% @hits.each do |hit| %> + <%= hit.title %> + <%= hit.author %> +<% end %> + +<%= paginate @hits %> # if using kaminari + +<%= will_paginate @hits %> # if using will_paginate +``` + +The **number of hits per page defaults to 20**, you can customize it by adding the `hits_per_page` parameter to your search: + +```ruby +Book.search('harry potter', hits_per_page: 10) +``` + +### Backend Pagination with `pagy` <!-- omit in toc --> + +This gem supports [pagy](https://github.com/ddnexus/pagy) to paginate your search results. + +To use `pagy` with your `meilisearch-rails` you need to: + +Add the `pagy` gem to your Gemfile. +Create a new initializer `pagy.rb` with this: + +```rb +# config/initializers/pagy.rb + +require 'pagy/extras/meilisearch' +``` + +Then in your model you must extend `Pagy::Meilisearch`: + +```rb +class Book < ApplicationRecord + include MeiliSearch::Rails + extend Pagy::Meilisearch + + meilisearch # ... +end +``` + +And in your controller and view: + +```rb +# controllers/books_controller.rb +def search + hits = Book.pagy_search(params[:query]) + @pagy, @hits = pagy_meilisearch(hits, items: 25) +end + + +# views/books/search.html.rb +<%== pagy_nav(@pagy) %> +``` + +:warning: There is no need to set `pagination_backend` in the configuration block `MeiliSearch::Rails.configuration` for `pagy`. + +Check [`ddnexus/pagy`](https://ddnexus.github.io/pagy/extras/meilisearch) for more information. + #### Deactivate Meilisearch in certain moments By default HTTP connections to the Meilisearch URL is always active, but sometimes you want to disable the HTTP requests in a particular moment or environment.<br> you have multiple ways to achieve this. By adding `active: false` in the configuration initializer: ```ruby MeiliSearch::Rails.configuration = { - meilisearch_host: 'YourMeilisearchHost', + meilisearch_url: 'YourMeilisearchUrl', meilisearch_api_key: 'YourMeilisearchAPIKey', active: false } ``` @@ -306,10 +352,10 @@ You can suffix the index UID with the current Rails environment by setting it globally: ```ruby MeiliSearch::Rails.configuration = { - meilisearch_host: 'YourMeilisearchHost', + meilisearch_url: 'YourMeilisearchUrl', meilisearch_api_key: 'YourMeilisearchAPIKey', per_environment: true } ```