erichummel-sunspot_rails 1.2.1g → 2.0.0.pre.111215

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +1 -0
  3. data/History.txt +23 -0
  4. data/README.rdoc +14 -7
  5. data/Rakefile +6 -7
  6. data/dev_tasks/rdoc.rake +2 -2
  7. data/dev_tasks/spec.rake +103 -18
  8. data/gemfiles/rails-2.3.14 +12 -0
  9. data/gemfiles/rails-3.0.11 +12 -0
  10. data/gemfiles/rails-3.1.3 +12 -0
  11. data/gemfiles/rails-3.2.1 +12 -0
  12. data/generators/sunspot/templates/sunspot.yml +3 -1
  13. data/lib/generators/sunspot_rails/install/templates/config/sunspot.yml +3 -1
  14. data/lib/sunspot/rails.rb +14 -3
  15. data/lib/sunspot/rails/configuration.rb +36 -3
  16. data/lib/sunspot/rails/log_subscriber.rb +33 -0
  17. data/lib/sunspot/rails/railtie.rb +10 -0
  18. data/lib/sunspot/rails/railties/controller_runtime.rb +36 -0
  19. data/lib/sunspot/rails/searchable.rb +104 -25
  20. data/lib/sunspot/rails/server.rb +10 -76
  21. data/lib/sunspot/rails/solr_instrumentation.rb +19 -0
  22. data/lib/sunspot/rails/solr_logging.rb +16 -17
  23. data/lib/sunspot/rails/stub_session_proxy.rb +56 -2
  24. data/lib/sunspot/rails/tasks.rb +56 -33
  25. data/lib/sunspot_rails.rb +5 -0
  26. data/spec/configuration_spec.rb +41 -5
  27. data/spec/model_lifecycle_spec.rb +1 -1
  28. data/spec/model_spec.rb +246 -1
  29. data/spec/rails_template/app/controllers/application_controller.rb +10 -0
  30. data/spec/rails_template/app/controllers/posts_controller.rb +6 -0
  31. data/spec/rails_template/app/models/author.rb +8 -0
  32. data/spec/rails_template/app/models/blog.rb +12 -0
  33. data/spec/rails_template/app/models/location.rb +2 -0
  34. data/spec/rails_template/app/models/photo_post.rb +2 -0
  35. data/spec/rails_template/app/models/post.rb +11 -0
  36. data/spec/rails_template/app/models/post_with_auto.rb +10 -0
  37. data/spec/rails_template/app/models/post_with_default_scope.rb +11 -0
  38. data/spec/rails_template/config/boot.rb +127 -0
  39. data/spec/rails_template/config/preinitializer.rb +22 -0
  40. data/spec/rails_template/config/routes.rb +9 -0
  41. data/spec/rails_template/config/sunspot.yml +24 -0
  42. data/spec/rails_template/db/schema.rb +27 -0
  43. data/spec/request_lifecycle_spec.rb +1 -1
  44. data/spec/searchable_spec.rb +12 -0
  45. data/spec/server_spec.rb +3 -7
  46. data/spec/session_spec.rb +35 -2
  47. data/spec/shared_examples/indexed_after_save.rb +8 -0
  48. data/spec/shared_examples/not_indexed_after_save.rb +8 -0
  49. data/spec/spec_helper.rb +4 -2
  50. data/spec/stub_session_proxy_spec.rb +2 -2
  51. data/sunspot_rails.gemspec +43 -0
  52. metadata +144 -87
  53. data/TESTING.md +0 -35
  54. data/VERSION.yml +0 -4
  55. data/lib/sunspot/rails/version.rb +0 -5
@@ -0,0 +1,7 @@
1
+ sunspot-solr.pid
2
+ doc
3
+ pkg/*
4
+ log
5
+ .bundle
6
+ tmp/*
7
+ gemfiles/*.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -1,3 +1,26 @@
1
+ == 2.0.0
2
+ * Finds orphaned objects in batches to avoid excessive memory use (Peer Allan)
3
+ * Default batch size can be specified by setting `Sunspot.config.indexing.default_batch_size`
4
+ (Peer Allan)
5
+ * Explanation of `progress_bar` is written to stdout instead of stderr (Matt Gornick)
6
+ * Fixes deprecated behavior of using InstanceMethods module with
7
+ ActiveSupport::Concern (Everton J. Carpes)
8
+
9
+ == 1.3.0 2011-11-26
10
+ * `Model.index` correctly uses `:first_id` option (Hamza Khan-Cheema)
11
+ * Solr request performance is instrumented in Rails (Paco Guzmán)
12
+ * Reindexing tasks display a progress bar if `progress_bar` gem is available (Paul Carey)
13
+ * Deprecated Rails syntax is removed from `Sunspot::Rails::Searchable` (Steve Schwartz)
14
+ * Deprecated syntax is removed from rake tasks (Huned Botee)
15
+ * `sunspot:reindex` rake task correctly handles namespaced models (João Gradim)
16
+ * `bind_address` parameter can be specified in `sunspot.yml` to bind Solr to a
17
+ specific interface (Sylvain Utard)
18
+ * `disabled` parameter can be specified in `sunspot.yml` to stub out the
19
+ connection to Solr (David B)
20
+
21
+ == 1.2.1 2010-12-28
22
+ * Decreased default reindexing batch size from 500 to 50
23
+
1
24
  == 1.2.0 2010-12-28
2
25
  * Compatible with both Rails 2 and Rails 3
3
26
  * Configure Sunspot with a SOLR_URL or WEBSOLR_URL environment variable, also
@@ -21,6 +21,10 @@ Sunspot::Rails has been tested with Rails versions 2.3 and 3.0
21
21
  In your <code>Gemfile</code>:
22
22
 
23
23
  gem 'sunspot_rails'
24
+ # This is an optional packaged Solr:
25
+ group :test, :development do
26
+ gem 'sunspot_solr'
27
+ end
24
28
 
25
29
  == Installation in Rails 2
26
30
 
@@ -28,7 +32,12 @@ In your project's <code>config/environment.rb</code>, add the following gem depe
28
32
 
29
33
  config.gem 'sunspot'
30
34
  config.gem 'sunspot_rails'
31
-
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
+
32
41
  Install the gems with:
33
42
 
34
43
  rake gems:install
@@ -53,7 +62,8 @@ Sunspot::Rails will detect them and tell Solr to use your local configurations.
53
62
  Use caution when modifying <code>schema.xml</code> - Sunspot relies on the
54
63
  field naming scheme in the packaged schema file.
55
64
 
56
- To start up a Solr instance, issue the following:
65
+ To start up a Solr instance, issue the following (requires sunspot_solr to be
66
+ installed):
57
67
 
58
68
  rake sunspot:solr:start
59
69
 
@@ -148,7 +158,6 @@ without actually loading the models out of the database. For that, you can
148
158
  call +search_ids+, using the same block format as #search. This will return an
149
159
  array of IDs.
150
160
 
151
-
152
161
  === Searching for multiple types
153
162
 
154
163
  Sunspot is entirely agnostic about whether searches are for one or more types;
@@ -205,7 +214,6 @@ remove those documents from the index, use +clean_index_orphans+. Note that
205
214
  neither of these operations should be needed if Sunspot and Sunspot::Rails are
206
215
  used as intended.
207
216
 
208
-
209
217
  == Testing Solr integration using RSpec
210
218
 
211
219
  To disable the sunspot-solr integration for your active record models, require
@@ -217,7 +225,7 @@ Then, in your spec, use the #disconnect_sunspot method:
217
225
 
218
226
  describe Post do
219
227
  disconnect_sunspot
220
-
228
+
221
229
  it 'should have some behavior'
222
230
  # ...
223
231
  end
@@ -238,8 +246,7 @@ Posts about Sunspot on my blog are available at http://outofti.me/tagged/sunspot
238
246
 
239
247
  == Bugs
240
248
 
241
- Please submit bug reports to
242
- http://outoftime.lighthouseapp.com/projects/20339-sunspot
249
+ Please submit bug reports to https://github.com/sunspot/sunspot/issues
243
250
 
244
251
  == Contributors
245
252
 
data/Rakefile CHANGED
@@ -1,5 +1,10 @@
1
1
  require 'rake'
2
- require 'rake/rdoctask'
2
+
3
+ begin
4
+ require 'rdoc/task'
5
+ rescue LoadError
6
+ require 'rake/rdoctask'
7
+ end
3
8
 
4
9
  if File.exist?(sunspot_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'sunspot', 'lib')))
5
10
  STDERR.puts("Using sunspot lib at #{sunspot_lib}")
@@ -7,12 +12,6 @@ if File.exist?(sunspot_lib = File.expand_path(File.join(File.dirname(__FILE__),
7
12
  end
8
13
 
9
14
  task :environment do
10
- if ENV['SUNSPOT_LIB']
11
- $: << ENV['SUNSPOT_LIB']
12
- end
13
- ENV['RAILS_ROOT'] ||= File.join(File.dirname(__FILE__), 'spec', 'rails3')
14
- ENV['RAILS_ENV'] ||= 'test'
15
- require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'))
16
15
  end
17
16
 
18
17
  FileList['dev_tasks/*.rake', 'lib/sunspot/rails/tasks.rb'].each { |file| load(file) }
@@ -8,8 +8,8 @@ rescue LoadError
8
8
  end
9
9
 
10
10
  Rake::RDocTask.new(:doc) do |rdoc|
11
- rdoc.main = 'README.rdoc'
12
- rdoc.rdoc_files.include('README.rdoc', 'lib/sunspot/rails/**/*.rb', 'lib/sunspot/rails.rb')
11
+ rdoc.main = 'README.md'
12
+ rdoc.rdoc_files.include('README.md', 'lib/sunspot/rails/**/*.rb', 'lib/sunspot/rails.rb')
13
13
  rdoc.rdoc_dir = 'doc'
14
14
  end
15
15
 
@@ -1,22 +1,107 @@
1
- desc 'Run spec suite in both Rails 2 and Rails 3'
2
- task :spec => [:"spec:rails2", :"spec:rails3"]
1
+ require 'fileutils'
3
2
 
4
3
  namespace :spec do
5
- desc 'Run spec suite in Rails 2 application'
6
- task :rails2 do
7
- ENV['BUNDLE_GEMFILE'] = 'spec/rails2/Gemfile'
8
- ENV['RAILS_ROOT'] = 'spec/rails2'
9
- require 'bundler'
10
- Bundler.setup(:default, :test)
11
- system "spec --color #{ENV['SPEC'] || 'spec'}"
12
- end
13
-
14
- desc 'Run spec suite in Rails 3 application'
15
- task :rails3 do
16
- ENV['BUNDLE_GEMFILE'] = 'spec/rails3/Gemfile'
17
- ENV['RAILS_ROOT'] = 'spec/rails3'
18
- require 'bundler'
19
- Bundler.setup(:default, :test)
20
- system "rspec --color #{ENV['SPEC'] || 'spec'}"
4
+ def rails_app_path(version)
5
+ File.join(File.dirname(__FILE__), "..", "tmp", "rails_#{version.gsub(".", "_")}_app")
6
+ end
7
+
8
+ def gemfile_path(version)
9
+ File.join(File.dirname(__FILE__), "..", "gemfiles", "rails-#{version}")
10
+ end
11
+
12
+ def vendor_path(version)
13
+ File.expand_path("vendor/bundle", rails_app_path(version))
14
+ end
15
+
16
+ def rails_template_path
17
+ File.join(File.dirname(__FILE__), "..", "spec", "rails_template")
18
+ end
19
+
20
+ task :run_with_rails => [:set_gemfile, :generate_rails_app, :setup_rails_app, :run]
21
+
22
+ task :set_gemfile do
23
+ version = ENV['VERSION']
24
+
25
+ ENV['BUNDLE_PATH'] = vendor_path(version)
26
+ ENV['BUNDLE_GEMFILE'] = gemfile_path(version)
27
+
28
+ unless File.exist?(ENV['BUNDLE_PATH'])
29
+ puts "Installing gems for Rails #{version} (this will only be done once)..."
30
+ system("bundle install #{ENV['BUNDLE_ARGS']}") || exit(1)
31
+ end
32
+ end
33
+
34
+ task :generate_rails_app do
35
+ version = ENV['VERSION']
36
+ app_path = rails_app_path(version)
37
+
38
+ unless File.exist?(File.expand_path("config/environment.rb", app_path))
39
+ rails_cmd = "bundle exec rails _#{version}_"
40
+
41
+ puts "Generating Rails #{version} application..."
42
+ if version.start_with?("2")
43
+ system("#{rails_cmd} \"#{app_path}\" --force") || exit(1)
44
+ elsif version.start_with?("3")
45
+ system("#{rails_cmd} new \"#{app_path}\" --force --skip-git --skip-javascript --skip-gemfile --skip-sprockets") || exit(1)
46
+ end
47
+ end
48
+ end
49
+
50
+ task :setup_rails_app do
51
+ version = ENV['VERSION']
52
+ app_path = rails_app_path(version)
53
+
54
+ FileUtils.cp_r File.join(rails_template_path, "."), app_path
55
+ end
56
+
57
+ task :run do
58
+ version = ENV['VERSION']
59
+
60
+ ENV['BUNDLE_GEMFILE'] = gemfile_path(version)
61
+ ENV['RAILS_ROOT'] = rails_app_path(version)
62
+
63
+ spec_command = if version.start_with?("2")
64
+ "spec"
65
+ elsif version.start_with?("3")
66
+ "rspec"
67
+ end
68
+
69
+ system "bundle exec #{spec_command} #{ENV['SPEC'] || 'spec/*_spec.rb'} --color"
70
+ end
71
+ end
72
+
73
+ def rails_all_versions
74
+ versions = []
75
+ Dir.glob(File.join(File.dirname(__FILE__), "..", "gemfiles", "rails-*")).each do |gemfile|
76
+ if !gemfile.end_with?(".lock") && gemfile =~ /rails-([0-9.]+)/
77
+ versions << $1
78
+ end
79
+ end
80
+
81
+ versions
82
+ end
83
+
84
+ def reenable_spec_tasks
85
+ Rake::Task.tasks.each do |task|
86
+ if task.name =~ /spec:/
87
+ task.reenable
88
+ end
89
+ end
90
+ end
91
+
92
+ desc 'Run spec suite in all Rails versions'
93
+ task :spec do
94
+ versions = if ENV['RAILS']
95
+ ENV['RAILS'].split(",")
96
+ else
97
+ rails_all_versions
98
+ end
99
+
100
+ versions.each do |version|
101
+ puts "Running specs against Rails #{version}..."
102
+
103
+ ENV['VERSION'] = version
104
+ reenable_spec_tasks
105
+ Rake::Task['spec:run_with_rails'].invoke
21
106
  end
22
107
  end
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '2.3.14'
4
+ gem 'sqlite3-ruby', '~> 1.3.1'
5
+
6
+ gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
7
+ gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
8
+ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
9
+
10
+ group :test do
11
+ gem 'rspec-rails', '~> 1.3.4'
12
+ end
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '3.0.11'
4
+ gem 'sqlite3-ruby', '~> 1.3.1'
5
+
6
+ gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
7
+ gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
8
+ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
9
+
10
+ group :test do
11
+ gem 'rspec-rails', '~> 2.8.1'
12
+ end
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '3.1.3'
4
+ gem 'sqlite3-ruby', '~> 1.3.1'
5
+
6
+ gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
7
+ gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
8
+ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
9
+
10
+ group :test do
11
+ gem 'rspec-rails', '~> 2.8.1'
12
+ end
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'rails', '3.2.1'
4
+ gem 'sqlite3-ruby', '~> 1.3.1'
5
+
6
+ gem 'sunspot', :path => File.expand_path('../../../sunspot', __FILE__)
7
+ gem 'sunspot_solr', :path => File.expand_path('../../../sunspot_solr', __FILE__)
8
+ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
9
+
10
+ group :test do
11
+ gem 'rspec-rails', '~> 2.8.1'
12
+ end
@@ -3,6 +3,8 @@ production:
3
3
  hostname: localhost
4
4
  port: 8983
5
5
  log_level: WARNING
6
+ # read_timeout: 2
7
+ # open_timeout: 0.5
6
8
 
7
9
  development:
8
10
  solr:
@@ -15,4 +17,4 @@ test:
15
17
  hostname: localhost
16
18
  port: 8981
17
19
  log_level: WARNING
18
-
20
+
@@ -3,6 +3,8 @@ production:
3
3
  hostname: localhost
4
4
  port: 8983
5
5
  log_level: WARNING
6
+ # read_timeout: 2
7
+ # open_timeout: 0.5
6
8
 
7
9
  development:
8
10
  solr:
@@ -14,4 +16,4 @@ test:
14
16
  solr:
15
17
  hostname: localhost
16
18
  port: 8981
17
- log_level: WARNING
19
+ log_level: WARNING
@@ -6,9 +6,14 @@ require File.join(File.dirname(__FILE__), 'rails', 'searchable')
6
6
 
7
7
  module Sunspot #:nodoc:
8
8
  module Rails #:nodoc:
9
+ autoload :SolrInstrumentation, File.join(File.dirname(__FILE__), 'rails', 'solr_instrumentation')
9
10
  autoload :StubSessionProxy, File.join(File.dirname(__FILE__), 'rails', 'stub_session_proxy')
10
- autoload :Server, File.join(File.dirname(__FILE__), 'rails', 'server')
11
- autoload :VERSION, File.join(File.dirname(__FILE__), 'rails', 'version')
11
+ begin
12
+ require 'sunspot_solr'
13
+ autoload :Server, File.join(File.dirname(__FILE__), 'rails', 'server')
14
+ rescue LoadError => e
15
+ # We're fine
16
+ end
12
17
 
13
18
  class <<self
14
19
  attr_writer :configuration
@@ -22,7 +27,9 @@ module Sunspot #:nodoc:
22
27
  end
23
28
 
24
29
  def build_session(configuration = self.configuration)
25
- if configuration.has_master?
30
+ if configuration.disabled?
31
+ StubSessionProxy.new(Sunspot.session)
32
+ elsif configuration.has_master?
26
33
  SessionProxy::MasterSlaveSessionProxy.new(
27
34
  SessionProxy::ThreadLocalSessionProxy.new(master_config(configuration)),
28
35
  SessionProxy::ThreadLocalSessionProxy.new(slave_config(configuration))
@@ -41,6 +48,8 @@ module Sunspot #:nodoc:
41
48
  :port => sunspot_rails_configuration.master_port,
42
49
  :path => sunspot_rails_configuration.master_path
43
50
  ).to_s
51
+ config.solr.read_timeout = sunspot_rails_configuration.read_timeout
52
+ config.solr.open_timeout = sunspot_rails_configuration.open_timeout
44
53
  config
45
54
  end
46
55
 
@@ -51,6 +60,8 @@ module Sunspot #:nodoc:
51
60
  :port => sunspot_rails_configuration.port,
52
61
  :path => sunspot_rails_configuration.path
53
62
  ).to_s
63
+ config.solr.read_timeout = sunspot_rails_configuration.read_timeout
64
+ config.solr.open_timeout = sunspot_rails_configuration.open_timeout
54
65
  config
55
66
  end
56
67
  end
@@ -1,3 +1,5 @@
1
+ require 'erb'
2
+
1
3
  module Sunspot #:nodoc:
2
4
  module Rails #:nodoc:
3
5
  #
@@ -12,11 +14,15 @@ module Sunspot #:nodoc:
12
14
  # min_memory: 512M
13
15
  # max_memory: 1G
14
16
  # solr_jar: /some/path/solr15/start.jar
17
+ # bind_address: 0.0.0.0
18
+ # disabled: false
15
19
  # test:
16
20
  # solr:
17
21
  # hostname: localhost
18
22
  # port: 8983
19
23
  # log_level: OFF
24
+ # open_timeout: 0.5
25
+ # read_timeout: 2
20
26
  # production:
21
27
  # solr:
22
28
  # hostname: localhost
@@ -24,6 +30,8 @@ module Sunspot #:nodoc:
24
30
  # path: /solr/myindex
25
31
  # log_level: WARNING
26
32
  # solr_home: /some/path
33
+ # open_timeout: 0.5
34
+ # read_timeout: 2
27
35
  # master_solr:
28
36
  # hostname: localhost
29
37
  # port: 8982
@@ -193,9 +201,10 @@ module Sunspot #:nodoc:
193
201
  @data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env)
194
202
  end
195
203
 
196
- def pid_path
197
- @pids_path ||= user_configuration_from_key('solr', 'pid_path') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
204
+ def pid_dir
205
+ @pid_dir ||= user_configuration_from_key('solr', 'pid_dir') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
198
206
  end
207
+
199
208
 
200
209
  #
201
210
  # The solr home directory. Sunspot::Rails expects this directory
@@ -235,11 +244,34 @@ module Sunspot #:nodoc:
235
244
  def max_memory
236
245
  @max_memory ||= user_configuration_from_key('solr', 'max_memory')
237
246
  end
247
+
248
+ #
249
+ # Interface on which to run Solr
250
+ #
251
+ def bind_address
252
+ @bind_address ||= user_configuration_from_key('solr', 'bind_address')
253
+ end
238
254
 
239
255
  def multicore
240
256
  @multicore ||= !!user_configuration_from_key('solr', 'multicore')
241
257
  end
242
258
 
259
+ def read_timeout
260
+ @read_timeout ||= user_configuration_from_key('solr', 'read_timeout')
261
+ end
262
+
263
+ def open_timeout
264
+ @open_timeout ||= user_configuration_from_key('solr', 'open_timeout')
265
+ end
266
+
267
+ #
268
+ # Whether or not to disable Solr.
269
+ # Defaults to false.
270
+ #
271
+ def disabled?
272
+ @disabled ||= (user_configuration_from_key('disabled') || false)
273
+ end
274
+
243
275
  private
244
276
 
245
277
  #
@@ -281,7 +313,8 @@ module Sunspot #:nodoc:
281
313
  path = File.join(::Rails.root, 'config', 'sunspot.yml')
282
314
  if File.exist?(path)
283
315
  File.open(path) do |file|
284
- YAML.load(file)[::Rails.env]
316
+ processed = ERB.new(file.read).result
317
+ YAML.load(processed)[::Rails.env]
285
318
  end
286
319
  else
287
320
  {}