@@ -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
)
@@ -268,7 +268,7 @@ Use `#each_result` to loop through pairs of your provided keys and the results:
268
268
Records are loaded when the keys are models, or when ` :class_name ` option is passed:
269
269
270
270
``` ruby
271
- multi_search_results = MeiliSearch ::Rails .multi_search(
271
+ multi_search_results = Meilisearch ::Rails .multi_search(
272
272
' books' => { q: ' Harry' , class_name: ' Book' },
273
273
' mangas' => { q: ' Attack' , class_name: ' Manga' }
274
274
)
@@ -279,7 +279,7 @@ Otherwise, hashes are returned.
279
279
The index to search is inferred from the model if the key is a model, if the key is a string the key is assumed to be the index unless the ` :index_uid ` option is passed:
280
280
281
281
``` ruby
282
- multi_search_results = MeiliSearch ::Rails .multi_search(
282
+ multi_search_results = Meilisearch ::Rails .multi_search(
283
283
' western' => { q: ' Harry' , class_name: ' Book' , index_uid: ' books_production' },
284
284
' japanese' => { q: ' Attack' , class_name: ' Manga' , index_uid: ' mangas_production' }
285
285
)
@@ -291,7 +291,7 @@ You can search the same index multiple times by specifying `:index_uid`:
291
291
292
292
``` ruby
293
293
query = ' hero'
294
- multi_search_results = MeiliSearch ::Rails .multi_search(
294
+ multi_search_results = Meilisearch ::Rails .multi_search(
295
295
' Isekai Manga' => { q: query, class_name: ' Manga' , filters: ' genre:isekai' , index_uid: ' mangas_production' }
296
296
' Shounen Manga' => { q: query, class_name: ' Manga' , filters: ' genre:shounen' , index_uid: ' mangas_production' }
297
297
' Steampunk Manga' => { q: query, class_name: ' Manga' , filters: ' genre:steampunk' , index_uid: ' mangas_production' }
@@ -333,7 +333,7 @@ This gem supports:
333
333
Specify the ` :pagination_backend ` in the configuration file:
334
334
335
335
``` ruby
336
- MeiliSearch ::Rails .configuration = {
336
+ Meilisearch ::Rails .configuration = {
337
337
meilisearch_url: ' YourMeilisearchUrl' ,
338
338
meilisearch_api_key: ' YourMeilisearchAPIKey' ,
339
339
pagination_backend: :kaminari # :will_paginate
@@ -382,7 +382,7 @@ Then in your model you must extend `Pagy::Meilisearch`:
382
382
383
383
``` rb
384
384
class Book < ApplicationRecord
385
- include MeiliSearch ::Rails
385
+ include Meilisearch ::Rails
386
386
extend Pagy ::Meilisearch
387
387
388
388
meilisearch # ...
403
403
< %= = pagy_nav(@pagy ) %>
404
404
```
405
405
406
- :warning: There is no need to set `pagination_backend` in the configuration block `MeiliSearch ::Rails.configuration` for `pagy`.
406
+ :warning: There is no need to set `pagination_backend` in the configuration block `Meilisearch ::Rails.configuration` for `pagy`.
407
407
408
408
Check [`ddnexus/pagy`](https://ddnexus.github.io/pagy/extras/meilisearch) for more information.
409
409
@@ -415,7 +415,7 @@ you have multiple ways to achieve this.
415
415
By adding ` active: false` in the configuration initializer:
416
416
417
417
` ` ` ruby
418
- MeiliSearch ::Rails.configuration = {
418
+ Meilisearch ::Rails.configuration = {
419
419
meilisearch_url: 'YourMeilisearchUrl',
420
420
meilisearch_api_key: 'YourMeilisearchAPIKey',
421
421
active: false
@@ -425,11 +425,11 @@ MeiliSearch::Rails.configuration = {
425
425
Or you can disable programmatically:
426
426
427
427
` ` ` ruby
428
- MeiliSearch ::Rails.deactivate! # all the following HTTP calls will be dismissed.
428
+ Meilisearch ::Rails.deactivate! # all the following HTTP calls will be dismissed.
429
429
430
430
# or you can pass a block to it:
431
431
432
- MeiliSearch ::Rails.deactivate! do
432
+ Meilisearch ::Rails.deactivate! do
433
433
# every Meilisearch call here will be dismissed, no error will be raised.
434
434
# after the block, Meilisearch state will be active.
435
435
end
438
438
You can also activate if you deactivated earlier:
439
439
440
440
` ` ` ruby
441
- MeiliSearch ::Rails.activate!
441
+ Meilisearch ::Rails.activate!
442
442
` ` `
443
443
444
444
:warning : These calls are persistent, so prefer to use the method with the block. This way, you will not forget to activate it afterward.
@@ -449,7 +449,7 @@ By default, the **index_uid** will be the class name, e.g. `Book`. You can custo
449
449
450
450
` ` ` ruby
451
451
class Book < ActiveRecord::Base
452
- include MeiliSearch ::Rails
452
+ include Meilisearch ::Rails
453
453
454
454
meilisearch index_uid: 'MyCustomUID'
455
455
end
460
460
You can suffix the index UID with the current Rails environment by setting it globally:
461
461
462
462
` ` ` ruby
463
- MeiliSearch ::Rails.configuration = {
463
+ Meilisearch ::Rails.configuration = {
464
464
meilisearch_url: 'YourMeilisearchUrl',
465
465
meilisearch_api_key: 'YourMeilisearchAPIKey',
466
466
per_environment: true
@@ -479,7 +479,7 @@ You can add a custom attribute by using the `add_attribute` option or by using a
479
479
480
480
```ruby
481
481
class Author < ApplicationRecord
482
- include MeiliSearch ::Rails
482
+ include Meilisearch ::Rails
483
483
484
484
meilisearch do
485
485
attribute :first_name, :last_name
@@ -511,7 +511,7 @@ Note that the primary key must return a **unique value** otherwise your data cou
511
511
512
512
` ` ` ruby
513
513
class Book < ActiveRecord::Base
514
- include MeiliSearch ::Rails
514
+ include Meilisearch ::Rails
515
515
516
516
meilisearch primary_key: :isbn # isbn is a column in your table definition.
517
517
end
@@ -522,7 +522,7 @@ will be used as the reference to the document when Meilisearch needs it.
522
522
523
523
` ` ` rb
524
524
class Book < ActiveRecord::Base
525
- include MeiliSearch ::Rails
525
+ include Meilisearch ::Rails
526
526
527
527
meilisearch primary_key: :my_custom_ms_id
528
528
@@ -541,7 +541,7 @@ As soon as you use those constraints, `add_documents` and `delete_documents` cal
541
541
542
542
` ` ` ruby
543
543
class Book < ActiveRecord::Base
544
- include MeiliSearch ::Rails
544
+ include Meilisearch ::Rails
545
545
546
546
meilisearch if: :published?, unless: :premium?
547
547
@@ -564,7 +564,7 @@ You can index a record in several indexes using the `add_index` option:
564
564
565
565
` ` ` ruby
566
566
class Book < ActiveRecord::Base
567
- include MeiliSearch ::Rails
567
+ include Meilisearch ::Rails
568
568
569
569
PUBLIC_INDEX_UID = 'Books'
570
570
SECURED_INDEX_UID = 'PrivateBooks'
@@ -593,7 +593,7 @@ You may want to share an index between several models. You'll need to ensure you
593
593
594
594
` ` ` ruby
595
595
class Cat < ActiveRecord::Base
596
- include MeiliSearch ::Rails
596
+ include Meilisearch ::Rails
597
597
598
598
meilisearch index_uid: 'Animals', primary_key: :ms_id
599
599
@@ -605,7 +605,7 @@ class Cat < ActiveRecord::Base
605
605
end
606
606
607
607
class Dog < ActiveRecord::Base
608
- include MeiliSearch ::Rails
608
+ include Meilisearch ::Rails
609
609
610
610
meilisearch index_uid: 'Animals', primary_key: :ms_id
611
611
@@ -623,7 +623,7 @@ You can configure the auto-indexing & auto-removal process to use a queue to per
623
623
624
624
` ` ` ruby
625
625
class Book < ActiveRecord::Base
626
- include MeiliSearch ::Rails
626
+ include Meilisearch ::Rails
627
627
628
628
meilisearch enqueue: true # ActiveJob will be triggered using a ` meilisearch` queue
629
629
end
@@ -637,7 +637,7 @@ With **ActiveJob**:
637
637
638
638
` ` ` ruby
639
639
class Book < ActiveRecord::Base
640
- include MeiliSearch ::Rails
640
+ include Meilisearch ::Rails
641
641
642
642
meilisearch enqueue: :trigger_job do
643
643
attribute :title, :author, :description
@@ -667,7 +667,7 @@ With [**Sidekiq**](https://github.com/mperham/sidekiq):
667
667
668
668
` ` ` ruby
669
669
class Book < ActiveRecord::Base
670
- include MeiliSearch ::Rails
670
+ include Meilisearch ::Rails
671
671
672
672
meilisearch enqueue: :trigger_sidekiq_job do
673
673
attribute :title, :author, :description
@@ -697,7 +697,7 @@ With [**DelayedJob**](https://github.com/collectiveidea/delayed_job):
697
697
698
698
` ` ` ruby
699
699
class Book < ActiveRecord::Base
700
- include MeiliSearch ::Rails
700
+ include Meilisearch ::Rails
701
701
702
702
meilisearch enqueue: :trigger_delayed_job do
703
703
attribute :title, :author, :description
@@ -721,7 +721,7 @@ Extend a change to a related record.
721
721
722
722
```ruby
723
723
class Author < ActiveRecord::Base
724
- include MeiliSearch ::Rails
724
+ include Meilisearch ::Rails
725
725
726
726
has_many :books
727
727
# If your association uses belongs_to
@@ -731,7 +731,7 @@ class Author < ActiveRecord::Base
731
731
end
732
732
733
733
class Book < ActiveRecord::Base
734
- include MeiliSearch ::Rails
734
+ include Meilisearch ::Rails
735
735
736
736
belongs_to :author
737
737
after_touch :index!
@@ -750,7 +750,7 @@ With **Sequel**, you can use the `touch` plugin to propagate changes.
750
750
```ruby
751
751
# app/models/author.rb
752
752
class Author < Sequel::Model
753
- include MeiliSearch ::Rails
753
+ include Meilisearch ::Rails
754
754
755
755
one_to_many :books
756
756
772
772
773
773
# app/models/book.rb
774
774
class Book < Sequel::Model
775
- include MeiliSearch ::Rails
775
+ include Meilisearch ::Rails
776
776
777
777
many_to_one :author
778
778
after_touch :index!
@@ -795,7 +795,7 @@ You can strip all HTML tags from your attributes with the `sanitize` option.
795
795
796
796
```ruby
797
797
class Book < ActiveRecord::Base
798
- include MeiliSearch ::Rails
798
+ include Meilisearch ::Rails
799
799
800
800
meilisearch sanitize: true
801
801
end
@@ -807,7 +807,7 @@ You can force the UTF-8 encoding of all your attributes using the `force_utf8_en
807
807
808
808
```ruby
809
809
class Book < ActiveRecord::Base
810
- include MeiliSearch ::Rails
810
+ include Meilisearch ::Rails
811
811
812
812
meilisearch force_utf8_encoding: true
813
813
end
@@ -819,7 +819,7 @@ You can eager load associations using `meilisearch_import` scope.
819
819
820
820
```ruby
821
821
class Author < ActiveRecord::Base
822
- include MeiliSearch ::Rails
822
+ include Meilisearch ::Rails
823
823
824
824
has_many :books
825
825
@@ -872,7 +872,7 @@ You can disable exceptions that could be raised while trying to reach Meilisearc
872
872
873
873
``` ruby
874
874
class Book < ActiveRecord ::Base
875
- include MeiliSearch ::Rails
875
+ include Meilisearch ::Rails
876
876
877
877
# Only raise exceptions in development environment.
878
878
meilisearch raise_on_failure: Rails .env.development?
@@ -887,7 +887,7 @@ You can force indexing and removing to be synchronous by setting the following o
887
887
888
888
``` ruby
889
889
class Book < ActiveRecord ::Base
890
- include MeiliSearch ::Rails
890
+ include Meilisearch ::Rails
891
891
892
892
meilisearch synchronous: true
893
893
end
@@ -900,7 +900,7 @@ You can disable auto-indexing and auto-removing setting the following options:
900
900
901
901
``` ruby
902
902
class Book < ActiveRecord ::Base
903
- include MeiliSearch ::Rails
903
+ include Meilisearch ::Rails
904
904
905
905
meilisearch auto_index: false , auto_remove: false
906
906
end
0 commit comments