sunspot_rails 2.2.0 → 2.2.4
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.
- checksums.yaml +7 -0
- data/gemfiles/rails-3.0.0 +1 -0
- data/gemfiles/rails-3.1.0 +1 -0
- data/gemfiles/rails-3.2.0 +1 -0
- data/gemfiles/rails-4.0.0 +1 -0
- data/gemfiles/rails-4.1.0 +21 -0
- data/gemfiles/rails-4.2.0 +21 -0
- data/lib/sunspot/rails/adapters.rb +5 -1
- data/lib/sunspot/rails/configuration.rb +6 -18
- data/lib/sunspot/rails/searchable.rb +72 -13
- data/lib/sunspot/rails/server.rb +10 -28
- data/lib/sunspot/rails/stub_session_proxy.rb +54 -0
- data/lib/sunspot/rails/tasks.rb +2 -0
- data/spec/configuration_spec.rb +1 -10
- data/spec/model_spec.rb +16 -0
- data/spec/rails_template/app/models/post.rb +4 -0
- data/spec/rails_template/config/sunspot.yml +0 -1
- data/spec/rake_task_spec.rb +6 -0
- data/spec/server_spec.rb +0 -4
- data/spec/stub_session_proxy_spec.rb +38 -1
- metadata +9 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 35f1acfbb723240a94351de829da76209d44e561
|
4
|
+
data.tar.gz: 47ee861fe055f37f2a09901f46538007789eb210
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 483a3523c068942840b0fee63727e30a7a506793ad7107ce9df747e0199e61f764a5915873e20ec66789c7ad895b9ceb22e640eb65caf9405523fc9245b41817
|
7
|
+
data.tar.gz: ae29cca30f1103b861cbffe4776f3172e4f6408711738a4e0dbce81dcb51b5e4c90ed0464f76db469de7cb63dc8a0d7adb29a7d58689b7283667bb46330767e7
|
data/gemfiles/rails-3.0.0
CHANGED
data/gemfiles/rails-3.1.0
CHANGED
data/gemfiles/rails-3.2.0
CHANGED
data/gemfiles/rails-4.0.0
CHANGED
@@ -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
|
@@ -21,11 +21,12 @@ module Sunspot #:nodoc:
|
|
21
21
|
class ActiveRecordDataAccessor < Sunspot::Adapters::DataAccessor
|
22
22
|
# options for the find
|
23
23
|
attr_accessor :include
|
24
|
+
attr_accessor :scopes
|
24
25
|
attr_reader :select
|
25
26
|
|
26
27
|
def initialize(clazz)
|
27
28
|
super(clazz)
|
28
|
-
@inherited_attributes = [:include, :select]
|
29
|
+
@inherited_attributes = [:include, :select, :scopes]
|
29
30
|
end
|
30
31
|
|
31
32
|
#
|
@@ -77,6 +78,9 @@ module Sunspot #:nodoc:
|
|
77
78
|
scope = relation
|
78
79
|
scope = scope.includes(@include) if @include.present?
|
79
80
|
scope = scope.select(@select) if @select.present?
|
81
|
+
Array.wrap(@scopes).each do |s|
|
82
|
+
scope = scope.send(s)
|
83
|
+
end
|
80
84
|
scope
|
81
85
|
end
|
82
86
|
|
@@ -12,8 +12,7 @@ module Sunspot #:nodoc:
|
|
12
12
|
# solr:
|
13
13
|
# hostname: localhost
|
14
14
|
# port: 8982
|
15
|
-
#
|
16
|
-
# max_memory: 1G
|
15
|
+
# memory: 1G
|
17
16
|
# solr_jar: /some/path/solr15/start.jar
|
18
17
|
# bind_address: 0.0.0.0
|
19
18
|
# disabled: false
|
@@ -247,10 +246,6 @@ module Sunspot #:nodoc:
|
|
247
246
|
@log_file ||= (user_configuration_from_key('solr', 'log_file') || default_log_file_location )
|
248
247
|
end
|
249
248
|
|
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
249
|
def pid_dir
|
255
250
|
@pid_dir ||= user_configuration_from_key('solr', 'pid_dir') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
|
256
251
|
end
|
@@ -277,22 +272,15 @@ module Sunspot #:nodoc:
|
|
277
272
|
#
|
278
273
|
# Solr start jar
|
279
274
|
#
|
280
|
-
def
|
281
|
-
@
|
282
|
-
end
|
283
|
-
|
284
|
-
#
|
285
|
-
# Minimum java heap size for Solr instance
|
286
|
-
#
|
287
|
-
def min_memory
|
288
|
-
@min_memory ||= user_configuration_from_key('solr', 'min_memory')
|
275
|
+
def solr_executable
|
276
|
+
@solr_executable ||= user_configuration_from_key('solr', 'solr_executable')
|
289
277
|
end
|
290
278
|
|
291
279
|
#
|
292
|
-
#
|
280
|
+
# java heap size for Solr instance
|
293
281
|
#
|
294
|
-
def
|
295
|
-
@
|
282
|
+
def memory
|
283
|
+
@memory ||= user_configuration_from_key('solr', 'memory')
|
296
284
|
end
|
297
285
|
|
298
286
|
#
|
@@ -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
|
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>::
|
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 =>
|
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>::
|
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|
|
@@ -334,15 +374,15 @@ module Sunspot #:nodoc:
|
|
334
374
|
end
|
335
375
|
|
336
376
|
def solr_execute_search(options = {})
|
337
|
-
|
377
|
+
inherited_attributes = [:include, :select, :scopes]
|
378
|
+
options.assert_valid_keys(*inherited_attributes)
|
338
379
|
search = yield
|
339
380
|
unless options.empty?
|
340
381
|
search.build do |query|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
query.data_accessor_for(self).select = options[:select]
|
382
|
+
inherited_attributes.each do |attr|
|
383
|
+
if options[attr]
|
384
|
+
query.data_accessor_for(self).send("#{attr}=", options[attr])
|
385
|
+
end
|
346
386
|
end
|
347
387
|
end
|
348
388
|
end
|
@@ -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
|
data/lib/sunspot/rails/server.rb
CHANGED
@@ -2,32 +2,21 @@ module Sunspot
|
|
2
2
|
module Rails
|
3
3
|
class Server < Sunspot::Solr::Server
|
4
4
|
|
5
|
-
#
|
5
|
+
#
|
6
6
|
# Directory in which to store PID files
|
7
7
|
#
|
8
8
|
def pid_dir
|
9
9
|
configuration.pid_dir || File.join(::Rails.root, 'tmp', 'pids')
|
10
10
|
end
|
11
11
|
|
12
|
-
#
|
12
|
+
#
|
13
13
|
# Name of the PID file
|
14
14
|
#
|
15
15
|
def pid_file
|
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
19
|
#
|
24
|
-
# String:: data_path
|
25
|
-
#
|
26
|
-
def solr_data_dir
|
27
|
-
configuration.data_path
|
28
|
-
end
|
29
|
-
|
30
|
-
#
|
31
20
|
# Directory to use for Solr home.
|
32
21
|
#
|
33
22
|
def solr_home
|
@@ -37,18 +26,18 @@ module Sunspot
|
|
37
26
|
#
|
38
27
|
# Solr start jar
|
39
28
|
#
|
40
|
-
def
|
41
|
-
configuration.
|
29
|
+
def solr_executable
|
30
|
+
configuration.solr_executable || super
|
42
31
|
end
|
43
32
|
|
44
|
-
#
|
33
|
+
#
|
45
34
|
# Address on which to run Solr
|
46
35
|
#
|
47
36
|
def bind_address
|
48
37
|
configuration.bind_address
|
49
38
|
end
|
50
39
|
|
51
|
-
#
|
40
|
+
#
|
52
41
|
# Port on which to run Solr
|
53
42
|
#
|
54
43
|
def port
|
@@ -59,25 +48,18 @@ module Sunspot
|
|
59
48
|
configuration.log_level
|
60
49
|
end
|
61
50
|
|
62
|
-
#
|
51
|
+
#
|
63
52
|
# Log file for Solr. File is in the rails log/ directory.
|
64
53
|
#
|
65
54
|
def log_file
|
66
55
|
File.join(::Rails.root, 'log', "sunspot-solr-#{::Rails.env}.log")
|
67
56
|
end
|
68
57
|
|
69
|
-
#
|
70
|
-
# Minimum Java heap size for Solr
|
71
58
|
#
|
72
|
-
|
73
|
-
configuration.min_memory
|
74
|
-
end
|
75
|
-
|
76
|
-
#
|
77
|
-
# Maximum Java heap size for Solr
|
59
|
+
# Java heap size for Solr
|
78
60
|
#
|
79
|
-
def
|
80
|
-
configuration.
|
61
|
+
def memory
|
62
|
+
configuration.memory
|
81
63
|
end
|
82
64
|
|
83
65
|
private
|
@@ -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
|
data/lib/sunspot/rails/tasks.rb
CHANGED
@@ -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]
|
data/spec/configuration_spec.rb
CHANGED
@@ -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
|
165
|
+
::Rails.stub(:env => 'config_commit_test')
|
175
166
|
@config = Sunspot::Rails::Configuration.new
|
176
167
|
end
|
177
168
|
|
data/spec/model_spec.rb
CHANGED
@@ -165,6 +165,22 @@ describe 'ActiveRecord mixin' do
|
|
165
165
|
end.results.first.attribute_names.sort.should == ['body', 'id', 'title']
|
166
166
|
end
|
167
167
|
|
168
|
+
it 'should use the scoped option from search call to data accessor' do
|
169
|
+
Post.search(:scopes => [:includes_location]) do
|
170
|
+
with :title, 'Test Post'
|
171
|
+
end.data_accessor_for(Post).scopes.should == [:includes_location]
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'should use the scopes option on the data accessor when specified' do
|
175
|
+
@post.update_attribute(:location, Location.create)
|
176
|
+
post = Post.search do
|
177
|
+
with :title, 'Test Post'
|
178
|
+
data_accessor_for(Post).scopes = [:includes_location]
|
179
|
+
end.results.first
|
180
|
+
|
181
|
+
(Rails.version >= '3.1' ? post.association(:location).loaded? : post.loaded_location?).should be_true # Rails 3.1 removed "loaded_#{association}" method
|
182
|
+
end
|
183
|
+
|
168
184
|
it 'should gracefully handle nonexistent records' do
|
169
185
|
post2 = Post.create!(:title => 'Test Post')
|
170
186
|
post2.index!
|
data/spec/rake_task_spec.rb
CHANGED
@@ -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
|
|
data/spec/server_spec.rb
CHANGED
@@ -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 =
|
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.
|
5
|
-
prerelease:
|
4
|
+
version: 2.2.4
|
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:
|
29
|
+
date: 2016-01-21 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.
|
51
|
+
version: 2.2.4
|
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.
|
58
|
+
version: 2.2.4
|
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:
|
209
|
+
rubygems_version: 2.5.0
|
220
210
|
signing_key:
|
221
|
-
specification_version:
|
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
|