sunspot_rails 2.2.6 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -2
- data/Appraisals +64 -0
- data/Gemfile +3 -0
- data/lib/sunspot/rails/configuration.rb +4 -0
- data/lib/sunspot/rails/request_lifecycle.rb +3 -1
- data/lib/sunspot/rails/searchable.rb +15 -7
- data/lib/sunspot/rails/solr_instrumentation.rb +2 -2
- data/lib/sunspot/rails/solr_logging.rb +5 -10
- data/lib/sunspot/rails/stub_session_proxy.rb +9 -2
- data/lib/sunspot/rails/tasks.rb +0 -1
- data/lib/sunspot/rails.rb +2 -0
- data/spec/configuration_spec.rb +77 -69
- data/spec/model_lifecycle_spec.rb +8 -8
- data/spec/model_spec.rb +72 -71
- data/spec/rails_app/app/controllers/application_controller.rb +4 -0
- data/spec/rails_app/app/controllers/posts_controller.rb +16 -0
- data/spec/{rails_template → rails_app}/app/models/author.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/blog.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/location.rb +0 -1
- data/spec/{rails_template → rails_app}/app/models/post.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/post_with_auto.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/post_with_default_scope.rb +0 -2
- data/spec/{rails_template → rails_app}/app/models/post_with_only_some_attributes_triggering_reindex.rb +0 -2
- data/spec/rails_app/config/application.rb +17 -0
- data/spec/rails_app/config/boot.rb +6 -0
- data/spec/rails_app/config/database.yml +5 -0
- data/spec/rails_app/config/environment.rb +5 -0
- data/spec/rails_app/config/environments/test.rb +41 -0
- data/spec/rails_app/config/initializers/rails_5_override.rb +1 -0
- data/spec/rails_app/config/initializers/secret_token.rb +1 -0
- data/spec/rails_app/config/initializers/session_store.rb +3 -0
- data/spec/{rails_template → rails_app}/config/sunspot.yml +2 -0
- data/spec/rails_app/config.ru +4 -0
- data/spec/rails_app/db/schema.rb +26 -0
- data/spec/rails_app/vendor/engines/test_engine/app/models/test_engine/rake_task_auto_load_test_model.rb +15 -0
- data/spec/rails_app/vendor/engines/test_engine/lib/test_engine/engine.rb +5 -0
- data/spec/rails_app/vendor/engines/test_engine/lib/test_engine.rb +4 -0
- data/spec/rake_task_spec.rb +9 -9
- data/spec/request_lifecycle_spec.rb +17 -21
- data/spec/schema.rb +8 -9
- data/spec/searchable_spec.rb +4 -4
- data/spec/server_spec.rb +7 -7
- data/spec/session_spec.rb +3 -3
- data/spec/shared_examples/indexed_after_save.rb +1 -1
- data/spec/shared_examples/not_indexed_after_save.rb +1 -1
- data/spec/spec_helper.rb +18 -51
- data/spec/stub_session_proxy_spec.rb +40 -36
- data/sunspot_rails.gemspec +15 -8
- metadata +102 -58
- data/dev_tasks/spec.rake +0 -97
- data/gemfiles/rails-3.0.0 +0 -21
- data/gemfiles/rails-3.1.0 +0 -21
- data/gemfiles/rails-3.2.0 +0 -21
- data/gemfiles/rails-4.0.0 +0 -25
- data/gemfiles/rails-4.1.0 +0 -24
- data/gemfiles/rails-4.2.0 +0 -24
- data/spec/rails_template/app/controllers/application_controller.rb +0 -10
- data/spec/rails_template/app/controllers/posts_controller.rb +0 -6
- data/spec/rails_template/config/database.yml +0 -11
- data/spec/rails_template/db/schema.rb +0 -27
- /data/{tmp → gemfiles}/.gitkeep +0 -0
- /data/spec/{rails_template → rails_app}/app/models/photo_post.rb +0 -0
- /data/spec/{rails_template → rails_app}/app/models/rake_task_auto_load_test_model.rb +0 -0
- /data/spec/{rails_template → rails_app}/config/routes.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 63d24337902829c8c14a7ea0d9f081c7392b457e0604ff78887ed67037fcedc5
|
4
|
+
data.tar.gz: 77c235ecfc5bc55c4758abece0d0336bc0c541bf6461d5f134b7bec57eec3c88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3a95a7312b3dd3b3402fee02ff137c85b357cf17c1babf7c98f5a37456515882d5e8978729d368b42fa67c4163d02704b7540f9878cd4dd9d09cde22f78f1b8
|
7
|
+
data.tar.gz: 3b031829d6bfac5ee89d7cc33ebc76375614e4ac21f9b1864b55d313a537d08a4ef96cd57d60cc41fabc5eca589a2e42052169172c77756adf382aac7e108dae
|
data/.gitignore
CHANGED
data/Appraisals
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
ruby_version = Gem::Version.new(RUBY_VERSION)
|
2
|
+
|
3
|
+
if ruby_version < Gem::Version.new('2.2.0')
|
4
|
+
['3.0.0', '3.1.0'].each do |rails_version|
|
5
|
+
appraise "rails-#{rails_version}" do
|
6
|
+
gem 'bundler', '>= 1.3.0', '< 2.0'
|
7
|
+
gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME'])
|
8
|
+
gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME'])
|
9
|
+
gem 'rails', "~> #{rails_version}"
|
10
|
+
gem 'progress_bar', '~> 1.0.5', require: false
|
11
|
+
gem 'rspec', '~> 3.4.0'
|
12
|
+
gem 'rspec-rails', '~> 3.4.0'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
if ruby_version < Gem::Version.new('2.4.0')
|
18
|
+
appraise 'rails-3.2.0' do
|
19
|
+
gem 'bundler', '>= 1.3.0', '< 2.0'
|
20
|
+
gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME'])
|
21
|
+
gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME'])
|
22
|
+
gem 'rails', '~> 3.2.0'
|
23
|
+
gem 'progress_bar', '~> 1.0.5', require: false
|
24
|
+
gem 'test-unit', '~> 3.2.0'
|
25
|
+
gem 'rspec', '~> 3.4.0'
|
26
|
+
gem 'rspec-rails', '~> 3.4.0'
|
27
|
+
end
|
28
|
+
|
29
|
+
['4.0.0', '4.1.0'].each do |rails_version|
|
30
|
+
appraise "rails-#{rails_version}" do
|
31
|
+
gem 'bundler', '>= 1.3.0', '< 2.0'
|
32
|
+
gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME'])
|
33
|
+
gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME'])
|
34
|
+
gem 'rails', "~> #{rails_version}"
|
35
|
+
gem 'progress_bar', '~> 1.0.5', require: false
|
36
|
+
gem 'rspec', '~> 3.4.0'
|
37
|
+
gem 'rspec-rails', '~> 3.4.0'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if ruby_version < Gem::Version.new('2.5.0')
|
43
|
+
appraise 'rails-4.2.0' do
|
44
|
+
gem 'bundler', '>= 1.3.0', '< 2.0'
|
45
|
+
gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME'])
|
46
|
+
gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME'])
|
47
|
+
gem 'rails', '~> 4.2.0'
|
48
|
+
gem 'progress_bar', '~> 1.0.5', require: false
|
49
|
+
gem 'rspec', '~> 3.4.0'
|
50
|
+
gem 'rspec-rails', '~> 3.4.0'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
if ruby_version >= Gem::Version.new('2.2.0')
|
55
|
+
['5.0.0', '5.1.0', '5.2.0'].each do |rails_version|
|
56
|
+
appraise "rails-#{rails_version}" do
|
57
|
+
gem 'sunspot', path: File.expand_path('sunspot', ENV['SUNSPOT_LIB_HOME'])
|
58
|
+
gem 'sunspot_solr', path: File.expand_path('sunspot_solr', ENV['SUNSPOT_LIB_HOME'])
|
59
|
+
gem 'rails', "~> #{rails_version}"
|
60
|
+
gem 'sprockets', '~> 3.0'
|
61
|
+
gem 'progress_bar', '~> 1.0.5', require: false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/Gemfile
ADDED
@@ -301,6 +301,10 @@ module Sunspot #:nodoc:
|
|
301
301
|
@open_timeout ||= user_configuration_from_key('solr', 'open_timeout')
|
302
302
|
end
|
303
303
|
|
304
|
+
def update_format
|
305
|
+
@update_format ||= user_configuration_from_key('solr', 'update_format')
|
306
|
+
end
|
307
|
+
|
304
308
|
def proxy
|
305
309
|
@proxy ||= user_configuration_from_key('solr', 'proxy')
|
306
310
|
end
|
@@ -20,8 +20,10 @@ module Sunspot #:nodoc:
|
|
20
20
|
# this case, since after_filter uses the inheritable_attribute
|
21
21
|
# structure, the already-loaded subclasses don't get the filters. So,
|
22
22
|
# the below ensures that all loaded controllers have the filter.
|
23
|
+
callback = ::Rails::VERSION::MAJOR > 3 ? :after_action : :after_filter
|
24
|
+
|
23
25
|
loaded_controllers.each do |controller|
|
24
|
-
controller.
|
26
|
+
controller.send(callback) do
|
25
27
|
if Sunspot::Rails.configuration.auto_commit_after_request?
|
26
28
|
Sunspot.commit_if_dirty
|
27
29
|
elsif Sunspot::Rails.configuration.auto_commit_after_delete_request?
|
@@ -99,9 +99,15 @@ module Sunspot #:nodoc:
|
|
99
99
|
|
100
100
|
unless options[:auto_remove] == false
|
101
101
|
# after_commit { |searchable| searchable.remove_from_index }, :on => :destroy
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
# Only add the on filter if the callback supports it
|
103
|
+
if Sunspot::Rails.configuration.auto_remove_callback =~ /save|destroy|create/
|
104
|
+
__send__ Sunspot::Rails.configuration.auto_remove_callback,
|
105
|
+
proc { |searchable| searchable.remove_from_index }
|
106
|
+
else
|
107
|
+
__send__ Sunspot::Rails.configuration.auto_remove_callback,
|
108
|
+
proc { |searchable| searchable.remove_from_index },
|
109
|
+
:on => :destroy
|
110
|
+
end
|
105
111
|
end
|
106
112
|
options[:include] = Util::Array(options[:include])
|
107
113
|
|
@@ -258,7 +264,7 @@ module Sunspot #:nodoc:
|
|
258
264
|
|
259
265
|
if options[:batch_size].to_i > 0
|
260
266
|
batch_counter = 0
|
261
|
-
self.includes(options[:include]).find_in_batches(options.slice(:batch_size, :start)) do |records|
|
267
|
+
self.includes(options[:include]).find_in_batches(**options.slice(:batch_size, :start)) do |records|
|
262
268
|
|
263
269
|
solr_benchmark(options[:batch_size], batch_counter += 1) do
|
264
270
|
Sunspot.index(records.select(&:indexable?))
|
@@ -281,7 +287,7 @@ module Sunspot #:nodoc:
|
|
281
287
|
#
|
282
288
|
# ==== Updates (passed as a hash)
|
283
289
|
#
|
284
|
-
# updates should be specified as a hash, where key - is the object ID
|
290
|
+
# updates should be specified as a hash, where key - is the object or the object ID
|
285
291
|
# and values is hash with property name/values to be updated.
|
286
292
|
#
|
287
293
|
# ==== Examples
|
@@ -297,6 +303,8 @@ module Sunspot #:nodoc:
|
|
297
303
|
#
|
298
304
|
# # update single property
|
299
305
|
# Post.atomic_update(post1.id => {description: 'New post description'})
|
306
|
+
# Or
|
307
|
+
# Post.atomic_update(post1 => {description: 'New post description'})
|
300
308
|
#
|
301
309
|
# ==== Notice
|
302
310
|
# all non-stored properties in Solr index will be lost after update.
|
@@ -447,7 +455,7 @@ module Sunspot #:nodoc:
|
|
447
455
|
# you only need to pass hash with property changes
|
448
456
|
#
|
449
457
|
def solr_atomic_update(updates = {})
|
450
|
-
Sunspot.atomic_update(self.class, self
|
458
|
+
Sunspot.atomic_update(self.class, self => updates)
|
451
459
|
end
|
452
460
|
|
453
461
|
#
|
@@ -455,7 +463,7 @@ module Sunspot #:nodoc:
|
|
455
463
|
# See #solr_atomic_update
|
456
464
|
#
|
457
465
|
def solr_atomic_update!(updates = {})
|
458
|
-
Sunspot.atomic_update!(self.class, self
|
466
|
+
Sunspot.atomic_update!(self.class, self => updates)
|
459
467
|
end
|
460
468
|
|
461
469
|
#
|
@@ -4,10 +4,10 @@ module Sunspot
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
|
7
|
+
alias_method :send_and_receive_without_as_instrumentation, :send_and_receive
|
8
|
+
alias_method :send_and_receive, :send_and_receive_with_as_instrumentation
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
11
|
def send_and_receive_with_as_instrumentation(path, opts)
|
12
12
|
parameters = (opts[:params] || {})
|
13
13
|
parameters.merge!(opts[:data]) if opts[:data].is_a? Hash
|
@@ -2,28 +2,21 @@ module Sunspot
|
|
2
2
|
module Rails
|
3
3
|
module SolrLogging
|
4
4
|
|
5
|
-
class <<self
|
6
|
-
def included(base)
|
7
|
-
base.alias_method_chain :execute, :rails_logging
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
5
|
COMMIT = %r{<commit/>}
|
12
6
|
|
13
|
-
def execute_with_rails_logging(
|
7
|
+
def execute_with_rails_logging(request_context)
|
14
8
|
body = (request_context[:data]||"").dup
|
15
9
|
action = request_context[:path].capitalize
|
16
10
|
if body =~ COMMIT
|
17
11
|
action = "Commit"
|
18
12
|
body = ""
|
19
13
|
end
|
20
|
-
body = body[0, 800] + '...' if body.length > 800
|
21
14
|
|
22
15
|
# Make request and log.
|
23
16
|
response = nil
|
24
17
|
begin
|
25
18
|
ms = Benchmark.ms do
|
26
|
-
response = execute_without_rails_logging(
|
19
|
+
response = execute_without_rails_logging(request_context)
|
27
20
|
end
|
28
21
|
log_name = 'Solr %s (%.1fms)' % [action, ms]
|
29
22
|
::Rails.logger.debug(format_log_entry(log_name, body))
|
@@ -54,6 +47,8 @@ module Sunspot
|
|
54
47
|
end
|
55
48
|
end
|
56
49
|
|
57
|
-
RSolr::
|
50
|
+
RSolr::Client.class_eval do
|
58
51
|
include Sunspot::Rails::SolrLogging
|
52
|
+
alias_method :execute_without_rails_logging, :execute
|
53
|
+
alias_method :execute, :execute_with_rails_logging
|
59
54
|
end
|
@@ -44,6 +44,10 @@ module Sunspot
|
|
44
44
|
def optimize
|
45
45
|
end
|
46
46
|
|
47
|
+
def config
|
48
|
+
Sunspot::Configuration.build
|
49
|
+
end
|
50
|
+
|
47
51
|
def dirty?
|
48
52
|
false
|
49
53
|
end
|
@@ -104,7 +108,7 @@ module Sunspot
|
|
104
108
|
[]
|
105
109
|
end
|
106
110
|
|
107
|
-
def facet(name)
|
111
|
+
def facet(name, dynamic_name = nil)
|
108
112
|
FacetStub.new
|
109
113
|
end
|
110
114
|
|
@@ -123,6 +127,9 @@ module Sunspot
|
|
123
127
|
def execute
|
124
128
|
self
|
125
129
|
end
|
130
|
+
|
131
|
+
def spellcheck_collation
|
132
|
+
end
|
126
133
|
end
|
127
134
|
|
128
135
|
|
@@ -219,7 +226,7 @@ module Sunspot
|
|
219
226
|
[]
|
220
227
|
end
|
221
228
|
|
222
|
-
def facet(name)
|
229
|
+
def facet(name, dynamic_name = nil)
|
223
230
|
FacetStub.new
|
224
231
|
end
|
225
232
|
|
data/lib/sunspot/rails/tasks.rb
CHANGED
@@ -31,7 +31,6 @@ namespace :sunspot do
|
|
31
31
|
# Load all the application's models. Models which invoke 'searchable' will register themselves
|
32
32
|
# in Sunspot.searchable.
|
33
33
|
Rails.application.eager_load!
|
34
|
-
Rails::Engine.subclasses.each{|engine| engine.instance.eager_load!}
|
35
34
|
|
36
35
|
if args[:models].present?
|
37
36
|
# Choose a specific subset of models, if requested
|
data/lib/sunspot/rails.rb
CHANGED
@@ -53,6 +53,7 @@ module Sunspot #:nodoc:
|
|
53
53
|
config.solr.read_timeout = sunspot_rails_configuration.read_timeout
|
54
54
|
config.solr.open_timeout = sunspot_rails_configuration.open_timeout
|
55
55
|
config.solr.proxy = sunspot_rails_configuration.proxy
|
56
|
+
config.solr.update_format = sunspot_rails_configuration.update_format
|
56
57
|
config
|
57
58
|
end
|
58
59
|
|
@@ -68,6 +69,7 @@ module Sunspot #:nodoc:
|
|
68
69
|
config.solr.read_timeout = sunspot_rails_configuration.read_timeout
|
69
70
|
config.solr.open_timeout = sunspot_rails_configuration.open_timeout
|
70
71
|
config.solr.proxy = sunspot_rails_configuration.proxy
|
72
|
+
config.solr.update_format = sunspot_rails_configuration.update_format
|
71
73
|
config
|
72
74
|
end
|
73
75
|
end
|