meilisearch-rails 0.10.2 → 0.11.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/LICENSE +1 -1
- data/lib/meilisearch/rails/ms_clean_up_job.rb +19 -0
- data/lib/meilisearch/rails/pagination.rb +1 -1
- data/lib/meilisearch/rails/version.rb +1 -1
- data/lib/meilisearch-rails.rb +67 -28
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 215428bdb5e437c3a906e1246444dc7e2afce9d2b52646790de1d55d0490783f
|
4
|
+
data.tar.gz: 412f8d56c952a330a9b3473602aca9ac0fee6789a3a3632f65340c7c85524637
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad8f9e4489c11dd3b2a522b134921232fbe2b66946f57ebf6be0c18ccd0643490379fb483d0a2ecf3371a427ff442809801130308e8f11fdedc7d6869a8d14c5
|
7
|
+
data.tar.gz: 5473ca9c267a3dfada14258db095d86c2e3618d356afc29ecf60c6975b067078cac91d8cc84c3e0b0bf8b5f227496d95830d77ed41923d0deeb313165b0b37df
|
data/LICENSE
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module MeiliSearch
|
2
|
+
module Rails
|
3
|
+
class MSCleanUpJob < ::ActiveJob::Base
|
4
|
+
queue_as :meilisearch
|
5
|
+
|
6
|
+
def perform(documents)
|
7
|
+
documents.each do |document|
|
8
|
+
index = MeiliSearch::Rails.client.index(document[:index_uid])
|
9
|
+
|
10
|
+
if document[:synchronous]
|
11
|
+
index.delete_document!(document[:primary_key])
|
12
|
+
else
|
13
|
+
index.delete_document(document[:primary_key])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -18,7 +18,7 @@ module MeiliSearch
|
|
18
18
|
|
19
19
|
def self.log_pagy_error
|
20
20
|
MeiliSearch::Rails.logger
|
21
|
-
.
|
21
|
+
.warn('[meilisearch-rails] Remove `pagination_backend: :pagy` from your initializer, `pagy` it is not required for `pagy`')
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.load_pagination!(pagination_backend, results, total_hits, options)
|
data/lib/meilisearch-rails.rb
CHANGED
@@ -249,6 +249,7 @@ module MeiliSearch
|
|
249
249
|
# lazy load the ActiveJob class to ensure the
|
250
250
|
# queue is initialized before using it
|
251
251
|
autoload :MSJob, 'meilisearch/rails/ms_job'
|
252
|
+
autoload :MSCleanUpJob, 'meilisearch/rails/ms_clean_up_job'
|
252
253
|
end
|
253
254
|
|
254
255
|
# this class wraps an MeiliSearch::Index document ensuring all raised exceptions
|
@@ -260,7 +261,7 @@ module MeiliSearch
|
|
260
261
|
@raise_on_failure = raise_on_failure.nil? || raise_on_failure
|
261
262
|
|
262
263
|
SafeIndex.log_or_throw(nil, @raise_on_failure) do
|
263
|
-
client.create_index(index_uid, { primary_key: primary_key })
|
264
|
+
client.create_index!(index_uid, { primary_key: primary_key })
|
264
265
|
end
|
265
266
|
|
266
267
|
@index = client.index(index_uid)
|
@@ -282,6 +283,15 @@ module MeiliSearch
|
|
282
283
|
end
|
283
284
|
end
|
284
285
|
|
286
|
+
# Maually define facet_search due to complications with **opts in ruby 2.*
|
287
|
+
def facet_search(*args, **opts)
|
288
|
+
SafeIndex.log_or_throw(:facet_search, @raise_on_failure) do
|
289
|
+
return MeiliSearch::Rails.black_hole unless MeiliSearch::Rails.active?
|
290
|
+
|
291
|
+
@index.facet_search(*args, **opts)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
285
295
|
# special handling of wait_for_task to handle null task_id
|
286
296
|
def wait_for_task(task_uid)
|
287
297
|
return if task_uid.nil? && !@raise_on_failure # ok
|
@@ -373,7 +383,11 @@ module MeiliSearch
|
|
373
383
|
|
374
384
|
proc = if options[:enqueue] == true
|
375
385
|
proc do |record, remove|
|
376
|
-
|
386
|
+
if remove
|
387
|
+
MSCleanUpJob.perform_later(record.ms_entries)
|
388
|
+
else
|
389
|
+
MSJob.perform_later(record, 'ms_index!')
|
390
|
+
end
|
377
391
|
end
|
378
392
|
elsif options[:enqueue].respond_to?(:call)
|
379
393
|
options[:enqueue]
|
@@ -445,7 +459,7 @@ module MeiliSearch
|
|
445
459
|
end
|
446
460
|
end
|
447
461
|
elsif respond_to?(:after_destroy)
|
448
|
-
|
462
|
+
after_destroy_commit { |searchable| searchable.ms_enqueue_remove_from_index!(ms_synchronous?) }
|
449
463
|
end
|
450
464
|
end
|
451
465
|
|
@@ -526,7 +540,8 @@ module MeiliSearch
|
|
526
540
|
def ms_index!(document, synchronous = false)
|
527
541
|
return if ms_without_auto_index_scope
|
528
542
|
|
529
|
-
|
543
|
+
# MS tasks to be returned
|
544
|
+
ms_configurations.map do |options, settings|
|
530
545
|
next if ms_indexing_disabled?(options)
|
531
546
|
|
532
547
|
primary_key = ms_primary_key_of(document, options)
|
@@ -550,8 +565,20 @@ module MeiliSearch
|
|
550
565
|
index.delete_document(primary_key)
|
551
566
|
end
|
552
567
|
end
|
568
|
+
end.compact
|
569
|
+
end
|
570
|
+
|
571
|
+
def ms_entries_for(document:, synchronous:)
|
572
|
+
primary_key = ms_primary_key_of(document)
|
573
|
+
raise ArgumentError, 'Cannot index a record without a primary key' if primary_key.blank?
|
574
|
+
|
575
|
+
ms_configurations.filter_map do |options, settings|
|
576
|
+
{
|
577
|
+
synchronous: synchronous || options[:synchronous],
|
578
|
+
index_uid: options[:index_uid],
|
579
|
+
primary_key: primary_key
|
580
|
+
}.with_indifferent_access unless ms_indexing_disabled?(options)
|
553
581
|
end
|
554
|
-
nil
|
555
582
|
end
|
556
583
|
|
557
584
|
def ms_remove_from_index!(document, synchronous = false)
|
@@ -735,33 +762,38 @@ module MeiliSearch
|
|
735
762
|
|
736
763
|
protected
|
737
764
|
|
738
|
-
def ms_ensure_init(options =
|
765
|
+
def ms_ensure_init(options = meilisearch_options, settings = meilisearch_settings, user_configuration = settings.to_settings)
|
739
766
|
raise ArgumentError, 'No `meilisearch` block found in your model.' if meilisearch_settings.nil?
|
740
767
|
|
741
768
|
@ms_indexes ||= { true => {}, false => {} }
|
742
769
|
|
743
|
-
|
744
|
-
settings ||= meilisearch_settings
|
770
|
+
@ms_indexes[MeiliSearch::Rails.active?][settings] ||= SafeIndex.new(ms_index_uid(options), meilisearch_options[:raise_on_failure], meilisearch_options)
|
745
771
|
|
746
|
-
|
772
|
+
update_settings_if_changed(@ms_indexes[MeiliSearch::Rails.active?][settings], options, user_configuration)
|
747
773
|
|
748
|
-
@ms_indexes[MeiliSearch::Rails.active?][settings]
|
774
|
+
@ms_indexes[MeiliSearch::Rails.active?][settings]
|
775
|
+
end
|
749
776
|
|
750
|
-
|
777
|
+
private
|
751
778
|
|
752
|
-
|
753
|
-
|
779
|
+
def update_settings_if_changed(index, options, user_configuration)
|
780
|
+
server_state = index.settings
|
781
|
+
user_configuration = options[:primary_settings].to_settings.merge(user_configuration) if options[:inherit]
|
754
782
|
|
755
|
-
|
783
|
+
config = user_configuration.except(:attributes_to_highlight, :attributes_to_crop, :crop_length)
|
756
784
|
|
757
|
-
if !
|
758
|
-
|
785
|
+
if !skip_checking_settings?(options) && meilisearch_settings_changed?(server_state, config)
|
786
|
+
index.update_settings(user_configuration)
|
759
787
|
end
|
788
|
+
end
|
760
789
|
|
761
|
-
|
790
|
+
def skip_checking_settings?(options)
|
791
|
+
ms_indexing_disabled?(options) || ms_checking_disabled?(options)
|
762
792
|
end
|
763
793
|
|
764
|
-
|
794
|
+
def ms_checking_disabled?(options)
|
795
|
+
options[:check_settings] == false
|
796
|
+
end
|
765
797
|
|
766
798
|
def ms_configurations
|
767
799
|
raise ArgumentError, 'No `meilisearch` block found in your model.' if meilisearch_settings.nil?
|
@@ -800,19 +832,22 @@ module MeiliSearch
|
|
800
832
|
options[:primary_key] || MeiliSearch::Rails::IndexSettings::DEFAULT_PRIMARY_KEY
|
801
833
|
end
|
802
834
|
|
803
|
-
def meilisearch_settings_changed?(
|
804
|
-
return true if
|
835
|
+
def meilisearch_settings_changed?(server_state, user_configuration)
|
836
|
+
return true if server_state.nil?
|
805
837
|
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
838
|
+
user_configuration.transform_keys! { |key| key.to_s.camelize(:lower) }
|
839
|
+
|
840
|
+
user_configuration.any? do |key, user|
|
841
|
+
server = server_state[key]
|
842
|
+
|
843
|
+
if user.is_a?(Hash) && server.is_a?(Hash)
|
844
|
+
meilisearch_settings_changed?(server, user)
|
845
|
+
elsif user.is_a?(Array) && server.is_a?(Array)
|
846
|
+
user.map(&:to_s) != server.map(&:to_s)
|
847
|
+
else
|
848
|
+
user.to_s != server.to_s
|
813
849
|
end
|
814
850
|
end
|
815
|
-
false
|
816
851
|
end
|
817
852
|
|
818
853
|
def ms_conditional_index?(options = nil)
|
@@ -923,6 +958,10 @@ module MeiliSearch
|
|
923
958
|
@ms_synchronous
|
924
959
|
end
|
925
960
|
|
961
|
+
def ms_entries(synchronous = false)
|
962
|
+
self.class.ms_entries_for(document: self, synchronous: synchronous || ms_synchronous?)
|
963
|
+
end
|
964
|
+
|
926
965
|
private
|
927
966
|
|
928
967
|
def ms_mark_synchronous
|
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.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: meilisearch
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- lib/meilisearch-rails.rb
|
41
41
|
- lib/meilisearch/rails/configuration.rb
|
42
42
|
- lib/meilisearch/rails/errors.rb
|
43
|
+
- lib/meilisearch/rails/ms_clean_up_job.rb
|
43
44
|
- lib/meilisearch/rails/ms_job.rb
|
44
45
|
- lib/meilisearch/rails/null_object.rb
|
45
46
|
- lib/meilisearch/rails/pagination.rb
|