plok 1.1.2 → 1.1.4
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/app/models/concerns/plok/searchable.rb +1 -1
- data/lib/plok/version.rb +1 -1
- data/lib/tasks/plok/search.rake +47 -0
- data/lib/tasks/plok_tasks.rake +0 -46
- data/spec/support/plok/searchable.rb +35 -4
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f3ad1b023f6d523f5766b822fcc60d26cccb4983a46ec6e7efcc75d88fce4d0
|
4
|
+
data.tar.gz: 6ab0505a105e0534a15470b3b161ef23d6b49161ea2962af3dd34ff3c5819318
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418a0736b07848ff337b82ce1207ab4904810e6fd643ff15a93a44a125d7e35e676f981991e4d7f129f92d667d8602f976e3eddd72fb78c5b6c2d9d7b26e9b32
|
7
|
+
data.tar.gz: 9cac24540be3eafc2335cbb9b36e6bef87b65c80fcf9d3ea1850070b890cbd6840ea83e8b353ab977c73837049e93affbbbd1b96dcb77bfe3594ec6b50af3a22
|
@@ -3,7 +3,7 @@ module Plok::Searchable
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
has_many :search_indices, as: :searchable
|
6
|
+
has_many :search_indices, as: :searchable, dependent: :destroy
|
7
7
|
|
8
8
|
# The after_save block creates or saves indices for every indicated
|
9
9
|
# searchable field. Takes both translations and flexible content into
|
data/lib/plok/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
namespace 'plok:search' do
|
2
|
+
# The official Rails way to pass arguments to Rake tasks is this:
|
3
|
+
#
|
4
|
+
# task :rebuild_indices, [:modules] => :environment do |_t, args|
|
5
|
+
# args.with_defaults(modules: SearchModule.searchable.pluck(:klass))
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# The problem with that is that you can't comma-separate multiple modules
|
9
|
+
# unless you escape them. This is because commas denote multiple arguments.
|
10
|
+
#
|
11
|
+
# In short, this wouldn't work:
|
12
|
+
#
|
13
|
+
# bin/rails plok:search:rebuild_indices[EmailTemplate,Article]
|
14
|
+
#
|
15
|
+
# And you'd need to do this:
|
16
|
+
#
|
17
|
+
# bin/rails plok:search:rebuild_indices["EmailTemplate\,Article"]
|
18
|
+
#
|
19
|
+
# I don't agree with that notation, so instead I opted for ENV vars instead:
|
20
|
+
#
|
21
|
+
# bin/rails plok:search:rebuild_indices modules=EmailTemplate,Article
|
22
|
+
#
|
23
|
+
desc 'Rebuild select search indices (or all of them without additional arguments).'
|
24
|
+
task rebuild_indices: :environment do
|
25
|
+
# Default to all searchable modules
|
26
|
+
modules = ENV['modules']&.split(',') || SearchModule.searchable.pluck(:klass)
|
27
|
+
|
28
|
+
# A safeguard to prevent mishaps
|
29
|
+
modules.select! do |m|
|
30
|
+
SearchModule.exists?(klass: m) && # Only known modules
|
31
|
+
Plok::Engine.class_exists?(m.constantize) # Only existing classes
|
32
|
+
end
|
33
|
+
|
34
|
+
SearchModule.where(klass: modules).each do |m|
|
35
|
+
puts "Removing existing #{m.klass} indices..."
|
36
|
+
# Faster than SearchIndex.where(searchable_type: modules).destroy_all
|
37
|
+
ActiveRecord::Base
|
38
|
+
.connection
|
39
|
+
.execute("DELETE FROM search_indices WHERE searchable_type = '#{m.klass}'")
|
40
|
+
|
41
|
+
puts "Rebuilding #{m.klass} indices..."
|
42
|
+
m.klass.constantize.all.each(&:trigger_indices_save!)
|
43
|
+
end
|
44
|
+
|
45
|
+
puts "Done."
|
46
|
+
end
|
47
|
+
end
|
data/lib/tasks/plok_tasks.rake
CHANGED
@@ -1,46 +0,0 @@
|
|
1
|
-
namespace 'plok:search' do
|
2
|
-
# The official Rails way to pass arguments to Rake tasks is this:
|
3
|
-
#
|
4
|
-
# task :rebuild_indices, [:modules] => :environment do |_t, args|
|
5
|
-
# args.with_defaults(modules: SearchModule.searchable.pluck(:klass))
|
6
|
-
# end
|
7
|
-
#
|
8
|
-
# The problem with that is that you can't comma-separate multiple modules
|
9
|
-
# unless you escape them. This is because commas denote multiple arguments.
|
10
|
-
#
|
11
|
-
# In short, this wouldn't work:
|
12
|
-
#
|
13
|
-
# bin/rails plok:search:rebuild_indices[EmailTemplate,Article]
|
14
|
-
#
|
15
|
-
# And you'd need to do this:
|
16
|
-
#
|
17
|
-
# bin/rails plok:search:rebuild_indices["EmailTemplate\,Article"]
|
18
|
-
#
|
19
|
-
# I don't agree with that notation, so instead I opted for ENV vars instead:
|
20
|
-
#
|
21
|
-
# bin/rails plok:search:rebuild_indices modules=EmailTemplate,Article
|
22
|
-
#
|
23
|
-
desc 'Rebuild select search indices (or all of them without additional arguments).'
|
24
|
-
task rebuild_indices: :environment do
|
25
|
-
# Default to all searchable modules
|
26
|
-
modules = ENV['modules']&.split(',') || SearchModule.searchable.pluck(:klass)
|
27
|
-
|
28
|
-
# A safeguard to prevent mishaps
|
29
|
-
modules.select! do |m|
|
30
|
-
SearchModule.exists?(klass: m) && # Only known modules
|
31
|
-
Plok::Engine.class_exists?(m.constantize) # Only existing classes
|
32
|
-
end
|
33
|
-
|
34
|
-
# Faster than SearchIndex.where(searchable_type: modules).destroy_all
|
35
|
-
ActiveRecord::Base
|
36
|
-
.connection
|
37
|
-
.execute("DELETE FROM search_indices WHERE searchable_type in ('#{modules.join("','")}')")
|
38
|
-
|
39
|
-
SearchModule.where(klass: modules).each do |m|
|
40
|
-
puts "Rebuilding #{m.klass} indices..."
|
41
|
-
m.klass.constantize.all.each(&:trigger_indices_save!)
|
42
|
-
end
|
43
|
-
|
44
|
-
puts "Done."
|
45
|
-
end
|
46
|
-
end
|
@@ -3,16 +3,34 @@ require 'rails_helper'
|
|
3
3
|
shared_examples_for :searchable do
|
4
4
|
let(:klass) { described_class.to_s.underscore.to_sym }
|
5
5
|
|
6
|
+
describe 'relations' do
|
7
|
+
context 'when destroying a searchable model' do
|
8
|
+
it 'deletes all linked SearchIndex records' do
|
9
|
+
subject = create(klass)
|
10
|
+
index = create(:search_index, searchable: subject)
|
11
|
+
expect { subject.destroy }.to change(SearchIndex, :count)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
6
16
|
describe 'after_save' do
|
7
17
|
context 'non-translatable model' do
|
8
18
|
before do
|
9
19
|
# Because this is a spec/support included through it_behaves_like,
|
10
20
|
# we have to mock the entry points of the data used in
|
11
21
|
# Plok::Searchable.
|
12
|
-
allow(described_class).to receive(:searchable_fields_list)
|
22
|
+
allow(described_class).to receive(:searchable_fields_list) do
|
23
|
+
{
|
24
|
+
backend: [
|
25
|
+
{ name: :foo, conditions: [] }
|
26
|
+
]
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
13
30
|
if described_class.respond_to?(:translatable_fields_list)
|
14
31
|
allow(described_class).to receive(:translatable_fields_list) { [] }
|
15
32
|
end
|
33
|
+
|
16
34
|
described_class.define_method(:foo) { 'bar' }
|
17
35
|
end
|
18
36
|
|
@@ -27,7 +45,13 @@ shared_examples_for :searchable do
|
|
27
45
|
|
28
46
|
if described_class.respond_to?(:translatable_fields)
|
29
47
|
before do
|
30
|
-
allow(described_class).to receive(:searchable_fields_list)
|
48
|
+
allow(described_class).to receive(:searchable_fields_list) do
|
49
|
+
{
|
50
|
+
backend: [
|
51
|
+
{ name: :foo, conditions: [] }
|
52
|
+
]
|
53
|
+
}
|
54
|
+
end
|
31
55
|
end
|
32
56
|
|
33
57
|
context 'translatable model' do
|
@@ -62,7 +86,14 @@ shared_examples_for :searchable do
|
|
62
86
|
# Because this is a spec/support included through it_behaves_like,
|
63
87
|
# we have to mock the entry points of the data used in
|
64
88
|
# Plok::Searchable.
|
65
|
-
allow(described_class).to receive(:searchable_fields_list)
|
89
|
+
allow(described_class).to receive(:searchable_fields_list) do
|
90
|
+
{
|
91
|
+
backend: [
|
92
|
+
{ name: :foo, conditions: [] }
|
93
|
+
]
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
66
97
|
allow_any_subject_of(described_class).to receive(:foo) { 'bar' }
|
67
98
|
allow_any_subject_of(Concerns::Storable::Collection).to receive(:foo) { 'bar' }
|
68
99
|
|
@@ -90,7 +121,7 @@ shared_examples_for :searchable do
|
|
90
121
|
|
91
122
|
it '.respond_to?' do
|
92
123
|
expect(described_class).to respond_to(
|
93
|
-
:
|
124
|
+
:plok_searchable, :searchable_field, :searchable_fields_list
|
94
125
|
)
|
95
126
|
end
|
96
127
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davy Hellemans
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -67,6 +67,20 @@ dependencies:
|
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '6.0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: database_cleaner-active_record
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '2.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '2.0'
|
70
84
|
description: Some basics used for setting up rails projects
|
71
85
|
email:
|
72
86
|
- davy@blimp.be
|
@@ -125,6 +139,7 @@ files:
|
|
125
139
|
- lib/plok/search/result_objects/base.rb
|
126
140
|
- lib/plok/search/term.rb
|
127
141
|
- lib/plok/version.rb
|
142
|
+
- lib/tasks/plok/search.rake
|
128
143
|
- lib/tasks/plok_tasks.rake
|
129
144
|
- spec/factories/logs.rb
|
130
145
|
- spec/factories/queued_tasks.rb
|