sunspot_rails 2.2.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dc4062c6306167165c181dffb9aeeebfb04492d2
4
+ data.tar.gz: fb33383db287547638c5d5fce71a0ca1a3a8ab20
5
+ SHA512:
6
+ metadata.gz: f82e20a0ecad915f6462f28bb2da30416b9d029e00d65cf7c6674bcbf8b208b18f3e41a45fa4b0b45a38bf220bd30e297df2131c51dce067cd2b262e51bcb5e8
7
+ data.tar.gz: 9221cb7ce804e6b2380e90aec439350b47327e15b95f627a7ae24fb3919dfa96dfc3e730dd31828089daa95d0fb15f0d4c991430e2b28145b22e985c2a389f81
@@ -8,6 +8,7 @@ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
8
8
 
9
9
  group :test do
10
10
  gem 'rspec-rails', '~> 2.14.0'
11
+ gem 'progress_bar', '~> 1.0.5', require: false
11
12
  end
12
13
 
13
14
  group :postgres do
@@ -8,6 +8,7 @@ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
8
8
 
9
9
  group :test do
10
10
  gem 'rspec-rails', '~> 2.14.0'
11
+ gem 'progress_bar', '~> 1.0.5', require: false
11
12
  end
12
13
 
13
14
  group :postgres do
@@ -8,6 +8,7 @@ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
8
8
 
9
9
  group :test do
10
10
  gem 'rspec-rails', '~> 2.14.0'
11
+ gem 'progress_bar', '~> 1.0.5', require: false
11
12
  end
12
13
 
13
14
  group :postgres do
@@ -9,6 +9,7 @@ gem 'sunspot_rails', :path => File.expand_path('../..', __FILE__)
9
9
  group :test do
10
10
  gem 'protected_attributes' # Rails 4 support for attr_accessor so specs still work
11
11
  gem 'rspec-rails', '~> 2.14.0'
12
+ gem 'progress_bar', '~> 1.0.5', require: false
12
13
  end
13
14
 
14
15
  group :postgres do
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.1.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
+ gem 'progress_bar', '~> 1.0.5', require: false
13
+ end
14
+
15
+ group :postgres do
16
+ gem 'pg'
17
+ end
18
+
19
+ group :sqlite do
20
+ gem 'sqlite3', '~> 1.3.7'
21
+ end
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.2.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
+ gem 'progress_bar', '~> 1.0.5', require: false
13
+ end
14
+
15
+ group :postgres do
16
+ gem 'pg'
17
+ end
18
+
19
+ group :sqlite do
20
+ gem 'sqlite3', '~> 1.3.7'
21
+ end
@@ -247,10 +247,6 @@ module Sunspot #:nodoc:
247
247
  @log_file ||= (user_configuration_from_key('solr', 'log_file') || default_log_file_location )
248
248
  end
249
249
 
250
- def data_path
251
- @data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env)
252
- end
253
-
254
250
  def pid_dir
255
251
  @pid_dir ||= user_configuration_from_key('solr', 'pid_dir') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
256
252
  end
@@ -277,8 +273,8 @@ module Sunspot #:nodoc:
277
273
  #
278
274
  # Solr start jar
279
275
  #
280
- def solr_jar
281
- @solr_jar ||= user_configuration_from_key('solr', 'solr_jar')
276
+ def solr_executable
277
+ @solr_executable ||= user_configuration_from_key('solr', 'solr_executable')
282
278
  end
283
279
 
284
280
  #
@@ -134,6 +134,8 @@ module Sunspot #:nodoc:
134
134
  alias_method :index, :solr_index unless method_defined? :index
135
135
  alias_method :index_orphans, :solr_index_orphans unless method_defined? :index_orphans
136
136
  alias_method :clean_index_orphans, :solr_clean_index_orphans unless method_defined? :clean_index_orphans
137
+ alias_method :atomic_update, :solr_atomic_update unless method_defined? :atomic_update
138
+ alias_method :atomic_update!, :solr_atomic_update! unless method_defined? :atomic_update!
137
139
  end
138
140
  end
139
141
  #
@@ -257,9 +259,9 @@ module Sunspot #:nodoc:
257
259
  if options[:batch_size].to_i > 0
258
260
  batch_counter = 0
259
261
  self.includes(options[:include]).find_in_batches(options.slice(:batch_size, :start)) do |records|
260
-
262
+
261
263
  solr_benchmark(options[:batch_size], batch_counter += 1) do
262
- Sunspot.index(records.select { |model| model.indexable? })
264
+ Sunspot.index(records.select(&:indexable?))
263
265
  Sunspot.commit if options[:batch_commit]
264
266
  end
265
267
 
@@ -273,6 +275,46 @@ module Sunspot #:nodoc:
273
275
  Sunspot.commit unless options[:batch_commit]
274
276
  end
275
277
 
278
+ #
279
+ # Update properties of existing records in the Solr index.
280
+ # Atomic updates available only for the stored properties.
281
+ #
282
+ # ==== Updates (passed as a hash)
283
+ #
284
+ # updates should be specified as a hash, where key - is the object ID
285
+ # and values is hash with property name/values to be updated.
286
+ #
287
+ # ==== Examples
288
+ #
289
+ # class Post < ActiveRecord::Base
290
+ # searchable do
291
+ # string :title, stored: true
292
+ # string :description, stored: true
293
+ # end
294
+ # end
295
+ #
296
+ # post1 = Post.create(title: 'A Title', description: nil)
297
+ #
298
+ # # update single property
299
+ # Post.atomic_update(post1.id => {description: 'New post description'})
300
+ #
301
+ # ==== Notice
302
+ # all non-stored properties in Solr index will be lost after update.
303
+ # Read Solr wiki page: https://wiki.apache.org/solr/Atomic_Updates
304
+ def solr_atomic_update(updates = {})
305
+ Sunspot.atomic_update(self, updates)
306
+ end
307
+
308
+ #
309
+ # Update properties of existing records in the Solr index atomically, and
310
+ # immediately commits.
311
+ #
312
+ # See #solr_atomic_update for information on options, etc.
313
+ #
314
+ def solr_atomic_update!(updates = {})
315
+ Sunspot.atomic_update!(self, updates)
316
+ end
317
+
276
318
  #
277
319
  # Return the IDs of records of this class that are indexed in Solr but
278
320
  # do not exist in the database. Under normal circumstances, this should
@@ -282,8 +324,7 @@ module Sunspot #:nodoc:
282
324
  #
283
325
  # ==== Options (passed as a hash)
284
326
  #
285
- # batch_size<Integer>:: Batch size with which to load records. Passing
286
- # Default is 1000 (from ActiveRecord).
327
+ # batch_size<Integer>:: Override default batch size with which to load records.
287
328
  #
288
329
  # ==== Returns
289
330
  #
@@ -294,7 +335,7 @@ module Sunspot #:nodoc:
294
335
  solr_page = 0
295
336
  solr_ids = []
296
337
  while (solr_page = solr_page.next)
297
- ids = solr_search_ids { paginate(:page => solr_page, :per_page => 1000) }.to_a
338
+ ids = solr_search_ids { paginate(:page => solr_page, :per_page => batch_size) }.to_a
298
339
  break if ids.empty?
299
340
  solr_ids.concat ids
300
341
  end
@@ -310,8 +351,7 @@ module Sunspot #:nodoc:
310
351
  #
311
352
  # ==== Options (passed as a hash)
312
353
  #
313
- # batch_size<Integer>:: Batch size with which to load records
314
- # Default is 50
354
+ # batch_size<Integer>:: Override default batch size with which to load records
315
355
  #
316
356
  def solr_clean_index_orphans(opts={})
317
357
  solr_index_orphans(opts).each do |id|
@@ -378,6 +418,8 @@ module Sunspot #:nodoc:
378
418
  alias_method :remove_from_index!, :solr_remove_from_index! unless method_defined? :remove_from_index!
379
419
  alias_method :more_like_this, :solr_more_like_this unless method_defined? :more_like_this
380
420
  alias_method :more_like_this_ids, :solr_more_like_this_ids unless method_defined? :more_like_this_ids
421
+ alias_method :atomic_update, :solr_atomic_update unless method_defined? :atomic_update
422
+ alias_method :atomic_update!, :solr_atomic_update! unless method_defined? :atomic_update!
381
423
  end
382
424
  end
383
425
  #
@@ -398,6 +440,23 @@ module Sunspot #:nodoc:
398
440
  def solr_index!
399
441
  Sunspot.index!(self)
400
442
  end
443
+
444
+ #
445
+ # Updates specified model properties in Solr.
446
+ # Unlike ClassMethods#solr_atomic_update you dont need to pass object id,
447
+ # you only need to pass hash with property changes
448
+ #
449
+ def solr_atomic_update(updates = {})
450
+ Sunspot.atomic_update(self.class, self.id => updates)
451
+ end
452
+
453
+ #
454
+ # Updates specified model properties in Solr and immediately commit.
455
+ # See #solr_atomic_update
456
+ #
457
+ def solr_atomic_update!(updates = {})
458
+ Sunspot.atomic_update!(self.class, self.id => updates)
459
+ end
401
460
 
402
461
  #
403
462
  # Remove the model from the Solr index. Using the defaults, this should
@@ -16,17 +16,6 @@ module Sunspot
16
16
  "sunspot-solr-#{::Rails.env}.pid"
17
17
  end
18
18
 
19
- #
20
- # Directory to store lucene index data files
21
- #
22
- # ==== Returns
23
- #
24
- # String:: data_path
25
- #
26
- def solr_data_dir
27
- configuration.data_path
28
- end
29
-
30
19
  #
31
20
  # Directory to use for Solr home.
32
21
  #
@@ -37,8 +26,8 @@ module Sunspot
37
26
  #
38
27
  # Solr start jar
39
28
  #
40
- def solr_jar
41
- configuration.solr_jar || super
29
+ def solr_executable
30
+ configuration.solr_executable || super
42
31
  end
43
32
 
44
33
  #
@@ -17,6 +17,12 @@ module Sunspot
17
17
  def index!(*objects)
18
18
  end
19
19
 
20
+ def atomic_update(clazz, updates = {})
21
+ end
22
+
23
+ def atomic_update!(clazz, updates = {})
24
+ end
25
+
20
26
  def remove(*objects)
21
27
  end
22
28
 
@@ -110,6 +116,10 @@ module Sunspot
110
116
  DataAccessorStub.new
111
117
  end
112
118
 
119
+ def stats(name)
120
+ StatsStub.new
121
+ end
122
+
113
123
  def execute
114
124
  self
115
125
  end
@@ -148,6 +158,7 @@ module Sunspot
148
158
  def previous_page
149
159
  nil
150
160
  end
161
+ alias :prev_page :previous_page
151
162
 
152
163
  def next_page
153
164
  nil
@@ -171,6 +182,49 @@ module Sunspot
171
182
 
172
183
  end
173
184
 
185
+ class StatsStub
186
+ def min
187
+ 0
188
+ end
189
+
190
+ def max
191
+ 100
192
+ end
193
+
194
+ def count
195
+ 30
196
+ end
197
+
198
+ def sum
199
+ 500
200
+ end
201
+
202
+ def missing
203
+ 3
204
+ end
205
+
206
+ def sum_of_squares
207
+ 5000
208
+ end
209
+
210
+ def mean
211
+ 50
212
+ end
213
+
214
+ def standard_deviation
215
+ 20
216
+ end
217
+
218
+ def facets
219
+ []
220
+ end
221
+
222
+ def facet(name)
223
+ FacetStub.new
224
+ end
225
+
226
+ end
227
+
174
228
  end
175
229
  end
176
230
  end
@@ -49,6 +49,8 @@ namespace :sunspot do
49
49
  reindex_options[:progress_bar] = ProgressBar.new(total_documents)
50
50
  rescue LoadError => e
51
51
  $stdout.puts "Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile"
52
+ rescue ProgressBar::ArgumentError => e
53
+ $stdout.puts "You have no data in the database. Reindexing does nothing here."
52
54
  rescue Exception => e
53
55
  $stderr.puts "Error using progress bar: #{e.message}"
54
56
  end unless args[:silence]
@@ -67,11 +67,6 @@ describe Sunspot::Rails::Configuration, "default values without a sunspot.yml" d
67
67
  @config.solr_home.should == '/some/path/solr'
68
68
  end
69
69
 
70
- it "should handle the 'data_path' property when not set" do
71
- Rails.should_receive(:root).at_least(1).and_return('/some/path')
72
- @config.data_path.should == '/some/path/solr/data/test'
73
- end
74
-
75
70
  it "should handle the 'pid_dir' property when not set" do
76
71
  Rails.should_receive(:root).at_least(1).and_return('/some/path')
77
72
  @config.pid_dir.should == '/some/path/solr/pids/test'
@@ -136,10 +131,6 @@ describe Sunspot::Rails::Configuration, "user provided sunspot.yml" do
136
131
  @config.solr_home.should == '/my_superior_path'
137
132
  end
138
133
 
139
- it "should handle the 'data_path' property when set" do
140
- @config.data_path.should == '/my_superior_path/data'
141
- end
142
-
143
134
  it "should handle the 'pid_dir' property when set" do
144
135
  @config.pid_dir.should == '/my_superior_path/pids'
145
136
  end
@@ -171,7 +162,7 @@ end
171
162
 
172
163
  describe Sunspot::Rails::Configuration, "with auto_index_callback and auto_remove_callback set" do
173
164
  before do
174
- ::Rails.stub!(:env => 'config_commit_test')
165
+ ::Rails.stub(:env => 'config_commit_test')
175
166
  @config = Sunspot::Rails::Configuration.new
176
167
  end
177
168
 
@@ -17,7 +17,6 @@ config_test:
17
17
  port: 1234
18
18
  path: /solr/idx
19
19
  log_level: WARNING
20
- data_path: /my_superior_path/data
21
20
  pid_dir: /my_superior_path/pids
22
21
  solr_home: /my_superior_path
23
22
  bind_address: 127.0.0.1
@@ -30,6 +30,12 @@ describe 'sunspot namespace rake task' do
30
30
 
31
31
  run_rake_task("sunspot:reindex", '', "Post+Author", true)
32
32
  end
33
+
34
+ it "should raise exception when all tables of sunspot models are empty" do
35
+ STDOUT.should_receive(:puts).with("You have no data in the database. Reindexing does nothing here.")
36
+ empty_tables
37
+ run_rake_task("sunspot:reindex")
38
+ end
33
39
  end
34
40
  end
35
41
 
@@ -16,10 +16,6 @@ describe Sunspot::Rails::Server do
16
16
  @server.pid_path.should == File.join(@server.pid_dir, 'sunspot-solr-test.pid')
17
17
  end
18
18
 
19
- it "sets the correct Solr data dir" do
20
- @server.solr_data_dir.should == File.join(@solr_home, 'data', 'test')
21
- end
22
-
23
19
  it "sets the correct port" do
24
20
  @server.port.should == 8983
25
21
  end
@@ -10,7 +10,7 @@ describe 'specs with Sunspot stubbed' do
10
10
  end
11
11
 
12
12
  it 'should batch' do
13
- foo = mock('Foo')
13
+ foo = double('Foo')
14
14
  block = lambda { foo.bar }
15
15
 
16
16
  foo.should_receive(:bar)
@@ -28,6 +28,16 @@ describe 'specs with Sunspot stubbed' do
28
28
  @post.index!
29
29
  end
30
30
 
31
+ it 'should not send atomic_update to session' do
32
+ @session.should_not_receive(:atomic_update)
33
+ @post.index
34
+ end
35
+
36
+ it 'should not send atomic_update! to session' do
37
+ @session.should_not_receive(:atomic_update!)
38
+ @post.index!
39
+ end
40
+
31
41
  it 'should not send commit to session' do
32
42
  @session.should_not_receive(:commit)
33
43
  Sunspot.commit
@@ -154,5 +164,32 @@ describe 'specs with Sunspot stubbed' do
154
164
  @accessor.should respond_to(:include, :include=)
155
165
  end
156
166
  end
167
+
168
+ describe '#stats' do
169
+ before do
170
+ @stats = @search.stats(:price)
171
+ end
172
+
173
+ it 'should response to all the available data methods' do
174
+ @stats.should respond_to(
175
+ :min,
176
+ :max,
177
+ :count,
178
+ :sum,
179
+ :missing,
180
+ :sum_of_squares,
181
+ :mean,
182
+ :standard_deviation)
183
+ end
184
+
185
+ it 'should return empty results for a given facet' do
186
+ @stats.facet(:category_id).rows.should == []
187
+ end
188
+
189
+ it 'should return empty array if listing facets' do
190
+ @stats.facets.should == []
191
+ end
192
+
193
+ end
157
194
  end
158
195
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
5
- prerelease:
4
+ version: 2.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mat Brown
@@ -27,12 +26,11 @@ authors:
27
26
  autorequire:
28
27
  bindir: bin
29
28
  cert_chain: []
30
- date: 2015-04-09 00:00:00.000000000 Z
29
+ date: 2015-11-20 00:00:00.000000000 Z
31
30
  dependencies:
32
31
  - !ruby/object:Gem::Dependency
33
32
  name: rails
34
33
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
34
  requirements:
37
35
  - - ">="
38
36
  - !ruby/object:Gem::Version
@@ -40,7 +38,6 @@ dependencies:
40
38
  type: :runtime
41
39
  prerelease: false
42
40
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
41
  requirements:
45
42
  - - ">="
46
43
  - !ruby/object:Gem::Version
@@ -48,23 +45,20 @@ dependencies:
48
45
  - !ruby/object:Gem::Dependency
49
46
  name: sunspot
50
47
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
48
  requirements:
53
49
  - - '='
54
50
  - !ruby/object:Gem::Version
55
- version: 2.2.0
51
+ version: 2.2.1
56
52
  type: :runtime
57
53
  prerelease: false
58
54
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
55
  requirements:
61
56
  - - '='
62
57
  - !ruby/object:Gem::Version
63
- version: 2.2.0
58
+ version: 2.2.1
64
59
  - !ruby/object:Gem::Dependency
65
60
  name: nokogiri
66
61
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
62
  requirements:
69
63
  - - ">="
70
64
  - !ruby/object:Gem::Version
@@ -72,7 +66,6 @@ dependencies:
72
66
  type: :runtime
73
67
  prerelease: false
74
68
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
69
  requirements:
77
70
  - - ">="
78
71
  - !ruby/object:Gem::Version
@@ -80,7 +73,6 @@ dependencies:
80
73
  - !ruby/object:Gem::Dependency
81
74
  name: rspec
82
75
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
76
  requirements:
85
77
  - - "~>"
86
78
  - !ruby/object:Gem::Version
@@ -88,7 +80,6 @@ dependencies:
88
80
  type: :development
89
81
  prerelease: false
90
82
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
83
  requirements:
93
84
  - - "~>"
94
85
  - !ruby/object:Gem::Version
@@ -96,7 +87,6 @@ dependencies:
96
87
  - !ruby/object:Gem::Dependency
97
88
  name: rspec-rails
98
89
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
90
  requirements:
101
91
  - - "~>"
102
92
  - !ruby/object:Gem::Version
@@ -104,7 +94,6 @@ dependencies:
104
94
  type: :development
105
95
  prerelease: false
106
96
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
97
  requirements:
109
98
  - - "~>"
110
99
  - !ruby/object:Gem::Version
@@ -138,6 +127,8 @@ files:
138
127
  - gemfiles/rails-3.1.0
139
128
  - gemfiles/rails-3.2.0
140
129
  - gemfiles/rails-4.0.0
130
+ - gemfiles/rails-4.1.0
131
+ - gemfiles/rails-4.2.0
141
132
  - generators/sunspot/sunspot_generator.rb
142
133
  - generators/sunspot/templates/sunspot.yml
143
134
  - install.rb
@@ -193,6 +184,7 @@ files:
193
184
  homepage: http://github.com/outoftime/sunspot/tree/master/sunspot_rails
194
185
  licenses:
195
186
  - MIT
187
+ metadata: {}
196
188
  post_install_message:
197
189
  rdoc_options:
198
190
  - "--webcvs=http://github.com/outoftime/sunspot/tree/master/%s"
@@ -203,22 +195,20 @@ rdoc_options:
203
195
  require_paths:
204
196
  - lib
205
197
  required_ruby_version: !ruby/object:Gem::Requirement
206
- none: false
207
198
  requirements:
208
199
  - - ">="
209
200
  - !ruby/object:Gem::Version
210
201
  version: '0'
211
202
  required_rubygems_version: !ruby/object:Gem::Requirement
212
- none: false
213
203
  requirements:
214
204
  - - ">="
215
205
  - !ruby/object:Gem::Version
216
206
  version: '0'
217
207
  requirements: []
218
208
  rubyforge_project: sunspot
219
- rubygems_version: 1.8.25
209
+ rubygems_version: 2.5.0
220
210
  signing_key:
221
- specification_version: 3
211
+ specification_version: 4
222
212
  summary: Rails integration for the Sunspot Solr search library
223
213
  test_files:
224
214
  - spec/configuration_spec.rb