sunspot_rails 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +6 -1
- data/README.rdoc +0 -26
- data/dev_tasks/spec.rake +15 -24
- data/gemfiles/{rails-2.3.16 → rails-3.0.0} +11 -5
- data/gemfiles/{rails-3.0.20 → rails-3.1.0} +11 -4
- data/gemfiles/{rails-3.1.10 → rails-3.2.0} +11 -4
- data/gemfiles/rails-4.0.0 +20 -0
- data/generators/sunspot/templates/sunspot.yml +7 -4
- data/lib/generators/sunspot_rails/install/templates/config/sunspot.yml +4 -0
- data/lib/sunspot/rails/adapters.rb +12 -11
- data/lib/sunspot/rails/configuration.rb +2 -2
- data/lib/sunspot/rails/log_subscriber.rb +11 -6
- data/lib/sunspot/rails/railtie.rb +1 -1
- data/lib/sunspot/rails/searchable.rb +10 -15
- data/lib/sunspot/rails/solr_instrumentation.rb +7 -5
- data/lib/sunspot/rails/solr_logging.rb +2 -5
- data/lib/sunspot/rails/stub_session_proxy.rb +14 -0
- data/lib/sunspot/rails/tasks.rb +47 -42
- data/lib/sunspot_rails.rb +2 -7
- data/spec/configuration_spec.rb +10 -10
- data/spec/model_spec.rb +38 -29
- data/spec/rails_template/app/models/post_with_default_scope.rb +3 -1
- data/spec/rails_template/app/models/rake_task_auto_load_test_model.rb +13 -0
- data/spec/rails_template/config/database.yml +11 -0
- data/spec/rails_template/config/routes.rb +3 -9
- data/spec/rake_task_spec.rb +40 -0
- data/spec/searchable_spec.rb +3 -0
- data/spec/session_spec.rb +1 -1
- data/spec/spec_helper.rb +59 -32
- data/spec/stub_session_proxy_spec.rb +8 -4
- data/sunspot_rails.gemspec +1 -0
- metadata +42 -22
- data/gemfiles/rails-3.2.11 +0 -12
- data/spec/rails_template/config/boot.rb +0 -127
- data/spec/rails_template/config/preinitializer.rb +0 -22
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 2.1.0
|
2
|
+
* Dropped Rails 2 support in favour of supporting Rails 4
|
3
|
+
* Passing :silence => true while invoking sunspot:reindex task will no longer show the Progress Bar
|
4
|
+
* Model names can now also be delimited with spaces when passing them the sunspot:reindex task
|
5
|
+
|
1
6
|
== 2.0.0
|
2
7
|
* Finds orphaned objects in batches to avoid excessive memory use (Peer Allan)
|
3
8
|
* Default batch size can be specified by setting `Sunspot.config.indexing.default_batch_size`
|
@@ -67,7 +72,7 @@
|
|
67
72
|
== 0.10.6
|
68
73
|
* Added script/generate sunspot support to generate the required sunspot.yml
|
69
74
|
file [Brandon Keepers]
|
70
|
-
|
75
|
+
|
71
76
|
== 0.10.5
|
72
77
|
* Added a auto_commit_after_request option to sunspot.yml. Sunspot will not
|
73
78
|
automatically commit any changes in solr if you set this value to false.
|
data/README.rdoc
CHANGED
@@ -26,32 +26,6 @@ In your <code>Gemfile</code>:
|
|
26
26
|
gem 'sunspot_solr'
|
27
27
|
end
|
28
28
|
|
29
|
-
== Installation in Rails 2
|
30
|
-
|
31
|
-
In your project's <code>config/environment.rb</code>, add the following gem dependencies:
|
32
|
-
|
33
|
-
config.gem 'sunspot'
|
34
|
-
config.gem 'sunspot_rails'
|
35
|
-
|
36
|
-
And in your project's <code>config/development.rb</code> and <code>config/test.rb</code>,
|
37
|
-
add the following gem dependency to install the optional packaged Solr:
|
38
|
-
|
39
|
-
config.gem 'sunspot_solr'
|
40
|
-
|
41
|
-
Install the gems with:
|
42
|
-
|
43
|
-
rake gems:install
|
44
|
-
|
45
|
-
Generate the file <code>config/sunspot.yml</code>:
|
46
|
-
|
47
|
-
script/generate sunspot
|
48
|
-
|
49
|
-
Rails doesn't automatically load rake tasks from plugins installed as gems
|
50
|
-
(https://rails.lighthouseapp.com/projects/8994/tickets/59). If you installed
|
51
|
-
Sunspot::Rails as a gem, add the following line to your project's Rakefile:
|
52
|
-
|
53
|
-
require 'sunspot/rails/tasks'
|
54
|
-
|
55
29
|
== Using Sunspot::Rails
|
56
30
|
|
57
31
|
If you wish to make modifications to the Solr schema, you can create a custom
|
data/dev_tasks/spec.rake
CHANGED
@@ -17,11 +17,13 @@ namespace :spec do
|
|
17
17
|
File.join(File.dirname(__FILE__), "..", "spec", "rails_template")
|
18
18
|
end
|
19
19
|
|
20
|
-
|
20
|
+
def version
|
21
|
+
ENV['VERSION']
|
22
|
+
end
|
21
23
|
|
22
|
-
task :set_gemfile
|
23
|
-
version = ENV['VERSION']
|
24
|
+
task :run_with_rails => [:set_gemfile, :generate_rails_app, :initialize_database, :setup_rails_app, :run]
|
24
25
|
|
26
|
+
task :set_gemfile do
|
25
27
|
ENV['BUNDLE_PATH'] = vendor_path(version)
|
26
28
|
ENV['BUNDLE_GEMFILE'] = gemfile_path(version)
|
27
29
|
|
@@ -32,41 +34,30 @@ namespace :spec do
|
|
32
34
|
end
|
33
35
|
|
34
36
|
task :generate_rails_app do
|
35
|
-
version = ENV['VERSION']
|
36
37
|
app_path = rails_app_path(version)
|
37
38
|
|
38
39
|
unless File.exist?(File.expand_path("config/environment.rb", app_path))
|
39
|
-
rails_cmd = "bundle exec rails _#{version}_"
|
40
|
-
|
41
40
|
puts "Generating Rails #{version} application..."
|
42
|
-
|
43
|
-
sh("#{rails_cmd} \"#{app_path}\" --force") || exit(1)
|
44
|
-
elsif version.start_with?("3")
|
45
|
-
sh("#{rails_cmd} new \"#{app_path}\" --force --skip-git --skip-javascript --skip-gemfile --skip-sprockets") || exit(1)
|
46
|
-
end
|
41
|
+
sh("bundle exec rails _#{version}_ new \"#{app_path}\" --force --skip-git --skip-javascript --skip-gemfile --skip-sprockets") || exit(1)
|
47
42
|
end
|
48
43
|
end
|
49
44
|
|
50
|
-
task :
|
51
|
-
|
52
|
-
|
45
|
+
task :initialize_database do
|
46
|
+
if ENV['DB'] == 'postgres'
|
47
|
+
sh "psql -c 'DROP DATABASE IF EXISTS sunspot_test;' -d template1"
|
48
|
+
sh "psql -c 'create database sunspot_test;' -d template1"
|
49
|
+
end
|
50
|
+
end
|
53
51
|
|
54
|
-
|
52
|
+
task :setup_rails_app do
|
53
|
+
FileUtils.cp_r File.join(rails_template_path, "."), rails_app_path(version)
|
55
54
|
end
|
56
55
|
|
57
56
|
task :run do
|
58
|
-
version = ENV['VERSION']
|
59
|
-
|
60
57
|
ENV['BUNDLE_GEMFILE'] = gemfile_path(version)
|
61
58
|
ENV['RAILS_ROOT'] = rails_app_path(version)
|
62
59
|
|
63
|
-
|
64
|
-
"spec"
|
65
|
-
elsif version.start_with?("3")
|
66
|
-
"rspec"
|
67
|
-
end
|
68
|
-
|
69
|
-
sh "bundle exec #{spec_command} #{ENV['SPEC'] || 'spec/*_spec.rb'} --color"
|
60
|
+
sh "bundle exec rspec #{ENV['SPEC'] || 'spec/*_spec.rb'} --color"
|
70
61
|
end
|
71
62
|
end
|
72
63
|
|
@@ -1,13 +1,19 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rails', '
|
4
|
-
gem 'sqlite3', '~> 1.3.7'
|
3
|
+
gem 'rails', '~> 3.0.0'
|
5
4
|
|
6
5
|
gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
|
7
6
|
gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
|
8
7
|
gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
|
9
8
|
|
10
9
|
group :test do
|
11
|
-
gem 'rspec-rails', '~>
|
12
|
-
gem 'test-unit', '~> 1.2.3', :platform => :mri_19
|
10
|
+
gem 'rspec-rails', '~> 2.14.0'
|
13
11
|
end
|
12
|
+
|
13
|
+
group :postgres do
|
14
|
+
gem 'pg'
|
15
|
+
end
|
16
|
+
|
17
|
+
group :sqlite do
|
18
|
+
gem 'sqlite3', '~> 1.3.7'
|
19
|
+
end
|
@@ -1,12 +1,19 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rails', '3.0
|
4
|
-
gem 'sqlite3', '~> 1.3.7'
|
3
|
+
gem 'rails', '~> 3.1.0'
|
5
4
|
|
6
5
|
gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
|
7
6
|
gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
|
8
7
|
gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
|
9
8
|
|
10
9
|
group :test do
|
11
|
-
gem 'rspec-rails', '~> 2.
|
10
|
+
gem 'rspec-rails', '~> 2.14.0'
|
12
11
|
end
|
12
|
+
|
13
|
+
group :postgres do
|
14
|
+
gem 'pg'
|
15
|
+
end
|
16
|
+
|
17
|
+
group :sqlite do
|
18
|
+
gem 'sqlite3', '~> 1.3.7'
|
19
|
+
end
|
@@ -1,12 +1,19 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
gem 'rails', '3.
|
4
|
-
gem 'sqlite3', '~> 1.3.7'
|
3
|
+
gem 'rails', '~> 3.2.0'
|
5
4
|
|
6
5
|
gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
|
7
6
|
gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
|
8
7
|
gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
|
9
8
|
|
10
9
|
group :test do
|
11
|
-
gem 'rspec-rails', '~> 2.
|
10
|
+
gem 'rspec-rails', '~> 2.14.0'
|
12
11
|
end
|
12
|
+
|
13
|
+
group :postgres do
|
14
|
+
gem 'pg'
|
15
|
+
end
|
16
|
+
|
17
|
+
group :sqlite do
|
18
|
+
gem 'sqlite3', '~> 1.3.7'
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
source 'http://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 4.0.0'
|
4
|
+
|
5
|
+
gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
|
6
|
+
gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
|
7
|
+
gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
|
8
|
+
|
9
|
+
group :test do
|
10
|
+
gem 'protected_attributes' # Rails 4 support for attr_accessor so specs still work
|
11
|
+
gem 'rspec-rails', '~> 2.14.0'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :postgres do
|
15
|
+
gem 'pg'
|
16
|
+
end
|
17
|
+
|
18
|
+
group :sqlite do
|
19
|
+
gem 'sqlite3', '~> 1.3.7'
|
20
|
+
end
|
@@ -3,18 +3,21 @@ production:
|
|
3
3
|
hostname: localhost
|
4
4
|
port: 8983
|
5
5
|
log_level: WARNING
|
6
|
-
|
7
|
-
|
6
|
+
path: /solr/production
|
7
|
+
read_timeout: 20
|
8
|
+
open_timeout: 1
|
8
9
|
|
9
10
|
development:
|
10
11
|
solr:
|
11
12
|
hostname: localhost
|
12
|
-
port:
|
13
|
+
port: 8983
|
13
14
|
log_level: INFO
|
15
|
+
path: /solr/development
|
14
16
|
|
15
17
|
test:
|
16
18
|
solr:
|
17
19
|
hostname: localhost
|
18
|
-
port:
|
20
|
+
port: 8983
|
19
21
|
log_level: WARNING
|
22
|
+
path: /solr/test
|
20
23
|
|
@@ -3,6 +3,7 @@ production:
|
|
3
3
|
hostname: localhost
|
4
4
|
port: 8983
|
5
5
|
log_level: WARNING
|
6
|
+
path: /solr/production
|
6
7
|
# read_timeout: 2
|
7
8
|
# open_timeout: 0.5
|
8
9
|
|
@@ -11,9 +12,12 @@ development:
|
|
11
12
|
hostname: localhost
|
12
13
|
port: 8982
|
13
14
|
log_level: INFO
|
15
|
+
path: /solr/development
|
14
16
|
|
15
17
|
test:
|
16
18
|
solr:
|
17
19
|
hostname: localhost
|
18
20
|
port: 8981
|
19
21
|
log_level: WARNING
|
22
|
+
path: /solr/test
|
23
|
+
|
@@ -53,9 +53,7 @@ module Sunspot #:nodoc:
|
|
53
53
|
# ActiveRecord::Base:: ActiveRecord model
|
54
54
|
#
|
55
55
|
def load(id)
|
56
|
-
@clazz.
|
57
|
-
:conditions => { @clazz.primary_key => id}
|
58
|
-
))
|
56
|
+
@clazz.where(@clazz.primary_key => id).merge(scope_for_load).first
|
59
57
|
end
|
60
58
|
|
61
59
|
#
|
@@ -70,18 +68,21 @@ module Sunspot #:nodoc:
|
|
70
68
|
# Array:: Collection of ActiveRecord models
|
71
69
|
#
|
72
70
|
def load_all(ids)
|
73
|
-
@clazz.
|
74
|
-
:conditions => { @clazz.primary_key => ids.map { |id| id }}
|
75
|
-
))
|
71
|
+
@clazz.where(@clazz.primary_key => ids).merge(scope_for_load)
|
76
72
|
end
|
77
73
|
|
78
74
|
private
|
79
75
|
|
80
|
-
def
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
76
|
+
def scope_for_load
|
77
|
+
scope = relation
|
78
|
+
scope = scope.includes(@include) if @include.present?
|
79
|
+
scope = scope.select(@select) if @select.present?
|
80
|
+
scope
|
81
|
+
end
|
82
|
+
|
83
|
+
# COMPATIBILITY: Rails 4 has deprecated the 'scoped' method in favour of 'all'
|
84
|
+
def relation
|
85
|
+
::Rails.version >= '4' ? @clazz.all : @clazz.scoped
|
85
86
|
end
|
86
87
|
end
|
87
88
|
end
|
@@ -88,7 +88,7 @@ module Sunspot #:nodoc:
|
|
88
88
|
|
89
89
|
#
|
90
90
|
# The url path to the Solr servlet (useful if you are running multicore).
|
91
|
-
# Default '/solr'.
|
91
|
+
# Default '/solr/default'.
|
92
92
|
#
|
93
93
|
# ==== Returns
|
94
94
|
#
|
@@ -352,7 +352,7 @@ module Sunspot #:nodoc:
|
|
352
352
|
end
|
353
353
|
|
354
354
|
def default_path
|
355
|
-
'/solr'
|
355
|
+
'/solr/default'
|
356
356
|
end
|
357
357
|
|
358
358
|
end
|
@@ -13,15 +13,15 @@ module Sunspot
|
|
13
13
|
rt, self.runtime = runtime, 0
|
14
14
|
rt
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def self.logger=(logger)
|
18
18
|
@logger = logger
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.logger
|
22
22
|
@logger if defined?(@logger)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def logger
|
26
26
|
self.class.logger || ::Rails.logger
|
27
27
|
end
|
@@ -32,9 +32,14 @@ module Sunspot
|
|
32
32
|
|
33
33
|
name = '%s (%.1fms)' % ["SOLR Request", event.duration]
|
34
34
|
|
35
|
-
# produces: path
|
36
|
-
|
37
|
-
|
35
|
+
# produces: path=select parameters={fq: ["type:Tag"], q: "rossi", fl: "* score", qf: "tag_name_text", defType: "edismax", start: 0, rows: 20}
|
36
|
+
path = color(event.payload[:path], BOLD, true)
|
37
|
+
parameters = event.payload[:parameters].map { |k, v|
|
38
|
+
v = "\"#{v}\"" if v.is_a? String
|
39
|
+
v = v.to_s.gsub(/\\/,'') # unescape
|
40
|
+
"#{k}: #{color(v, BOLD, true)}"
|
41
|
+
}.join(', ')
|
42
|
+
request = "path=#{path} parameters={#{parameters}}"
|
38
43
|
|
39
44
|
debug " #{color(name, GREEN, true)} [ #{request} ]"
|
40
45
|
end
|
@@ -12,7 +12,7 @@ module Sunspot
|
|
12
12
|
include(Sunspot::Rails::RequestLifecycle)
|
13
13
|
end
|
14
14
|
require 'sunspot/rails/log_subscriber'
|
15
|
-
RSolr::
|
15
|
+
RSolr::Client.class_eval{ include Sunspot::Rails::SolrInstrumentation }
|
16
16
|
end
|
17
17
|
|
18
18
|
# Expose database runtime to controller for logging.
|
@@ -246,29 +246,24 @@ module Sunspot #:nodoc:
|
|
246
246
|
:batch_size => Sunspot.config.indexing.default_batch_size,
|
247
247
|
:batch_commit => true,
|
248
248
|
:include => self.sunspot_options[:include],
|
249
|
-
:start => opts.delete(:first_id)
|
249
|
+
:start => opts.delete(:first_id)
|
250
250
|
}.merge(opts)
|
251
|
-
|
252
|
-
|
253
|
-
:batch_size => options[:batch_size],
|
254
|
-
:start => options[:start]
|
255
|
-
}
|
256
|
-
progress_bar = options[:progress_bar]
|
257
|
-
if options[:batch_size]
|
251
|
+
|
252
|
+
if options[:batch_size].to_i > 0
|
258
253
|
batch_counter = 0
|
259
|
-
find_in_batches(
|
260
|
-
|
254
|
+
self.includes(options[:include]).find_in_batches(options.slice(:batch_size, :start)) do |records|
|
255
|
+
|
256
|
+
solr_benchmark(options[:batch_size], batch_counter += 1) do
|
261
257
|
Sunspot.index(records.select { |model| model.indexable? })
|
262
258
|
Sunspot.commit if options[:batch_commit]
|
263
259
|
end
|
264
|
-
|
265
|
-
progress_bar.increment!(records.length) if progress_bar
|
266
|
-
batch_counter += 1
|
260
|
+
|
261
|
+
options[:progress_bar].increment!(records.length) if options[:progress_bar]
|
267
262
|
end
|
268
263
|
else
|
269
|
-
|
270
|
-
Sunspot.index!(records)
|
264
|
+
Sunspot.index! self.includes(options[:include]).select(&:indexable?)
|
271
265
|
end
|
266
|
+
|
272
267
|
# perform a final commit if not committing in batches
|
273
268
|
Sunspot.commit unless options[:batch_commit]
|
274
269
|
end
|
@@ -4,14 +4,16 @@ module Sunspot
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
alias_method_chain :
|
7
|
+
alias_method_chain :send_and_receive, :as_instrumentation
|
8
8
|
end
|
9
9
|
|
10
10
|
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def send_and_receive_with_as_instrumentation(path, opts)
|
12
|
+
parameters = (opts[:params] || {})
|
13
|
+
parameters.merge!(opts[:data]) if opts[:data].is_a? Hash
|
14
|
+
payload = {:path => path, :parameters => parameters}
|
15
|
+
ActiveSupport::Notifications.instrument("request.rsolr", payload) do
|
16
|
+
send_and_receive_without_as_instrumentation(path, opts)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
end
|
@@ -39,11 +39,8 @@ module Sunspot
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def format_log_entry(message, dump = nil)
|
42
|
-
@colorize_logging ||=
|
43
|
-
|
44
|
-
rescue NoMethodError
|
45
|
-
ActiveRecord::Base.colorize_logging # Rails 2
|
46
|
-
end
|
42
|
+
@colorize_logging ||= ::Rails.application.config.colorize_logging
|
43
|
+
|
47
44
|
if @colorize_logging
|
48
45
|
message_color, dump_color = "4;32;1", "0;1"
|
49
46
|
log_entry = " \e[#{message_color}m#{message}\e[0m "
|