meilisearch-rails 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2541e903db43e95ae8290c07308159dc9d724949dc1ffa27214df3e52cd37fe6
4
- data.tar.gz: 8b4e32b34e9e3c4fbae0e5c21efa20d87e611ebada16889ba01ba236343b0f6d
3
+ metadata.gz: c0d3aeaf9f6e2549c11cdcd7cf5920fecb819fb1b2f03a25af11c19a5dd09444
4
+ data.tar.gz: 0af07156e3e3ea69d492745f806751e2213ad7148553f57396528ad54fa3f02a
5
5
  SHA512:
6
- metadata.gz: 1eba16d0d03695d817998c5249a1ad33d343df4816332a63c7e7b220d42cd2734b9d1ed90e1893a12de6b67d5ed4b1f4e4ca8cad21f3d3e206f8e108f3ffc07f
7
- data.tar.gz: 53ffa781649f9370e7fe35aa5b7263f8792a7f04ede7c28da6e2f6d85b015ae2fcef236affeea659b11c538385a39ca50fb13dab7857d50e8e76067b813f7dfc
6
+ metadata.gz: a49c6d3b48de31033515e61c9fd182842d5d7d7ba90e140b6447339eeb6473139f3de4f1c3428f48a9176f3c36c5080ebc198897f4b53900f74e416bb817eaf1
7
+ data.tar.gz: 63805d38ba88e0b020a0a147cce244ec35a0fb2a93715ff5b62df77ca87021b2b11581647626b2c76eaddc26ad15ab0a8e9d4e82c7e1895095829b7cce74965c
data/README.md CHANGED
@@ -170,10 +170,10 @@ Then, as soon as you use the `search` method, the returning results will be pagi
170
170
  <%= will_paginate @hits %> # if using will_paginate
171
171
  ```
172
172
 
173
- The **number of hits per page defaults to 20**, you can customize it by adding the `hitsPerPage` parameter to your search:
173
+ The **number of hits per page defaults to 20**, you can customize it by adding the `hits_per_page` parameter to your search:
174
174
 
175
175
  ```ruby
176
- Book.search('harry potter', hitsPerPage: 10)
176
+ Book.search('harry potter', hits_per_page: 10)
177
177
  ```
178
178
 
179
179
  #### Extra Configuration <!-- omit in toc -->
@@ -228,7 +228,7 @@ Check the dedicated section of the documentation, for more information on the [s
228
228
  All the supported options are described in the [search parameters](https://docs.meilisearch.com/reference/features/search_parameters.html) section of the documentation.
229
229
 
230
230
  ```ruby
231
- Book.search('Harry', attributesToHighlight: ['*'])
231
+ Book.search('Harry', attributes_to_highlight: ['*'])
232
232
  ```
233
233
  👉 Don't forget that `attributes_to_highlight`, `attributes_to_crop`, and
234
234
  `crop_length` can be set up in the `meilisearch` block of your model.
@@ -256,24 +256,36 @@ By default, the **index_uid** will be the class name, e.g. `Book`. You can custo
256
256
  class Book < ActiveRecord::Base
257
257
  include MeiliSearch::Rails
258
258
 
259
- meilisearch index_uid: 'MyCustomUID' do
260
- end
259
+ meilisearch index_uid: 'MyCustomUID'
261
260
  end
262
261
  ```
263
262
 
264
263
  #### Index UID according to the environment <!-- omit in toc -->
265
264
 
266
- You can suffix the index UID with the current Rails environment using the following option:
265
+ You can suffix the index UID with the current Rails environment using one of the following options:
266
+
267
+ By defining directly in your model:
267
268
 
268
269
  ```ruby
269
270
  class Book < ActiveRecord::Base
270
271
  include MeiliSearch::Rails
271
272
 
272
- meilisearch per_environment: true do # The index UID will be "Book_#{Rails.env}"
273
- end
273
+ meilisearch per_environment: true
274
274
  end
275
275
  ```
276
276
 
277
+ Or setting it globally:
278
+
279
+ ```ruby
280
+ MeiliSearch::Rails.configuration = {
281
+ meilisearch_host: 'YourMeilisearchHost',
282
+ meilisearch_api_key: 'YourMeilisearchAPIKey',
283
+ per_environment: true
284
+ }
285
+ ```
286
+
287
+ Both options will make your index name look like this `"Book_#{Rails.env}"`.
288
+
277
289
  ### Index configuration
278
290
 
279
291
  #### Custom attribute definition
@@ -318,8 +330,7 @@ Note that the primary key must have a **unique value**.
318
330
  class Book < ActiveRecord::Base
319
331
  include MeiliSearch::Rails
320
332
 
321
- meilisearch primary_key: 'ISBN' do
322
- end
333
+ meilisearch primary_key: 'ISBN'
323
334
  end
324
335
  ```
325
336
  #### Conditional indexing
@@ -331,8 +342,7 @@ As soon as you use those constraints, `add_documents` and `delete_documents` cal
331
342
  class Book < ActiveRecord::Base
332
343
  include MeiliSearch::Rails
333
344
 
334
- meilisearch if: :published?, unless: :premium? do
335
- end
345
+ meilisearch if: :published?, unless: :premium?
336
346
 
337
347
  def published?
338
348
  # [...]
@@ -369,6 +379,7 @@ class Book < ActiveRecord::Base
369
379
  end
370
380
 
371
381
  private
382
+
372
383
  def public?
373
384
  released? && !premium?
374
385
  end
@@ -383,10 +394,10 @@ You may want to share an index between several models. You'll need to ensure you
383
394
  class Cat < ActiveRecord::Base
384
395
  include MeiliSearch::Rails
385
396
 
386
- meilisearch index_uid: 'Animals', primary_key: :ms_id do
387
- end
397
+ meilisearch index_uid: 'Animals', primary_key: :ms_id
388
398
 
389
399
  private
400
+
390
401
  def ms_id
391
402
  "cat_#{primary_key}" # ensure the cats & dogs primary_keys are not conflicting
392
403
  end
@@ -395,10 +406,10 @@ end
395
406
  class Dog < ActiveRecord::Base
396
407
  include MeiliSearch::Rails
397
408
 
398
- meilisearch index_uid: 'Animals', primary_key: :ms_id do
399
- end
409
+ meilisearch index_uid: 'Animals', primary_key: :ms_id
400
410
 
401
411
  private
412
+
402
413
  def ms_id
403
414
  "dog_#{primary_key}" # ensure the cats & dogs primary_keys are not conflicting
404
415
  end
@@ -413,8 +424,7 @@ You can configure the auto-indexing & auto-removal process to use a queue to per
413
424
  class Book < ActiveRecord::Base
414
425
  include MeiliSearch::Rails
415
426
 
416
- meilisearch enqueue: true do # ActiveJob will be triggered using a `meilisearch` queue
417
- end
427
+ meilisearch enqueue: true # ActiveJob will be triggered using a `meilisearch` queue
418
428
  end
419
429
  ```
420
430
 
@@ -586,8 +596,7 @@ You can strip all HTML tags from your attributes with the `sanitize` option.
586
596
  class Book < ActiveRecord::Base
587
597
  include MeiliSearch::Rails
588
598
 
589
- meilisearch sanitize: true do
590
- end
599
+ meilisearch sanitize: true
591
600
  end
592
601
  ```
593
602
 
@@ -599,8 +608,7 @@ You can force the UTF-8 encoding of all your attributes using the `force_utf8_en
599
608
  class Book < ActiveRecord::Base
600
609
  include MeiliSearch::Rails
601
610
 
602
- meilisearch force_utf8_encoding: true do
603
- end
611
+ meilisearch force_utf8_encoding: true
604
612
  end
605
613
  ```
606
614
 
@@ -652,8 +660,7 @@ class Book < ActiveRecord::Base
652
660
  include MeiliSearch::Rails
653
661
 
654
662
  # Only raise exceptions in development environment.
655
- meilisearch raise_on_failure: Rails.env.development? do
656
- end
663
+ meilisearch raise_on_failure: Rails.env.development?
657
664
  end
658
665
  ```
659
666
 
@@ -667,8 +674,7 @@ You can force indexing and removing to be synchronous by setting the following o
667
674
  class Book < ActiveRecord::Base
668
675
  include MeiliSearch::Rails
669
676
 
670
- meilisearch synchronous: true do
671
- end
677
+ meilisearch synchronous: true
672
678
  end
673
679
  ```
674
680
  🚨 This is only recommended for testing purposes, the gem will call the `wait_for_task` method that will stop your code execution until the asynchronous task has been processed by MeilSearch.
@@ -681,8 +687,7 @@ You can disable auto-indexing and auto-removing setting the following options:
681
687
  class Book < ActiveRecord::Base
682
688
  include MeiliSearch::Rails
683
689
 
684
- meilisearch auto_index: false, auto_remove: false do
685
- end
690
+ meilisearch auto_index: false, auto_remove: false
686
691
  end
687
692
  ```
688
693
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module MeiliSearch
4
4
  module Rails
5
- VERSION = '0.5.2'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -105,7 +105,7 @@ module MeiliSearch
105
105
  end
106
106
 
107
107
  def sequel?(document)
108
- defined?(::Sequel) && document.class < ::Sequel::Model
108
+ defined?(::Sequel::Model) && document.class < ::Sequel::Model
109
109
  end
110
110
 
111
111
  def active_record?(document)
@@ -319,8 +319,12 @@ module MeiliSearch
319
319
 
320
320
  attr_accessor :formatted
321
321
 
322
+ if options.key?(:per_environment)
323
+ raise BadConfiguration, ':per_environment option should be defined globally on MeiliSearch::Rails.configuration block.'
324
+ end
325
+
322
326
  if options[:synchronous] == true
323
- if defined?(::Sequel) && self < Sequel::Model
327
+ if defined?(::Sequel::Model) && self < Sequel::Model
324
328
  class_eval do
325
329
  copy_after_validation = instance_method(:after_validation)
326
330
  define_method(:after_validation) do |*args|
@@ -352,7 +356,7 @@ module MeiliSearch
352
356
  end
353
357
  end
354
358
  unless options[:auto_index] == false
355
- if defined?(::Sequel) && self < Sequel::Model
359
+ if defined?(::Sequel::Model) && self < Sequel::Model
356
360
  class_eval do
357
361
  copy_after_validation = instance_method(:after_validation)
358
362
  copy_before_save = instance_method(:before_save)
@@ -399,7 +403,7 @@ module MeiliSearch
399
403
  end
400
404
  end
401
405
  unless options[:auto_remove] == false
402
- if defined?(::Sequel) && self < Sequel::Model
406
+ if defined?(::Sequel::Model) && self < Sequel::Model
403
407
  class_eval do
404
408
  copy_after_destroy = instance_method(:after_destroy)
405
409
 
@@ -653,8 +657,11 @@ module MeiliSearch
653
657
 
654
658
  def ms_index_uid(options = nil)
655
659
  options ||= meilisearch_options
660
+ global_options ||= MeiliSearch::Rails.configuration
661
+
656
662
  name = options[:index_uid] || model_name.to_s.gsub('::', '_')
657
- name = "#{name}_#{::Rails.env}" if options[:per_environment]
663
+ name = "#{name}_#{::Rails.env}" if global_options[:per_environment]
664
+
658
665
  name
659
666
  end
660
667
 
@@ -821,7 +828,7 @@ module MeiliSearch
821
828
  def ms_find_in_batches(batch_size, &block)
822
829
  if (defined?(::ActiveRecord) && ancestors.include?(::ActiveRecord::Base)) || respond_to?(:find_in_batches)
823
830
  find_in_batches(batch_size: batch_size, &block)
824
- elsif defined?(::Sequel) && self < Sequel::Model
831
+ elsif defined?(::Sequel::Model) && self < Sequel::Model
825
832
  dataset.extension(:pagination).each_page(batch_size, &block)
826
833
  else
827
834
  # don't worry, mongoid has its own underlying cursor/streaming mechanism
@@ -903,7 +910,7 @@ module MeiliSearch
903
910
  # ms_must_reindex flag is reset after every commit as part. If we must reindex at any point in
904
911
  # a transaction, keep flag set until it is explicitly unset
905
912
  @ms_must_reindex ||=
906
- if defined?(::Sequel) && is_a?(Sequel::Model)
913
+ if defined?(::Sequel::Model) && is_a?(Sequel::Model)
907
914
  new? || self.class.ms_must_reindex?(self)
908
915
  else
909
916
  new_record? || self.class.ms_must_reindex?(self)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meilisearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meili
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-18 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: meilisearch