outoftime-sunspot_rails 0.10.4 → 0.10.5

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.
data/README.rdoc CHANGED
@@ -18,41 +18,26 @@ Sunspot::Rails has been tested with Rails versions 2.1, 2.2, and 2.3
18
18
 
19
19
  == Installation
20
20
 
21
- First, install the Sunspot and Sunspot::Rails gems:
21
+ For recent versions of Rails, In your project's <code>config/environment.rb</code>, add the following gem dependencies:
22
22
 
23
- sudo gem install outoftime-sunspot outoftime-sunspot_rails --source=http://gems.github.com
24
-
25
- In your project's <code>config/environment.rb</code>, add the following gem dependencies:
23
+ config.gem 'outoftime-sunspot', :lib => 'sunspot',
24
+ :source => 'http://gems.github.com'
25
+ config.gem 'outoftime-sunspot_rails', :lib => 'sunspot/rails',
26
+ :source => 'http://gems.github.com'
27
+
28
+ Install the gems with:
26
29
 
27
- config.gem 'outoftime-sunspot', :lib => 'sunspot'
28
- config.gem 'outoftime-sunspot_rails', :lib => 'sunspot/rails'
30
+ rake gems:install
29
31
 
30
- If you are using an older version of Rails that doesn't support plugins-as-gems,
31
- use:
32
+ If you are using an older version of Rails that doesn't support plugins-as-gems, install the gems manually and install the plugin:
32
33
 
34
+ sudo gem install outoftime-sunspot outoftime-sunspot_rails --source=http://gems.github.com
35
+
33
36
  script/plugin install git://github.com/outoftime/sunspot_rails.git
37
+
38
+ Generate the file <code>config/sunspot.yml</code>:
34
39
 
35
- Create the file <code>config/sunspot.yml</code> and set it up for your environments. Here is a sample:
36
-
37
- common: &common
38
- solr:
39
- hostname: localhost
40
- port: 8983
41
-
42
- production:
43
- <<: *common
44
- solr:
45
- path: /solr/myindex
46
-
47
- development:
48
- <<: *common
49
- solr:
50
- port: 8982
51
-
52
- test:
53
- <<: *common
54
- solr:
55
- port: 8981
40
+ script/generate sunspot
56
41
 
57
42
  Rails doesn't automatically load rake tasks from plugins installed as gems
58
43
  (https://rails.lighthouseapp.com/projects/8994/tickets/59). If you installed
@@ -240,6 +225,8 @@ http://outoftime.lighthouseapp.com/projects/20339-sunspot
240
225
  - Peer Allan (peer.allan@gmail.com)
241
226
  - Michael Moen (michael@underpantsgnome.com)
242
227
  - Benjamin Krause (bk@benjaminkrause.com)
228
+ - Adam Salter (adam@codebright.net)
229
+ - Brandon Keepers (brandon@opensoul.org)
243
230
 
244
231
  == License
245
232
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 10
3
- :patch: 4
3
+ :patch: 5
4
4
  :major: 0
@@ -7,9 +7,11 @@ begin
7
7
  s.email = 'mat@patch.com'
8
8
  s.homepage = 'http://github.com/outoftime/sunspot_rails'
9
9
  s.description = 'Rails integration for the Sunspot Solr search library'
10
- s.authors = ['Mat Brown', 'Peer Allan', 'Michael Moen', 'Benjamin Krause']
10
+ s.authors = ['Mat Brown', 'Peer Allan', 'Michael Moen', 'Benjamin Krause', 'Adam Salter', 'Brandon Keepers']
11
+ s.rubyforge_project = 'sunspot'
11
12
  s.files = FileList['[A-Z]*',
12
13
  '{lib,tasks,dev_tasks}/**/*',
14
+ 'generators/**/*',
13
15
  'install.rb',
14
16
  'MIT-LICENSE',
15
17
  'rails/*',
@@ -0,0 +1,4 @@
1
+ namespace :release do
2
+ desc 'Release gem on RubyForge and GitHub'
3
+ task :all => [:release, :"rubyforge:release:gem"]
4
+ end
@@ -0,0 +1,9 @@
1
+ class SunspotGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.template 'sunspot.yml', 'config/sunspot.yml'
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,19 @@
1
+ common: &common
2
+ solr:
3
+ hostname: localhost
4
+ port: 8983
5
+
6
+ production:
7
+ <<: *common
8
+ solr:
9
+ path: /solr/myindex
10
+
11
+ development:
12
+ <<: *common
13
+ solr:
14
+ port: 8982
15
+
16
+ test:
17
+ <<: *common
18
+ solr:
19
+ port: 8981
data/lib/sunspot/rails.rb CHANGED
@@ -3,6 +3,8 @@ require 'sunspot'
3
3
  module Sunspot #:nodoc:
4
4
  module Rails #:nodoc:
5
5
  class <<self
6
+ attr_writer :configuration
7
+
6
8
  def configuration
7
9
  @configuration ||= Sunspot::Rails::Configuration.new
8
10
  end
@@ -25,6 +25,7 @@ module Sunspot #:nodoc:
25
25
  # <code>rake sunspot:solr:start</code> task.
26
26
  #
27
27
  class Configuration
28
+ attr_writer :user_configuration
28
29
  #
29
30
  # The host name at which to connect to Solr. Default 'localhost'.
30
31
  #
@@ -33,10 +34,7 @@ module Sunspot #:nodoc:
33
34
  # String:: host name
34
35
  #
35
36
  def hostname
36
- @hostname ||=
37
- if user_configuration.has_key?('solr')
38
- user_configuration['solr']['hostname']
39
- end || 'localhost'
37
+ @hostname ||= (user_configuration_from_key('solr', 'hostname') || 'localhost')
40
38
  end
41
39
 
42
40
  #
@@ -47,14 +45,11 @@ module Sunspot #:nodoc:
47
45
  # Integer:: port
48
46
  #
49
47
  def port
50
- @port ||=
51
- if user_configuration.has_key?('solr')
52
- user_configuration['solr']['port']
53
- end || 8983
48
+ @port ||= (user_configuration_from_key('solr', 'port') || 8983).to_i
54
49
  end
55
50
 
56
51
  #
57
- # The path to the Solr servlet (useful if you are running multicore).
52
+ # The url path to the Solr servlet (useful if you are running multicore).
58
53
  # Default '/solr'.
59
54
  #
60
55
  # ==== Returns
@@ -62,13 +57,91 @@ module Sunspot #:nodoc:
62
57
  # String:: path
63
58
  #
64
59
  def path
65
- @path ||=
60
+ @path ||= (user_configuration_from_key('solr', 'path') || '/solr')
61
+ end
62
+
63
+ #
64
+ # Should the solr index receive a commit after each http-request.
65
+ # Default true
66
+ #
67
+ # ==== Returns
68
+ #
69
+ # Boolean:: bool
70
+ #
71
+
72
+ def auto_commit_after_request?
73
+ @auto_commit_after_request ||=
74
+ user_configuration_from_key('auto_commit_after_request') != false
75
+ end
76
+
77
+ #
78
+ # The path to the Solr indexes. (Used by the rake tasks).
79
+ # Default RAILS_ROOT + '/solr/data/' + ENVIRONMENT
80
+ #
81
+ # ==== Returns
82
+ #
83
+ # String:: path
84
+ #
85
+ def data_path
86
+ @data_path ||=
66
87
  if user_configuration.has_key?('solr')
67
- "#{user_configuration['solr']['path'] || '/solr'}"
88
+ "#{user_configuration['solr']['data_path'] || File.join(::Rails.root, 'solr', 'data', ::Rails.env)}"
89
+ end
90
+ end
91
+
92
+ #
93
+ # The path to the Solr pids
94
+ # Default RAILS_ROOT + '/solr/pids/' + ENVIRONMENT
95
+ #
96
+ # ==== Returns
97
+ #
98
+ # String:: path
99
+ #
100
+ def pid_path
101
+ @pids_path ||=
102
+ if user_configuration.has_key?('solr')
103
+ "#{user_configuration['solr']['pid_path'] || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)}"
104
+ end
105
+ end
106
+
107
+ #
108
+ # The path to the Solr home directory
109
+ # Default nil (runs the solr with sunspot default settings).
110
+ #
111
+ # If you have a custom solr conf directory,
112
+ # change this to the directory above your solr conf files
113
+ #
114
+ # e.g. conf files in RAILS_ROOT/solr/conf
115
+ # solr_home: RAILS_ROOT/solr
116
+ #
117
+ # ==== Returns
118
+ #
119
+ # String:: path
120
+ #
121
+ def solr_home
122
+ @solr_home ||=
123
+ if user_configuration.has_key?('solr')
124
+ if user_configuration['solr']['solr_home'].present?
125
+ user_configuration['solr']['solr_home']
126
+ elsif %w(solrconfig schema).all? { |file| File.exist?(File.join(::Rails.root, 'solr', 'conf', "#{file}.xml")) }
127
+ File.join(::Rails.root, 'solr')
128
+ end
68
129
  end
69
130
  end
70
131
 
71
132
  private
133
+
134
+ #
135
+ # return a specific key from the user configuration in config/sunspot.yml
136
+ #
137
+ # ==== Returns
138
+ #
139
+ #
140
+ def user_configuration_from_key( *keys )
141
+ keys.inject(user_configuration) do |hash, key|
142
+ hash[key] if hash
143
+ end
144
+ end
72
145
 
73
146
  #
74
147
  # Memoized hash of configuration options for the current Rails environment
@@ -86,6 +159,8 @@ module Sunspot #:nodoc:
86
159
  File.open(path) do |file|
87
160
  YAML.load(file)[::Rails.env]
88
161
  end
162
+ else
163
+ {}
89
164
  end
90
165
  end
91
166
  end
@@ -9,7 +9,7 @@ module Sunspot #:nodoc:
9
9
  class <<self
10
10
  def included(base) #:nodoc:
11
11
  base.after_filter do
12
- Sunspot.commit_if_dirty
12
+ Sunspot.commit_if_dirty if Sunspot::Rails.configuration.auto_commit_after_request?
13
13
  end
14
14
  end
15
15
  end
@@ -208,7 +208,8 @@ module Sunspot #:nodoc:
208
208
  #
209
209
  # Array:: Collection of IDs that exist in Solr but not in the database
210
210
  def index_orphans
211
- indexed_ids = search_ids.to_set
211
+ count = self.count
212
+ indexed_ids = search_ids { paginate(:page => 1, :per_page => count) }.to_set
212
213
  all(:select => 'id').each do |object|
213
214
  indexed_ids.delete(object.id)
214
215
  end
@@ -7,12 +7,9 @@ namespace :sunspot do
7
7
  if RUBY_PLATFORM =~ /w(in)?32$/
8
8
  abort('This command does not work on Windows. Please use rake sunspot:solr:run to run Solr in the foreground.')
9
9
  end
10
- data_path = File.join(::Rails.root, 'solr', 'data', ::Rails.env)
11
- pid_path = File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
12
- solr_home =
13
- if %w(solrconfig schema).all? { |file| File.exist?(File.join(::Rails.root, 'solr', 'conf', "#{file}.xml")) }
14
- File.join(::Rails.root, 'solr')
15
- end
10
+ data_path = Sunspot::Rails.configuration.data_path
11
+ pid_path = Sunspot::Rails.configuration.pid_path
12
+ solr_home = Sunspot::Rails.configuration.solr_home
16
13
  [data_path, pid_path].each { |path| FileUtils.mkdir_p(path) }
17
14
  port = Sunspot::Rails.configuration.port
18
15
  FileUtils.cd(File.join(pid_path)) do
@@ -26,11 +23,8 @@ namespace :sunspot do
26
23
 
27
24
  desc 'Run the Solr instance in the foreground'
28
25
  task :run => :environment do
29
- data_path = File.join(::Rails.root, 'solr', 'data', ::Rails.env)
30
- solr_home =
31
- if %w(solrconfig schema).all? { |file| File.exist?(File.join(::Rails.root, 'solr', 'conf', "#{file}.xml")) }
32
- File.join(::Rails.root, 'solr')
33
- end
26
+ data_path = Sunspot::Rails.configuration.data_path
27
+ solr_home = Sunspot::Rails.configuration.solr_home
34
28
  FileUtils.mkdir_p(data_path)
35
29
  port = Sunspot::Rails.configuration.port
36
30
  command = ['sunspot-solr', 'run', '--', '-p', port.to_s, '-d', data_path]
@@ -45,7 +39,7 @@ namespace :sunspot do
45
39
 
46
40
  desc 'Stop the Solr instance'
47
41
  task :stop => :environment do
48
- FileUtils.cd(File.join(::Rails.root, 'solr', 'pids', ::Rails.env)) do
42
+ FileUtils.cd(Sunspot::Rails.configuration.pid_path) do
49
43
  system(Escape.shell_command(['sunspot-solr', 'stop']))
50
44
  end
51
45
  end
@@ -1,16 +1,53 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
- describe "Configuration" do
3
+ describe Sunspot::Rails::Configuration, "default values" do
4
+ before(:each) do
5
+ File.should_receive(:exist?).and_return(false)
6
+ end
7
+
8
+ it "should handle the 'hostname' property when not set" do
9
+ config = Sunspot::Rails::Configuration.new
10
+ config.hostname.should == 'localhost'
11
+ end
12
+
4
13
  it "should handle the 'path' property when not set" do
5
14
  config = Sunspot::Rails::Configuration.new
6
15
  config.path.should == '/solr'
7
16
  end
8
17
 
18
+ it "should handle the 'port' property when not set" do
19
+ config = Sunspot::Rails::Configuration.new
20
+ config.port.should == 8983
21
+ end
22
+
23
+ it "should handle the 'auto_commit_after_request' propery when not set" do
24
+ config = Sunspot::Rails::Configuration.new
25
+ config.auto_commit_after_request?.should == true
26
+ end
27
+ end
28
+
29
+ describe Sunspot::Rails::Configuration, "user settings" do
30
+ before(:each) do
31
+ Rails.stub!(:env => 'config_test')
32
+ end
33
+
34
+ it "should handle the 'hostname' property when not set" do
35
+ config = Sunspot::Rails::Configuration.new
36
+ config.hostname.should == 'some.host'
37
+ end
38
+
39
+ it "should handle the 'port' property when not set" do
40
+ config = Sunspot::Rails::Configuration.new
41
+ config.port.should == 1234
42
+ end
43
+
9
44
  it "should handle the 'path' property when set" do
10
- silence_stderr do
11
- Rails.stub!(:env => 'path_test')
12
- config = Sunspot::Rails::Configuration.new
13
- config.path.should == '/solr/path_test'
14
- end
45
+ config = Sunspot::Rails::Configuration.new
46
+ config.path.should == '/solr/idx'
47
+ end
48
+
49
+ it "should handle the 'auto_commit_after_request' propery when set" do
50
+ config = Sunspot::Rails::Configuration.new
51
+ config.auto_commit_after_request?.should == false
15
52
  end
16
53
  end
@@ -6,8 +6,9 @@ development:
6
6
  solr:
7
7
  hostname: localhost
8
8
  port: 8981
9
- path_test:
9
+ config_test:
10
10
  solr:
11
- hostname: localhost
12
- port: 8981
13
- path: /solr/path_test
11
+ hostname: some.host
12
+ port: 1234
13
+ path: /solr/idx
14
+ auto_commit_after_request: false
@@ -1,10 +1,30 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe 'request lifecycle', :type => :controller do
4
+ before(:each) do
5
+ Sunspot::Rails.configuration = @configuration = Sunspot::Rails::Configuration.new
6
+ end
7
+
8
+ after(:each) do
9
+ Sunspot::Rails.configuration = nil
10
+ end
4
11
  controller_name :posts
5
12
 
6
- it 'should automatically commit after each action' do
13
+ it 'should automatically commit after each action if specified' do
14
+ @configuration.user_configuration = { 'auto_commit_after_request' => true }
15
+ Sunspot.should_receive(:commit_if_dirty)
16
+ post :create, :post => { :title => 'Test 1' }
17
+ end
18
+
19
+ it 'should not commit, if configuration is set to false' do
20
+ @configuration.user_configuration = { 'auto_commit_after_request' => false }
21
+ Sunspot.should_not_receive(:commit_if_dirty)
22
+ post :create, :post => { :title => 'Test 1' }
23
+ end
24
+
25
+ it 'should commit if configuration is not specified' do
26
+ @configuration.user_configuration = {}
27
+ Sunspot.should_receive(:commit_if_dirty)
7
28
  post :create, :post => { :title => 'Test 1' }
8
- PostWithAuto.search { with :title, 'Test 1' }.results.should_not be_empty
9
29
  end
10
30
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,9 @@ require File.expand_path(File.join(ENV['RAILS_ROOT'], 'config', 'environment.rb'
5
5
 
6
6
  require 'spec'
7
7
  require 'spec/rails'
8
- require 'ruby-debug'
8
+ require 'rake'
9
+ require 'ruby-debug' unless RUBY_VERSION =~ /1\.9/
10
+ require 'sunspot/rails/tasks'
9
11
 
10
12
  def load_schema
11
13
  stdout = $stdout
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outoftime-sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-07-23 00:00:00 -07:00
15
+ date: 2009-09-01 00:00:00 -07:00
16
16
  default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -102,7 +102,10 @@ files:
102
102
  - VERSION.yml
103
103
  - dev_tasks/gemspec.rake
104
104
  - dev_tasks/rdoc.rake
105
+ - dev_tasks/release.rake
105
106
  - dev_tasks/todo.rake
107
+ - generators/sunspot/sunspot_generator.rb
108
+ - generators/sunspot/templates/sunspot.yml
106
109
  - install.rb
107
110
  - lib/sunspot/rails.rb
108
111
  - lib/sunspot/rails/adapters.rb
@@ -132,7 +135,7 @@ files:
132
135
  - spec/request_lifecycle_spec.rb
133
136
  - spec/schema.rb
134
137
  - spec/spec_helper.rb
135
- has_rdoc: true
138
+ has_rdoc: false
136
139
  homepage: http://github.com/outoftime/sunspot_rails
137
140
  post_install_message:
138
141
  rdoc_options:
@@ -153,28 +156,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
156
  version:
154
157
  requirements: []
155
158
 
156
- rubyforge_project:
159
+ rubyforge_project: sunspot
157
160
  rubygems_version: 1.2.0
158
161
  signing_key:
159
162
  specification_version: 3
160
163
  summary: Rails integration for the Sunspot Solr search library
161
164
  test_files:
162
- - spec/spec_helper.rb
163
165
  - spec/configuration_spec.rb
164
- - spec/model_lifecycle_spec.rb
165
- - spec/schema.rb
166
- - spec/model_spec.rb
167
- - spec/mock_app/app/controllers/posts_controller.rb
168
- - spec/mock_app/app/controllers/application_controller.rb
169
166
  - spec/mock_app/app/controllers/application.rb
167
+ - spec/mock_app/app/controllers/application_controller.rb
168
+ - spec/mock_app/app/controllers/posts_controller.rb
170
169
  - spec/mock_app/app/models/blog.rb
171
- - spec/mock_app/app/models/post_with_auto.rb
172
170
  - spec/mock_app/app/models/post.rb
171
+ - spec/mock_app/app/models/post_with_auto.rb
172
+ - spec/mock_app/config/boot.rb
173
173
  - spec/mock_app/config/environment.rb
174
- - spec/mock_app/config/initializers/session_store.rb
175
- - spec/mock_app/config/initializers/new_rails_defaults.rb
176
174
  - spec/mock_app/config/environments/development.rb
177
175
  - spec/mock_app/config/environments/test.rb
176
+ - spec/mock_app/config/initializers/new_rails_defaults.rb
177
+ - spec/mock_app/config/initializers/session_store.rb
178
178
  - spec/mock_app/config/routes.rb
179
- - spec/mock_app/config/boot.rb
179
+ - spec/model_lifecycle_spec.rb
180
+ - spec/model_spec.rb
180
181
  - spec/request_lifecycle_spec.rb
182
+ - spec/schema.rb
183
+ - spec/spec_helper.rb