meilisearch-rails 0.14.2 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +258 -50
- data/lib/meilisearch/rails/configuration.rb +3 -3
- data/lib/meilisearch/rails/errors.rb +2 -2
- data/lib/meilisearch/rails/ms_clean_up_job.rb +2 -2
- data/lib/meilisearch/rails/ms_job.rb +1 -1
- data/lib/meilisearch/rails/multi_search/federated_search_result.rb +78 -0
- data/lib/meilisearch/rails/multi_search/multi_search_result.rb +115 -0
- data/lib/meilisearch/rails/multi_search.rb +63 -8
- data/lib/meilisearch/rails/null_object.rb +1 -1
- data/lib/meilisearch/rails/pagination/kaminari.rb +10 -7
- data/lib/meilisearch/rails/pagination/will_paginate.rb +9 -3
- data/lib/meilisearch/rails/pagination.rb +4 -4
- data/lib/meilisearch/rails/railtie.rb +1 -1
- data/lib/meilisearch/rails/tasks/meilisearch.rake +3 -3
- data/lib/meilisearch/rails/templates/initializer.rb +1 -1
- data/lib/meilisearch/rails/utilities.rb +2 -2
- data/lib/meilisearch/rails/version.rb +2 -2
- data/lib/meilisearch-rails.rb +28 -22
- data/meilisearch-rails.gemspec +2 -2
- metadata +6 -5
- data/lib/meilisearch/rails/multi_search/result.rb +0 -84
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 317b4503e3616fe8f309ac194c2eb85a902222edda8ae58824c53f081280a0de
|
4
|
+
data.tar.gz: f9ef605f39f533307b5af4d6204c8fd19fb5d49dd507e72010d7d5458b37e066
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f2d3137a16b624704eeadb64d86c32e0c87864abf7af1fb7df19d8acf90d74ee57db5df1707c073c80a73aec99964519bcace556a6ce8f40828d179b74971f4
|
7
|
+
data.tar.gz: 0a56e1651b062fc45fcde8e4206d2f08c21af07882bfaaeb80d928fe3cf4fa112a5e2102127f7d598120c978076bbacf2c2681c2452cca0406ac5ac15a899d2a
|
data/README.md
CHANGED
@@ -38,6 +38,7 @@
|
|
38
38
|
- [⚙️ Settings](#️-settings)
|
39
39
|
- [🔍 Custom search](#-custom-search)
|
40
40
|
- [🔍🔍 Multi search](#-multi-search)
|
41
|
+
- [🔍🔍 Federated search](#-federated-search)
|
41
42
|
- [🪛 Options](#-options)
|
42
43
|
- [Meilisearch configuration & environment](#meilisearch-configuration--environment)
|
43
44
|
- [Pagination with `kaminari` or `will_paginate`](#backend-pagination-with-kaminari-or-will_paginate-)
|
@@ -98,7 +99,7 @@ gem 'meilisearch-rails'
|
|
98
99
|
Create a new file `config/initializers/meilisearch.rb` to setup your `MEILISEARCH_HOST` and `MEILISEARCH_API_KEY`
|
99
100
|
|
100
101
|
```ruby
|
101
|
-
|
102
|
+
Meilisearch::Rails.configuration = {
|
102
103
|
meilisearch_url: ENV.fetch('MEILISEARCH_HOST', 'http://localhost:7700'),
|
103
104
|
meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY', 'YourMeilisearchAPIKey')
|
104
105
|
}
|
@@ -120,7 +121,7 @@ The following code will create a `Book` index and add search capabilities to you
|
|
120
121
|
|
121
122
|
```ruby
|
122
123
|
class Book < ActiveRecord::Base
|
123
|
-
include
|
124
|
+
include Meilisearch::Rails
|
124
125
|
|
125
126
|
meilisearch do
|
126
127
|
attribute :title, :author # only the attributes 'title', and 'author' will be sent to Meilisearch
|
@@ -154,7 +155,7 @@ Requests made to Meilisearch may timeout and retry. To adapt the behavior to
|
|
154
155
|
your needs, you can change the parameters during configuration:
|
155
156
|
|
156
157
|
```ruby
|
157
|
-
|
158
|
+
Meilisearch::Rails.configuration = {
|
158
159
|
meilisearch_url: 'YourMeilisearchUrl',
|
159
160
|
meilisearch_api_key: 'YourMeilisearchAPIKey',
|
160
161
|
timeout: 2,
|
@@ -172,7 +173,7 @@ You can configure the index settings by adding them inside the `meilisearch` blo
|
|
172
173
|
|
173
174
|
```ruby
|
174
175
|
class Book < ApplicationRecord
|
175
|
-
include
|
176
|
+
include Meilisearch::Rails
|
176
177
|
|
177
178
|
meilisearch do
|
178
179
|
searchable_attributes [:title, :author, :publisher, :description]
|
@@ -235,13 +236,75 @@ Book.search('*', sort: ['title:asc'])
|
|
235
236
|
Meilisearch supports searching multiple models at the same time (see [🔍 Custom search](#-custom-search) for search options):
|
236
237
|
|
237
238
|
```ruby
|
238
|
-
multi_search_results =
|
239
|
+
multi_search_results = Meilisearch::Rails.multi_search(
|
239
240
|
Book => { q: 'Harry' },
|
240
241
|
Manga => { q: 'Attack' }
|
241
242
|
)
|
242
243
|
```
|
243
244
|
|
244
|
-
|
245
|
+
Use `#each_result` to loop through pairs of your provided keys and the results:
|
246
|
+
```erb
|
247
|
+
<% multi_search_results.each_result do |klass, results| %>
|
248
|
+
<p><%= klass.name.pluralize %></p>
|
249
|
+
|
250
|
+
<ul>
|
251
|
+
<% results.each do |record| %>
|
252
|
+
<li><%= record.title %></li>
|
253
|
+
<% end %>
|
254
|
+
</ul>
|
255
|
+
<% end %>
|
256
|
+
|
257
|
+
|
258
|
+
<p>Books</p>
|
259
|
+
<ul>
|
260
|
+
<li>Harry Potter and the Philosopher's Stone</li>
|
261
|
+
<li>Harry Potter and the Chamber of Secrets</li>
|
262
|
+
</ul>
|
263
|
+
<p>Mangas</p>
|
264
|
+
<ul>
|
265
|
+
<li>Attack on Titan</li>
|
266
|
+
</ul>
|
267
|
+
```
|
268
|
+
|
269
|
+
Records are loaded when the keys are models, or when `:scope` option is passed:
|
270
|
+
|
271
|
+
```ruby
|
272
|
+
multi_search_results = Meilisearch::Rails.multi_search(
|
273
|
+
# scope may be a relation
|
274
|
+
'books' => { q: 'Harry', scope: Book.all },
|
275
|
+
# or a model
|
276
|
+
'mangas' => { q: 'Attack', scope: Manga }
|
277
|
+
)
|
278
|
+
```
|
279
|
+
|
280
|
+
Otherwise, hashes are returned.
|
281
|
+
|
282
|
+
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:
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
multi_search_results = Meilisearch::Rails.multi_search(
|
286
|
+
'western' => { q: 'Harry', scope: Book, index_uid: 'books_production' },
|
287
|
+
'japanese' => { q: 'Attack', scope: Manga, index_uid: 'mangas_production' }
|
288
|
+
)
|
289
|
+
```
|
290
|
+
|
291
|
+
### Multi search the same index <!-- omit in toc -->
|
292
|
+
|
293
|
+
You can search the same index multiple times by specifying `:index_uid`:
|
294
|
+
|
295
|
+
```ruby
|
296
|
+
query = 'hero'
|
297
|
+
|
298
|
+
multi_search_results = Meilisearch::Rails.multi_search(
|
299
|
+
'Isekai Manga' => { q: query, scope: Manga, filters: 'genre:isekai', index_uid: 'mangas_production' }
|
300
|
+
'Shounen Manga' => { q: query, scope: Manga, filters: 'genre:shounen', index_uid: 'mangas_production' }
|
301
|
+
'Steampunk Manga' => { q: query, scope: Manga, filters: 'genre:steampunk', index_uid: 'mangas_production' }
|
302
|
+
)
|
303
|
+
```
|
304
|
+
|
305
|
+
### Deprecated #each <!-- omit in toc -->
|
306
|
+
|
307
|
+
**DEPRECATED:** You used to be able to iterate through a flattened collection with `.each`:
|
245
308
|
|
246
309
|
```erb
|
247
310
|
<% multi_search_results.each do |record| %>
|
@@ -257,30 +320,175 @@ You can iterate through the results with `.each` or `.each_result`:
|
|
257
320
|
<p>Iseyama</p>
|
258
321
|
```
|
259
322
|
|
260
|
-
|
261
|
-
<% multi_search_results.each_result do |klass, results| %>
|
262
|
-
<p><%= klass.name.pluralize %></p>
|
323
|
+
But this has been deprecated in favor of **federated search**.
|
263
324
|
|
264
|
-
|
265
|
-
<% results.each do |record| %>
|
266
|
-
<li><%= record.title %></li>
|
267
|
-
<% end %>
|
268
|
-
</ul>
|
269
|
-
<% end %>
|
325
|
+
See the [official multi search documentation](https://www.meilisearch.com/docs/reference/api/multi_search).
|
270
326
|
|
327
|
+
## 🔍🔍 Federated search
|
271
328
|
|
272
|
-
|
329
|
+
Federated search is similar to multi search, except that results are not grouped but sorted by ranking rules.
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
results = Meilisearch::Rails.federated_search(
|
333
|
+
queries: [
|
334
|
+
{ q: 'Harry', scope: Book.all },
|
335
|
+
{ q: 'Attack on Titan', scope: Manga.all }
|
336
|
+
]
|
337
|
+
)
|
338
|
+
```
|
339
|
+
|
340
|
+
An enumerable `FederatedSearchResult` is returned, which can be iterated through with `#each`:
|
341
|
+
|
342
|
+
```erb
|
273
343
|
<ul>
|
274
|
-
|
275
|
-
|
344
|
+
<% results.each do |record| %>
|
345
|
+
<li><%= record.title %></li>
|
346
|
+
<% end %>
|
276
347
|
</ul>
|
277
|
-
|
348
|
+
|
349
|
+
|
278
350
|
<ul>
|
351
|
+
<!-- Attack on Titan appears first even though it was specified second,
|
352
|
+
it's ranked higher because it's a closer match -->
|
279
353
|
<li>Attack on Titan</li>
|
354
|
+
<li>Harry Potter and the Philosopher's Stone</li>
|
355
|
+
<li>Harry Potter and the Chamber of Secrets</li>
|
280
356
|
</ul>
|
281
357
|
```
|
282
358
|
|
283
|
-
|
359
|
+
The `queries` parameter may be a multi-search style hash with keys that are either classes, index names, or neither:
|
360
|
+
|
361
|
+
```ruby
|
362
|
+
results = Meilisearch::Rails.federated_search(
|
363
|
+
queries: {
|
364
|
+
Book => { q: 'Harry' },
|
365
|
+
Manga => { q: 'Attack on Titan' }
|
366
|
+
}
|
367
|
+
)
|
368
|
+
```
|
369
|
+
|
370
|
+
```ruby
|
371
|
+
results = Meilisearch::Rails.federated_search(
|
372
|
+
queries: {
|
373
|
+
'books_production' => { q: 'Harry', scope: Book.all },
|
374
|
+
'mangas_production' => { q: 'Attack on Titan', scope: Manga.all }
|
375
|
+
}
|
376
|
+
)
|
377
|
+
```
|
378
|
+
|
379
|
+
```ruby
|
380
|
+
results = Meilisearch::Rails.federated_search(
|
381
|
+
queries: {
|
382
|
+
'potter' => { q: 'Harry', scope: Book.all, index_uid: 'books_production' },
|
383
|
+
'titan' => { q: 'Attack on Titan', scope: Manga.all, index_uid: 'mangas_production' }
|
384
|
+
}
|
385
|
+
)
|
386
|
+
```
|
387
|
+
|
388
|
+
### Loading records <!-- omit in toc -->
|
389
|
+
|
390
|
+
Records are loaded when the `:scope` option is passed (may be a model or a relation),
|
391
|
+
or when a hash query is used with models as keys:
|
392
|
+
|
393
|
+
```ruby
|
394
|
+
results = Meilisearch::Rails.federated_search(
|
395
|
+
queries: [
|
396
|
+
{ q: 'Harry', scope: Book },
|
397
|
+
{ q: 'Attack on Titan', scope: Manga },
|
398
|
+
]
|
399
|
+
)
|
400
|
+
```
|
401
|
+
|
402
|
+
```ruby
|
403
|
+
results = Meilisearch::Rails.federated_search(
|
404
|
+
queries: {
|
405
|
+
Book => { q: 'Harry' },
|
406
|
+
Manga => { q: 'Attack on Titan' }
|
407
|
+
}
|
408
|
+
)
|
409
|
+
```
|
410
|
+
|
411
|
+
If the model is not provided, hashes are returned!
|
412
|
+
|
413
|
+
### Scoping records <!-- omit in toc -->
|
414
|
+
|
415
|
+
Any relation passed as `:scope` is used as the starting point when loading records:
|
416
|
+
|
417
|
+
```ruby
|
418
|
+
results = Meilisearch::Rails.federated_search(
|
419
|
+
queries: [
|
420
|
+
{ q: 'Harry', scope: Book.where('year <= 2006') },
|
421
|
+
{ q: 'Attack on Titan', scope: Manga.where(author: Author.find_by(name: 'Iseyama')) },
|
422
|
+
]
|
423
|
+
)
|
424
|
+
```
|
425
|
+
|
426
|
+
### Specifying the search index <!-- omit in toc -->
|
427
|
+
|
428
|
+
In order of precedence, to figure out which index to search, Meilisearch Rails will check:
|
429
|
+
|
430
|
+
1. `index_uid` options
|
431
|
+
```ruby
|
432
|
+
results = Meilisearch::Rails.federated_search(
|
433
|
+
queries: [
|
434
|
+
# Searching the 'fantasy_books' index
|
435
|
+
{ q: 'Harry', scope: Book, index_uid: 'fantasy_books' },
|
436
|
+
]
|
437
|
+
)
|
438
|
+
```
|
439
|
+
2. The index associated with the model
|
440
|
+
```ruby
|
441
|
+
results = Meilisearch::Rails.federated_search(
|
442
|
+
queries: [
|
443
|
+
# Searching the index associated with the Book model
|
444
|
+
# i. e. Book.index.uid
|
445
|
+
{ q: 'Harry', scope: Book },
|
446
|
+
]
|
447
|
+
)
|
448
|
+
```
|
449
|
+
3. The key when using hash queries
|
450
|
+
```ruby
|
451
|
+
results = Meilisearch::Rails.federated_search(
|
452
|
+
queries: {
|
453
|
+
# Searching index 'books_production'
|
454
|
+
books_production: { q: 'Harry', scope: Book },
|
455
|
+
}
|
456
|
+
)
|
457
|
+
```
|
458
|
+
|
459
|
+
### Pagination and other options <!-- omit in toc -->
|
460
|
+
|
461
|
+
In addition to queries, federated search also accepts `:federation` parameters which allow for finer control of the search:
|
462
|
+
|
463
|
+
```ruby
|
464
|
+
results = Meilisearch::Rails.federated_search(
|
465
|
+
queries: [
|
466
|
+
{ q: 'Harry', scope: Book },
|
467
|
+
{ q: 'Attack on Titan', scope: Manga },
|
468
|
+
],
|
469
|
+
federation: { offset: 10, limit: 5 }
|
470
|
+
)
|
471
|
+
```
|
472
|
+
See a full list of accepted options in [the meilisearch documentation](https://www.meilisearch.com/docs/reference/api/multi_search#federation).
|
473
|
+
|
474
|
+
#### Metadata <!-- omit in toc -->
|
475
|
+
|
476
|
+
The returned result from a federated search includes a `.metadata` attribute you can use to access everything other than the search hits:
|
477
|
+
|
478
|
+
```ruby
|
479
|
+
result.metadata
|
480
|
+
# {
|
481
|
+
# "processingTimeMs" => 0,
|
482
|
+
# "limit" => 20,
|
483
|
+
# "offset" => 0,
|
484
|
+
# "estimatedTotalHits" => 2,
|
485
|
+
# "semanticHitCount": 0
|
486
|
+
# }
|
487
|
+
```
|
488
|
+
|
489
|
+
The metadata contains facet stats and pagination stats, among others. See the full response in [the documentation](https://www.meilisearch.com/docs/reference/api/multi_search#federated-multi-search-requests).
|
490
|
+
|
491
|
+
More details on federated search (such as available `federation:` options) can be found on [the official multi search documentation](https://www.meilisearch.com/docs/reference/api/multi_search).
|
284
492
|
|
285
493
|
## 🪛 Options
|
286
494
|
|
@@ -295,7 +503,7 @@ This gem supports:
|
|
295
503
|
Specify the `:pagination_backend` in the configuration file:
|
296
504
|
|
297
505
|
```ruby
|
298
|
-
|
506
|
+
Meilisearch::Rails.configuration = {
|
299
507
|
meilisearch_url: 'YourMeilisearchUrl',
|
300
508
|
meilisearch_api_key: 'YourMeilisearchAPIKey',
|
301
509
|
pagination_backend: :kaminari # :will_paginate
|
@@ -344,7 +552,7 @@ Then in your model you must extend `Pagy::Meilisearch`:
|
|
344
552
|
|
345
553
|
```rb
|
346
554
|
class Book < ApplicationRecord
|
347
|
-
include
|
555
|
+
include Meilisearch::Rails
|
348
556
|
extend Pagy::Meilisearch
|
349
557
|
|
350
558
|
meilisearch # ...
|
@@ -365,7 +573,7 @@ end
|
|
365
573
|
<%== pagy_nav(@pagy) %>
|
366
574
|
```
|
367
575
|
|
368
|
-
:warning: There is no need to set `pagination_backend` in the configuration block `
|
576
|
+
:warning: There is no need to set `pagination_backend` in the configuration block `Meilisearch::Rails.configuration` for `pagy`.
|
369
577
|
|
370
578
|
Check [`ddnexus/pagy`](https://ddnexus.github.io/pagy/extras/meilisearch) for more information.
|
371
579
|
|
@@ -377,7 +585,7 @@ you have multiple ways to achieve this.
|
|
377
585
|
By adding `active: false` in the configuration initializer:
|
378
586
|
|
379
587
|
```ruby
|
380
|
-
|
588
|
+
Meilisearch::Rails.configuration = {
|
381
589
|
meilisearch_url: 'YourMeilisearchUrl',
|
382
590
|
meilisearch_api_key: 'YourMeilisearchAPIKey',
|
383
591
|
active: false
|
@@ -387,11 +595,11 @@ MeiliSearch::Rails.configuration = {
|
|
387
595
|
Or you can disable programmatically:
|
388
596
|
|
389
597
|
```ruby
|
390
|
-
|
598
|
+
Meilisearch::Rails.deactivate! # all the following HTTP calls will be dismissed.
|
391
599
|
|
392
600
|
# or you can pass a block to it:
|
393
601
|
|
394
|
-
|
602
|
+
Meilisearch::Rails.deactivate! do
|
395
603
|
# every Meilisearch call here will be dismissed, no error will be raised.
|
396
604
|
# after the block, Meilisearch state will be active.
|
397
605
|
end
|
@@ -400,7 +608,7 @@ end
|
|
400
608
|
You can also activate if you deactivated earlier:
|
401
609
|
|
402
610
|
```ruby
|
403
|
-
|
611
|
+
Meilisearch::Rails.activate!
|
404
612
|
```
|
405
613
|
|
406
614
|
: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 +619,7 @@ By default, the **index_uid** will be the class name, e.g. `Book`. You can custo
|
|
411
619
|
|
412
620
|
```ruby
|
413
621
|
class Book < ActiveRecord::Base
|
414
|
-
include
|
622
|
+
include Meilisearch::Rails
|
415
623
|
|
416
624
|
meilisearch index_uid: 'MyCustomUID'
|
417
625
|
end
|
@@ -422,7 +630,7 @@ end
|
|
422
630
|
You can suffix the index UID with the current Rails environment by setting it globally:
|
423
631
|
|
424
632
|
```ruby
|
425
|
-
|
633
|
+
Meilisearch::Rails.configuration = {
|
426
634
|
meilisearch_url: 'YourMeilisearchUrl',
|
427
635
|
meilisearch_api_key: 'YourMeilisearchAPIKey',
|
428
636
|
per_environment: true
|
@@ -441,7 +649,7 @@ You can add a custom attribute by using the `add_attribute` option or by using a
|
|
441
649
|
|
442
650
|
```ruby
|
443
651
|
class Author < ApplicationRecord
|
444
|
-
include
|
652
|
+
include Meilisearch::Rails
|
445
653
|
|
446
654
|
meilisearch do
|
447
655
|
attribute :first_name, :last_name
|
@@ -473,7 +681,7 @@ Note that the primary key must return a **unique value** otherwise your data cou
|
|
473
681
|
|
474
682
|
```ruby
|
475
683
|
class Book < ActiveRecord::Base
|
476
|
-
include
|
684
|
+
include Meilisearch::Rails
|
477
685
|
|
478
686
|
meilisearch primary_key: :isbn # isbn is a column in your table definition.
|
479
687
|
end
|
@@ -484,7 +692,7 @@ will be used as the reference to the document when Meilisearch needs it.
|
|
484
692
|
|
485
693
|
```rb
|
486
694
|
class Book < ActiveRecord::Base
|
487
|
-
include
|
695
|
+
include Meilisearch::Rails
|
488
696
|
|
489
697
|
meilisearch primary_key: :my_custom_ms_id
|
490
698
|
|
@@ -503,7 +711,7 @@ As soon as you use those constraints, `add_documents` and `delete_documents` cal
|
|
503
711
|
|
504
712
|
```ruby
|
505
713
|
class Book < ActiveRecord::Base
|
506
|
-
include
|
714
|
+
include Meilisearch::Rails
|
507
715
|
|
508
716
|
meilisearch if: :published?, unless: :premium?
|
509
717
|
|
@@ -526,7 +734,7 @@ You can index a record in several indexes using the `add_index` option:
|
|
526
734
|
|
527
735
|
```ruby
|
528
736
|
class Book < ActiveRecord::Base
|
529
|
-
include
|
737
|
+
include Meilisearch::Rails
|
530
738
|
|
531
739
|
PUBLIC_INDEX_UID = 'Books'
|
532
740
|
SECURED_INDEX_UID = 'PrivateBooks'
|
@@ -555,7 +763,7 @@ You may want to share an index between several models. You'll need to ensure you
|
|
555
763
|
|
556
764
|
```ruby
|
557
765
|
class Cat < ActiveRecord::Base
|
558
|
-
include
|
766
|
+
include Meilisearch::Rails
|
559
767
|
|
560
768
|
meilisearch index_uid: 'Animals', primary_key: :ms_id
|
561
769
|
|
@@ -567,7 +775,7 @@ class Cat < ActiveRecord::Base
|
|
567
775
|
end
|
568
776
|
|
569
777
|
class Dog < ActiveRecord::Base
|
570
|
-
include
|
778
|
+
include Meilisearch::Rails
|
571
779
|
|
572
780
|
meilisearch index_uid: 'Animals', primary_key: :ms_id
|
573
781
|
|
@@ -585,7 +793,7 @@ You can configure the auto-indexing & auto-removal process to use a queue to per
|
|
585
793
|
|
586
794
|
```ruby
|
587
795
|
class Book < ActiveRecord::Base
|
588
|
-
include
|
796
|
+
include Meilisearch::Rails
|
589
797
|
|
590
798
|
meilisearch enqueue: true # ActiveJob will be triggered using a `meilisearch` queue
|
591
799
|
end
|
@@ -599,7 +807,7 @@ With **ActiveJob**:
|
|
599
807
|
|
600
808
|
```ruby
|
601
809
|
class Book < ActiveRecord::Base
|
602
|
-
include
|
810
|
+
include Meilisearch::Rails
|
603
811
|
|
604
812
|
meilisearch enqueue: :trigger_job do
|
605
813
|
attribute :title, :author, :description
|
@@ -629,7 +837,7 @@ With [**Sidekiq**](https://github.com/mperham/sidekiq):
|
|
629
837
|
|
630
838
|
```ruby
|
631
839
|
class Book < ActiveRecord::Base
|
632
|
-
include
|
840
|
+
include Meilisearch::Rails
|
633
841
|
|
634
842
|
meilisearch enqueue: :trigger_sidekiq_job do
|
635
843
|
attribute :title, :author, :description
|
@@ -659,7 +867,7 @@ With [**DelayedJob**](https://github.com/collectiveidea/delayed_job):
|
|
659
867
|
|
660
868
|
```ruby
|
661
869
|
class Book < ActiveRecord::Base
|
662
|
-
include
|
870
|
+
include Meilisearch::Rails
|
663
871
|
|
664
872
|
meilisearch enqueue: :trigger_delayed_job do
|
665
873
|
attribute :title, :author, :description
|
@@ -683,7 +891,7 @@ Extend a change to a related record.
|
|
683
891
|
|
684
892
|
```ruby
|
685
893
|
class Author < ActiveRecord::Base
|
686
|
-
include
|
894
|
+
include Meilisearch::Rails
|
687
895
|
|
688
896
|
has_many :books
|
689
897
|
# If your association uses belongs_to
|
@@ -693,7 +901,7 @@ class Author < ActiveRecord::Base
|
|
693
901
|
end
|
694
902
|
|
695
903
|
class Book < ActiveRecord::Base
|
696
|
-
include
|
904
|
+
include Meilisearch::Rails
|
697
905
|
|
698
906
|
belongs_to :author
|
699
907
|
after_touch :index!
|
@@ -712,7 +920,7 @@ With **Sequel**, you can use the `touch` plugin to propagate changes.
|
|
712
920
|
```ruby
|
713
921
|
# app/models/author.rb
|
714
922
|
class Author < Sequel::Model
|
715
|
-
include
|
923
|
+
include Meilisearch::Rails
|
716
924
|
|
717
925
|
one_to_many :books
|
718
926
|
|
@@ -734,7 +942,7 @@ end
|
|
734
942
|
|
735
943
|
# app/models/book.rb
|
736
944
|
class Book < Sequel::Model
|
737
|
-
include
|
945
|
+
include Meilisearch::Rails
|
738
946
|
|
739
947
|
many_to_one :author
|
740
948
|
after_touch :index!
|
@@ -757,7 +965,7 @@ You can strip all HTML tags from your attributes with the `sanitize` option.
|
|
757
965
|
|
758
966
|
```ruby
|
759
967
|
class Book < ActiveRecord::Base
|
760
|
-
include
|
968
|
+
include Meilisearch::Rails
|
761
969
|
|
762
970
|
meilisearch sanitize: true
|
763
971
|
end
|
@@ -769,7 +977,7 @@ You can force the UTF-8 encoding of all your attributes using the `force_utf8_en
|
|
769
977
|
|
770
978
|
```ruby
|
771
979
|
class Book < ActiveRecord::Base
|
772
|
-
include
|
980
|
+
include Meilisearch::Rails
|
773
981
|
|
774
982
|
meilisearch force_utf8_encoding: true
|
775
983
|
end
|
@@ -781,7 +989,7 @@ You can eager load associations using `meilisearch_import` scope.
|
|
781
989
|
|
782
990
|
```ruby
|
783
991
|
class Author < ActiveRecord::Base
|
784
|
-
include
|
992
|
+
include Meilisearch::Rails
|
785
993
|
|
786
994
|
has_many :books
|
787
995
|
|
@@ -834,7 +1042,7 @@ You can disable exceptions that could be raised while trying to reach Meilisearc
|
|
834
1042
|
|
835
1043
|
```ruby
|
836
1044
|
class Book < ActiveRecord::Base
|
837
|
-
include
|
1045
|
+
include Meilisearch::Rails
|
838
1046
|
|
839
1047
|
# Only raise exceptions in development environment.
|
840
1048
|
meilisearch raise_on_failure: Rails.env.development?
|
@@ -849,7 +1057,7 @@ You can force indexing and removing to be synchronous by setting the following o
|
|
849
1057
|
|
850
1058
|
```ruby
|
851
1059
|
class Book < ActiveRecord::Base
|
852
|
-
include
|
1060
|
+
include Meilisearch::Rails
|
853
1061
|
|
854
1062
|
meilisearch synchronous: true
|
855
1063
|
end
|
@@ -862,7 +1070,7 @@ You can disable auto-indexing and auto-removing setting the following options:
|
|
862
1070
|
|
863
1071
|
```ruby
|
864
1072
|
class Book < ActiveRecord::Base
|
865
|
-
include
|
1073
|
+
include Meilisearch::Rails
|
866
1074
|
|
867
1075
|
meilisearch auto_index: false, auto_remove: false
|
868
1076
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Meilisearch
|
2
2
|
module Rails
|
3
3
|
module Configuration
|
4
4
|
def configuration
|
@@ -44,11 +44,11 @@ module MeiliSearch
|
|
44
44
|
def client
|
45
45
|
return black_hole unless active?
|
46
46
|
|
47
|
-
::
|
47
|
+
::Meilisearch::Client.new(
|
48
48
|
configuration[:meilisearch_url] || 'http://localhost:7700',
|
49
49
|
configuration[:meilisearch_api_key],
|
50
50
|
configuration.slice(:timeout, :max_retries)
|
51
|
-
.merge(client_agents:
|
51
|
+
.merge(client_agents: Meilisearch::Rails.qualified_version)
|
52
52
|
)
|
53
53
|
end
|
54
54
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Meilisearch
|
2
2
|
module Rails
|
3
3
|
class NoBlockGiven < StandardError; end
|
4
4
|
|
@@ -6,7 +6,7 @@ module MeiliSearch
|
|
6
6
|
|
7
7
|
class NotConfigured < StandardError
|
8
8
|
def message
|
9
|
-
'Please configure Meilisearch. Set
|
9
|
+
'Please configure Meilisearch. Set Meilisearch::Rails.configuration = ' \
|
10
10
|
"{meilisearch_url: 'YOUR_MEILISEARCH_URL', meilisearch_api_key: 'YOUR_API_KEY'}"
|
11
11
|
end
|
12
12
|
end
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module Meilisearch
|
2
2
|
module Rails
|
3
3
|
class MSCleanUpJob < ::ActiveJob::Base
|
4
4
|
queue_as :meilisearch
|
5
5
|
|
6
6
|
def perform(documents)
|
7
7
|
documents.each do |document|
|
8
|
-
index =
|
8
|
+
index = Meilisearch::Rails.client.index(document[:index_uid])
|
9
9
|
|
10
10
|
if document[:synchronous]
|
11
11
|
index.delete_document(document[:primary_key]).await
|