@@ -98,7 +98,7 @@ gem 'meilisearch-rails'
98
98
Create a new file ` config/initializers/meilisearch.rb ` to setup your ` MEILISEARCH_HOST ` and ` MEILISEARCH_API_KEY `
99
99
100
100
``` ruby
101
- MeiliSearch ::Rails .configuration = {
101
+ Meilisearch ::Rails .configuration = {
102
102
meilisearch_url: ENV .fetch(' MEILISEARCH_HOST' , ' http://localhost:7700' ),
103
103
meilisearch_api_key: ENV .fetch(' MEILISEARCH_API_KEY' , ' YourMeilisearchAPIKey' )
104
104
}
@@ -120,7 +120,7 @@ The following code will create a `Book` index and add search capabilities to you
120
120
121
121
``` ruby
122
122
class Book < ActiveRecord ::Base
123
- include MeiliSearch ::Rails
123
+ include Meilisearch ::Rails
124
124
125
125
meilisearch do
126
126
attribute :title , :author # only the attributes 'title', and 'author' will be sent to Meilisearch
@@ -154,7 +154,7 @@ Requests made to Meilisearch may timeout and retry. To adapt the behavior to
154
154
your needs, you can change the parameters during configuration:
155
155
156
156
``` ruby
157
- MeiliSearch ::Rails .configuration = {
157
+ Meilisearch ::Rails .configuration = {
158
158
meilisearch_url: ' YourMeilisearchUrl' ,
159
159
meilisearch_api_key: ' YourMeilisearchAPIKey' ,
160
160
timeout: 2 ,
@@ -172,7 +172,7 @@ You can configure the index settings by adding them inside the `meilisearch` blo
172
172
173
173
``` ruby
174
174
class Book < ApplicationRecord
175
- include MeiliSearch ::Rails
175
+ include Meilisearch ::Rails
176
176
177
177
meilisearch do
178
178
searchable_attributes [:title , :author , :publisher , :description ]
@@ -235,7 +235,7 @@ Book.search('*', sort: ['title:asc'])
235
235
Meilisearch supports searching multiple models at the same time (see [ 🔍 Custom search] ( #-custom-search ) for search options):
236
236
237
237
``` ruby
238
- multi_search_results = MeiliSearch ::Rails .multi_search(
238
+ multi_search_results = Meilisearch ::Rails .multi_search(
239
239
Book => { q: ' Harry' },
240
240
Manga => { q: ' Attack' }
241
241
)
@@ -295,7 +295,7 @@ This gem supports:
295
295
Specify the ` :pagination_backend ` in the configuration file:
296
296
297
297
``` ruby
298
- MeiliSearch ::Rails .configuration = {
298
+ Meilisearch ::Rails .configuration = {
299
299
meilisearch_url: ' YourMeilisearchUrl' ,
300
300
meilisearch_api_key: ' YourMeilisearchAPIKey' ,
301
301
pagination_backend: :kaminari # :will_paginate
@@ -344,7 +344,7 @@ Then in your model you must extend `Pagy::Meilisearch`:
344
344
345
345
``` rb
346
346
class Book < ApplicationRecord
347
- include MeiliSearch ::Rails
347
+ include Meilisearch ::Rails
348
348
extend Pagy ::Meilisearch
349
349
350
350
meilisearch # ...
365
365
< %= = pagy_nav(@pagy ) %>
366
366
```
367
367
368
- :warning: There is no need to set `pagination_backend` in the configuration block `MeiliSearch ::Rails.configuration` for `pagy`.
368
+ :warning: There is no need to set `pagination_backend` in the configuration block `Meilisearch ::Rails.configuration` for `pagy`.
369
369
370
370
Check [`ddnexus/pagy`](https://ddnexus.github.io/pagy/extras/meilisearch) for more information.
371
371
@@ -377,7 +377,7 @@ you have multiple ways to achieve this.
377
377
By adding ` active: false` in the configuration initializer:
378
378
379
379
` ` ` ruby
380
- MeiliSearch ::Rails.configuration = {
380
+ Meilisearch ::Rails.configuration = {
381
381
meilisearch_url: 'YourMeilisearchUrl',
382
382
meilisearch_api_key: 'YourMeilisearchAPIKey',
383
383
active: false
@@ -387,11 +387,11 @@ MeiliSearch::Rails.configuration = {
387
387
Or you can disable programmatically:
388
388
389
389
` ` ` ruby
390
- MeiliSearch ::Rails.deactivate! # all the following HTTP calls will be dismissed.
390
+ Meilisearch ::Rails.deactivate! # all the following HTTP calls will be dismissed.
391
391
392
392
# or you can pass a block to it:
393
393
394
- MeiliSearch ::Rails.deactivate! do
394
+ Meilisearch ::Rails.deactivate! do
395
395
# every Meilisearch call here will be dismissed, no error will be raised.
396
396
# after the block, Meilisearch state will be active.
397
397
end
400
400
You can also activate if you deactivated earlier:
401
401
402
402
` ` ` ruby
403
- MeiliSearch ::Rails.activate!
403
+ Meilisearch ::Rails.activate!
404
404
` ` `
405
405
406
406
:warning : These calls are persistent, so prefer to use the method with the block. This way, you will not forget to activate it afterward.
@@ -411,7 +411,7 @@ By default, the **index_uid** will be the class name, e.g. `Book`. You can custo
411
411
412
412
` ` ` ruby
413
413
class Book < ActiveRecord::Base
414
- include MeiliSearch ::Rails
414
+ include Meilisearch ::Rails
415
415
416
416
meilisearch index_uid: 'MyCustomUID'
417
417
end
422
422
You can suffix the index UID with the current Rails environment by setting it globally:
423
423
424
424
` ` ` ruby
425
- MeiliSearch ::Rails.configuration = {
425
+ Meilisearch ::Rails.configuration = {
426
426
meilisearch_url: 'YourMeilisearchUrl',
427
427
meilisearch_api_key: 'YourMeilisearchAPIKey',
428
428
per_environment: true
@@ -441,7 +441,7 @@ You can add a custom attribute by using the `add_attribute` option or by using a
441
441
442
442
```ruby
443
443
class Author < ApplicationRecord
444
- include MeiliSearch ::Rails
444
+ include Meilisearch ::Rails
445
445
446
446
meilisearch do
447
447
attribute :first_name, :last_name
@@ -473,7 +473,7 @@ Note that the primary key must return a **unique value** otherwise your data cou
473
473
474
474
` ` ` ruby
475
475
class Book < ActiveRecord::Base
476
- include MeiliSearch ::Rails
476
+ include Meilisearch ::Rails
477
477
478
478
meilisearch primary_key: :isbn # isbn is a column in your table definition.
479
479
end
@@ -484,7 +484,7 @@ will be used as the reference to the document when Meilisearch needs it.
484
484
485
485
` ` ` rb
486
486
class Book < ActiveRecord::Base
487
- include MeiliSearch ::Rails
487
+ include Meilisearch ::Rails
488
488
489
489
meilisearch primary_key: :my_custom_ms_id
490
490
@@ -503,7 +503,7 @@ As soon as you use those constraints, `add_documents` and `delete_documents` cal
503
503
504
504
` ` ` ruby
505
505
class Book < ActiveRecord::Base
506
- include MeiliSearch ::Rails
506
+ include Meilisearch ::Rails
507
507
508
508
meilisearch if: :published?, unless: :premium?
509
509
@@ -526,7 +526,7 @@ You can index a record in several indexes using the `add_index` option:
526
526
527
527
` ` ` ruby
528
528
class Book < ActiveRecord::Base
529
- include MeiliSearch ::Rails
529
+ include Meilisearch ::Rails
530
530
531
531
PUBLIC_INDEX_UID = 'Books'
532
532
SECURED_INDEX_UID = 'PrivateBooks'
@@ -555,7 +555,7 @@ You may want to share an index between several models. You'll need to ensure you
555
555
556
556
` ` ` ruby
557
557
class Cat < ActiveRecord::Base
558
- include MeiliSearch ::Rails
558
+ include Meilisearch ::Rails
559
559
560
560
meilisearch index_uid: 'Animals', primary_key: :ms_id
561
561
@@ -567,7 +567,7 @@ class Cat < ActiveRecord::Base
567
567
end
568
568
569
569
class Dog < ActiveRecord::Base
570
- include MeiliSearch ::Rails
570
+ include Meilisearch ::Rails
571
571
572
572
meilisearch index_uid: 'Animals', primary_key: :ms_id
573
573
@@ -585,7 +585,7 @@ You can configure the auto-indexing & auto-removal process to use a queue to per
585
585
586
586
` ` ` ruby
587
587
class Book < ActiveRecord::Base
588
- include MeiliSearch ::Rails
588
+ include Meilisearch ::Rails
589
589
590
590
meilisearch enqueue: true # ActiveJob will be triggered using a ` meilisearch` queue
591
591
end
@@ -599,7 +599,7 @@ With **ActiveJob**:
599
599
600
600
` ` ` ruby
601
601
class Book < ActiveRecord::Base
602
- include MeiliSearch ::Rails
602
+ include Meilisearch ::Rails
603
603
604
604
meilisearch enqueue: :trigger_job do
605
605
attribute :title, :author, :description
@@ -629,7 +629,7 @@ With [**Sidekiq**](https://github.com/mperham/sidekiq):
629
629
630
630
` ` ` ruby
631
631
class Book < ActiveRecord::Base
632
- include MeiliSearch ::Rails
632
+ include Meilisearch ::Rails
633
633
634
634
meilisearch enqueue: :trigger_sidekiq_job do
635
635
attribute :title, :author, :description
@@ -659,7 +659,7 @@ With [**DelayedJob**](https://github.com/collectiveidea/delayed_job):
659
659
660
660
` ` ` ruby
661
661
class Book < ActiveRecord::Base
662
- include MeiliSearch ::Rails
662
+ include Meilisearch ::Rails
663
663
664
664
meilisearch enqueue: :trigger_delayed_job do
665
665
attribute :title, :author, :description
@@ -683,7 +683,7 @@ Extend a change to a related record.
683
683
684
684
```ruby
685
685
class Author < ActiveRecord::Base
686
- include MeiliSearch ::Rails
686
+ include Meilisearch ::Rails
687
687
688
688
has_many :books
689
689
# If your association uses belongs_to
@@ -693,7 +693,7 @@ class Author < ActiveRecord::Base
693
693
end
694
694
695
695
class Book < ActiveRecord::Base
696
- include MeiliSearch ::Rails
696
+ include Meilisearch ::Rails
697
697
698
698
belongs_to :author
699
699
after_touch :index!
@@ -712,7 +712,7 @@ With **Sequel**, you can use the `touch` plugin to propagate changes.
712
712
```ruby
713
713
# app/models/author.rb
714
714
class Author < Sequel::Model
715
- include MeiliSearch ::Rails
715
+ include Meilisearch ::Rails
716
716
717
717
one_to_many :books
718
718
734
734
735
735
# app/models/book.rb
736
736
class Book < Sequel::Model
737
- include MeiliSearch ::Rails
737
+ include Meilisearch ::Rails
738
738
739
739
many_to_one :author
740
740
after_touch :index!
@@ -757,7 +757,7 @@ You can strip all HTML tags from your attributes with the `sanitize` option.
757
757
758
758
```ruby
759
759
class Book < ActiveRecord::Base
760
- include MeiliSearch ::Rails
760
+ include Meilisearch ::Rails
761
761
762
762
meilisearch sanitize: true
763
763
end
@@ -769,7 +769,7 @@ You can force the UTF-8 encoding of all your attributes using the `force_utf8_en
769
769
770
770
```ruby
771
771
class Book < ActiveRecord::Base
772
- include MeiliSearch ::Rails
772
+ include Meilisearch ::Rails
773
773
774
774
meilisearch force_utf8_encoding: true
775
775
end
@@ -781,7 +781,7 @@ You can eager load associations using `meilisearch_import` scope.
781
781
782
782
```ruby
783
783
class Author < ActiveRecord::Base
784
- include MeiliSearch ::Rails
784
+ include Meilisearch ::Rails
785
785
786
786
has_many :books
787
787
@@ -834,7 +834,7 @@ You can disable exceptions that could be raised while trying to reach Meilisearc
834
834
835
835
``` ruby
836
836
class Book < ActiveRecord ::Base
837
- include MeiliSearch ::Rails
837
+ include Meilisearch ::Rails
838
838
839
839
# Only raise exceptions in development environment.
840
840
meilisearch raise_on_failure: Rails .env.development?
@@ -849,7 +849,7 @@ You can force indexing and removing to be synchronous by setting the following o
849
849
850
850
``` ruby
851
851
class Book < ActiveRecord ::Base
852
- include MeiliSearch ::Rails
852
+ include Meilisearch ::Rails
853
853
854
854
meilisearch synchronous: true
855
855
end
@@ -862,7 +862,7 @@ You can disable auto-indexing and auto-removing setting the following options:
862
862
863
863
``` ruby
864
864
class Book < ActiveRecord ::Base
865
- include MeiliSearch ::Rails
865
+ include Meilisearch ::Rails
866
866
867
867
meilisearch auto_index: false , auto_remove: false
868
868
end
0 commit comments