UnderpantsGnome-sunspot 0.9.1.1 → 0.9.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,6 +15,16 @@ describe 'retrieving search' do
15
15
  session.search(Post).results.should == [post_2, post_1]
16
16
  end
17
17
 
18
+ # This is a reduction of a crazy bug I found in production where some hits
19
+ # were inexplicably not being populated.
20
+ it 'properly loads results of multiple classes that have the same primary key' do
21
+ Post.reset!
22
+ Namespaced::Comment.reset!
23
+ results = [Post.new, Namespaced::Comment.new]
24
+ stub_results(*results)
25
+ session.search(Post, Namespaced::Comment).results.should == results
26
+ end
27
+
18
28
  if ENV['USE_WILL_PAGINATE']
19
29
 
20
30
  it 'should return search total as attribute of results if pagination is provided' do
@@ -144,7 +154,7 @@ describe 'retrieving search' do
144
154
  end
145
155
  facet_values(result, :published_at).should ==
146
156
  [Time.gm(2009, 04, 07, 20, 25, 23),
147
- Time.gm(2009, 04, 07, 20, 26, 19)]
157
+ Time.gm(2009, 04, 07, 20, 26, 19)]
148
158
  end
149
159
 
150
160
  it 'should return date facet' do
@@ -158,7 +168,7 @@ describe 'retrieving search' do
158
168
  end
159
169
  facet_values(result, :expire_date).should ==
160
170
  [Date.new(2009, 07, 13),
161
- Date.new(2009, 04, 01)]
171
+ Date.new(2009, 04, 01)]
162
172
  end
163
173
 
164
174
  it 'should return boolean facet' do
@@ -223,6 +233,21 @@ describe 'retrieving search' do
223
233
  facet.rows.first.count.should == 3
224
234
  end
225
235
 
236
+ it 'returns limited field facet' do
237
+ stub_query_facet(
238
+ 'category_ids_im:1' => 3,
239
+ 'category_ids_im:3' => 1
240
+ )
241
+ search = session.search(Post) do
242
+ facet :category_ids, :only => [1, 3, 5]
243
+ end
244
+ facet = search.facet(:category_ids)
245
+ facet.rows.first.value.should == 1
246
+ facet.rows.first.count.should == 3
247
+ facet.rows.last.value.should == 3
248
+ facet.rows.last.count.should == 1
249
+ end
250
+
226
251
  it 'should return dynamic string facet' do
227
252
  stub_facet(:"custom_string:test_s", 'two' => 2, 'one' => 1)
228
253
  result = session.search(Post) { dynamic(:custom_string) { facet(:test) }}
@@ -236,6 +261,18 @@ describe 'retrieving search' do
236
261
  result.facet(:blog_id).rows.map { |row| row.instance }.should == blogs
237
262
  end
238
263
 
264
+ it 'returns instantiated facet values for limited field facet' do
265
+ blogs = Array.new(2) { Blog.new }
266
+ stub_query_facet(
267
+ "blog_id_i:#{blogs[0].id}" => 3,
268
+ "blog_id_i:#{blogs[1].id}" => 1
269
+ )
270
+ search = session.search(Post) do
271
+ facet(:blog_id, :only => blogs.map { |blog| blog.id })
272
+ end
273
+ search.facet(:blog_id).rows.map { |row| row.instance }.should == blogs
274
+ end
275
+
239
276
  it 'should only query the persistent store once for an instantiated facet' do
240
277
  query_count = Blog.query_count
241
278
  blogs = Array.new(2) { Blog.new }
@@ -258,9 +295,9 @@ describe 'retrieving search' do
258
295
  end
259
296
  response = {
260
297
  'response' => {
261
- 'docs' => docs,
262
- 'numFound' => count
263
- }
298
+ 'docs' => docs,
299
+ 'numFound' => count
300
+ }
264
301
  }
265
302
  connection.stub!(:select).and_return(response)
266
303
  end
@@ -268,11 +305,11 @@ describe 'retrieving search' do
268
305
  def stub_results(*results)
269
306
  stub_full_results(
270
307
  *results.map do |result|
271
- if result.is_a?(Integer)
272
- result
273
- else
274
- { 'instance' => result }
275
- end
308
+ if result.is_a?(Integer)
309
+ result
310
+ else
311
+ { 'instance' => result }
312
+ end
276
313
  end
277
314
  )
278
315
  end
@@ -280,20 +317,20 @@ describe 'retrieving search' do
280
317
  def stub_facet(name, values)
281
318
  connection.stub!(:select).and_return(
282
319
  'facet_counts' => {
283
- 'facet_fields' => {
284
- name.to_s => values.to_a.sort_by { |value, count| -count }.flatten
285
- }
286
- }
320
+ 'facet_fields' => {
321
+ name.to_s => values.to_a.sort_by { |value, count| -count }.flatten
322
+ }
323
+ }
287
324
  )
288
325
  end
289
326
 
290
327
  def stub_date_facet(name, gap, values)
291
328
  connection.stub!(:select).and_return(
292
329
  'facet_counts' => {
293
- 'facet_dates' => {
294
- name.to_s => { 'gap' => "+#{gap}SECONDS" }.merge(values)
295
- }
296
- }
330
+ 'facet_dates' => {
331
+ name.to_s => { 'gap' => "+#{gap}SECONDS" }.merge(values)
332
+ }
333
+ }
297
334
  )
298
335
  end
299
336
 
@@ -67,24 +67,24 @@ describe 'Session' do
67
67
 
68
68
  it 'should open connection with defaults if nothing specified' do
69
69
  Sunspot.commit
70
- connection.adapter.opts[:url].should == 'http://127.0.0.1:8983/solr'
70
+ connection.opts[:url].should == 'http://127.0.0.1:8983/solr'
71
71
  end
72
72
 
73
73
  it 'should open a connection with custom host' do
74
74
  Sunspot.config.solr.url = 'http://127.0.0.1:8981/solr'
75
75
  Sunspot.commit
76
- connection.adapter.opts[:url].should == 'http://127.0.0.1:8981/solr'
76
+ connection.opts[:url].should == 'http://127.0.0.1:8981/solr'
77
77
  end
78
78
 
79
79
  it 'should use Net::HTTP adapter by default' do
80
80
  Sunspot.commit
81
- connection.adapter.connector.adapter_name.should == :net_http
81
+ connection.adapter.should == :net_http
82
82
  end
83
83
 
84
84
  it 'should use Net::HTTP adapter when specified' do
85
85
  Sunspot.config.http_client = :curb
86
86
  Sunspot.commit
87
- connection.adapter.connector.adapter_name.should == :curb
87
+ connection.adapter.should == :curb
88
88
  end
89
89
  end
90
90
 
@@ -100,7 +100,7 @@ describe 'Session' do
100
100
  config.solr.url = 'http://127.0.0.1:8982/solr'
101
101
  end
102
102
  session.commit
103
- connection.adapter.opts[:url].should == 'http://127.0.0.1:8982/solr'
103
+ connection.opts[:url].should == 'http://127.0.0.1:8982/solr'
104
104
  end
105
105
  end
106
106
 
@@ -153,6 +153,107 @@ describe 'scoped_search' do
153
153
  end
154
154
  end
155
155
 
156
+ describe 'connectives' do
157
+ before :each do
158
+ Sunspot.remove_all
159
+ end
160
+
161
+ it 'should return results that match any restriction in a disjunction' do
162
+ posts = (1..3).map { |i| Post.new(:blog_id => i)}
163
+ Sunspot.index!(posts)
164
+ Sunspot.search(Post) do
165
+ any_of do
166
+ with(:blog_id, 1)
167
+ with(:blog_id, 2)
168
+ end
169
+ end.results.should == posts[0..1]
170
+ end
171
+
172
+ it 'should return results that match a nested conjunction in a disjunction' do
173
+ posts = [
174
+ Post.new(:title => 'No', :blog_id => 1),
175
+ Post.new(:title => 'Yes', :blog_id => 2),
176
+ Post.new(:title => 'Yes', :blog_id => 3),
177
+ Post.new(:title => 'No', :blog_id => 2)
178
+ ]
179
+ Sunspot.index!(posts)
180
+ Sunspot.search(Post) do
181
+ any_of do
182
+ with(:blog_id, 1)
183
+ all_of do
184
+ with(:blog_id, 2)
185
+ with(:title, 'Yes')
186
+ end
187
+ end
188
+ end.results.should == posts[0..1]
189
+ end
190
+
191
+ it 'should return results that match a conjunction with a negated restriction' do
192
+ posts = [
193
+ Post.new(:title => 'No', :blog_id => 1),
194
+ Post.new(:title => 'Yes', :blog_id => 2),
195
+ Post.new(:title => 'No', :blog_id => 2)
196
+ ]
197
+ Sunspot.index!(posts)
198
+ search = Sunspot.search(Post) do
199
+ any_of do
200
+ with(:blog_id, 1)
201
+ without(:title, 'No')
202
+ end
203
+ end
204
+ search.results.should == posts[0..1]
205
+ end
206
+
207
+ it 'should return results that match a conjunction with a disjunction with a conjunction with a negated restriction' do
208
+ posts = [
209
+ Post.new(:title => 'Yes', :ratings_average => 2.0),
210
+ Post.new(:blog_id => 1, :category_ids => [4], :ratings_average => 2.0),
211
+ Post.new(:blog_id => 1),
212
+ Post.new(:blog_id => 2),
213
+ Post.new(:blog_id => 1, :ratings_average => 2.0)
214
+ ]
215
+ Sunspot.index!(posts)
216
+ search = Sunspot.search(Post) do
217
+ any_of do
218
+ with(:title, 'Yes')
219
+ all_of do
220
+ with(:blog_id, 1)
221
+ any_of do
222
+ with(:category_ids, 4)
223
+ without(:average_rating, 2.0)
224
+ end
225
+ end
226
+ end
227
+ end
228
+ search.results.should == posts[0..2]
229
+ end
230
+
231
+ it 'should return results that match a disjunction with a negated restriction and a nested disjunction in a conjunction with a negated restriction' do
232
+ posts = [
233
+ Post.new,
234
+ Post.new(:title => 'Yes', :blog_id => 1, :category_ids => [4], :ratings_average => 2.0),
235
+ Post.new(:title => 'Yes', :blog_id => 1),
236
+ Post.new(:title => 'Yes'),
237
+ Post.new(:title => 'Yes', :category_ids => [4], :ratings_average => 2.0),
238
+ Post.new(:title => 'Yes', :blog_id => 1, :ratings_average => 2.0)
239
+ ]
240
+ Sunspot.index!(posts)
241
+ search = Sunspot.search(Post) do
242
+ any_of do
243
+ without(:title, 'Yes')
244
+ all_of do
245
+ with(:blog_id, 1)
246
+ any_of do
247
+ with(:category_ids, 4)
248
+ without(:average_rating, 2.0)
249
+ end
250
+ end
251
+ end
252
+ end
253
+ search.results.should == posts[0..2]
254
+ end
255
+ end
256
+
156
257
  describe 'multiple column ordering' do
157
258
  before do
158
259
  Sunspot.remove_all
@@ -1 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ Spec::Runner.configure do |config|
4
+ config.before(:all) do
5
+ Sunspot.config.solr.url = 'http://localhost:8983/solr'
6
+ end
7
+ end
@@ -1,5 +1,13 @@
1
1
  module Mock
2
2
  class ConnectionFactory
3
+ def connect(opts)
4
+ if @instance
5
+ raise('Factory can only create an instance once!')
6
+ else
7
+ @instance = Connection.new(opts.delete(:adapter), opts)
8
+ end
9
+ end
10
+
3
11
  def new(adapter = nil, opts = nil)
4
12
  if @instance
5
13
  raise('Factory can only create an instance once!')
@@ -5,6 +5,13 @@ class MockRecord
5
5
 
6
6
  attr_reader :id
7
7
 
8
+ class <<self
9
+ def reset!
10
+ IDS[name.to_sym] = 0
11
+ INSTANCES[name.to_sym] = {}
12
+ end
13
+ end
14
+
8
15
  def initialize(attrs = {})
9
16
  attrs.each_pair do |name, value|
10
17
  send(:"#{name}=", value)
data/spec/mocks/post.rb CHANGED
@@ -68,3 +68,6 @@ Sunspot.setup(Post) do
68
68
  end
69
69
  end
70
70
  end
71
+
72
+ class PhotoPost < Post
73
+ end
data/tasks/gemspec.rake CHANGED
@@ -1,16 +1,15 @@
1
1
  begin
2
- gem 'technicalpickles-jeweler', '~> 1.0.1'
3
2
  require 'jeweler'
4
3
  Jeweler::Tasks.new do |s|
5
4
  s.name = 'sunspot'
6
- s.executables = 'sunspot-solr'
5
+ s.executables = ['sunspot-solr', 'sunspot-configure-solr']
7
6
  s.summary = 'Library for expressive, powerful interaction with the Solr search engine'
8
7
  s.email = 'mat@patch.com'
9
8
  s.homepage = 'http://github.com/outoftime/sunspot'
10
9
  s.description = 'Library for expressive, powerful interaction with the Solr search engine'
11
10
  s.authors = ['Mat Brown', 'Peer Allan', 'Dmitriy Dzema', 'Benjamin Krause']
12
11
  s.files = FileList['[A-Z]*', '{bin,lib,spec,tasks,templates}/**/*', 'solr/{etc,lib,webapps}/**/*', 'solr/solr/conf/*', 'solr/start.jar']
13
- s.add_dependency 'mwmitchell-rsolr', '>= 0.8.9'
12
+ s.add_dependency 'mwmitchell-rsolr', '= 0.9.6'
14
13
  s.add_dependency 'daemons', '~> 1.0'
15
14
  s.add_dependency 'optiflag', '~> 0.6.5'
16
15
  s.add_dependency 'haml', '~> 2.2'
data/tasks/rdoc.rake CHANGED
@@ -1,5 +1,6 @@
1
1
  gem 'mislav-hanna'
2
2
  require 'hanna/rdoctask'
3
+ require 'jeweler'
3
4
 
4
5
  Rake::RDocTask.new(:doc) do |rdoc|
5
6
  version = Jeweler::VersionHelper.new(File.join(File.dirname(__FILE__), '..')).to_s
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: UnderpantsGnome-sunspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1.1
4
+ version: 0.9.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Brown
@@ -12,8 +12,8 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2009-07-21 00:00:00 -07:00
16
- default_executable: sunspot-solr
15
+ date: 2009-09-13 00:00:00 -07:00
16
+ default_executable:
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: mwmitchell-rsolr
@@ -21,9 +21,9 @@ dependencies:
21
21
  version_requirement:
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.9
26
+ version: 0.9.6
27
27
  version:
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: daemons
@@ -79,6 +79,7 @@ description: Library for expressive, powerful interaction with the Solr search e
79
79
  email: mat@patch.com
80
80
  executables:
81
81
  - sunspot-solr
82
+ - sunspot-configure-solr
82
83
  extensions: []
83
84
 
84
85
  extra_rdoc_files:
@@ -98,8 +99,6 @@ files:
98
99
  - lib/sunspot/composite_setup.rb
99
100
  - lib/sunspot/configuration.rb
100
101
  - lib/sunspot/data_extractor.rb
101
- - lib/sunspot/date_facet.rb
102
- - lib/sunspot/date_facet_row.rb
103
102
  - lib/sunspot/dsl.rb
104
103
  - lib/sunspot/dsl/field_query.rb
105
104
  - lib/sunspot/dsl/fields.rb
@@ -109,6 +108,7 @@ files:
109
108
  - lib/sunspot/dsl/scope.rb
110
109
  - lib/sunspot/dsl/search.rb
111
110
  - lib/sunspot/facet.rb
111
+ - lib/sunspot/facet_data.rb
112
112
  - lib/sunspot/facet_row.rb
113
113
  - lib/sunspot/field.rb
114
114
  - lib/sunspot/field_factory.rb
@@ -124,12 +124,11 @@ files:
124
124
  - lib/sunspot/query/pagination.rb
125
125
  - lib/sunspot/query/query_facet.rb
126
126
  - lib/sunspot/query/query_facet_row.rb
127
+ - lib/sunspot/query/query_field_facet.rb
127
128
  - lib/sunspot/query/restriction.rb
128
129
  - lib/sunspot/query/scope.rb
129
130
  - lib/sunspot/query/sort.rb
130
131
  - lib/sunspot/query/sort_composite.rb
131
- - lib/sunspot/query_facet.rb
132
- - lib/sunspot/query_facet_row.rb
133
132
  - lib/sunspot/schema.rb
134
133
  - lib/sunspot/search.rb
135
134
  - lib/sunspot/search/hit.rb
@@ -188,6 +187,7 @@ files:
188
187
  - templates/schema.xml.haml
189
188
  has_rdoc: true
190
189
  homepage: http://github.com/outoftime/sunspot
190
+ licenses:
191
191
  post_install_message:
192
192
  rdoc_options:
193
193
  - --charset=UTF-8
@@ -213,33 +213,33 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
213
  requirements: []
214
214
 
215
215
  rubyforge_project:
216
- rubygems_version: 1.2.0
216
+ rubygems_version: 1.3.5
217
217
  signing_key:
218
- specification_version: 3
218
+ specification_version: 2
219
219
  summary: Library for expressive, powerful interaction with the Solr search engine
220
220
  test_files:
221
- - spec/spec_helper.rb
222
- - spec/integration/spec_helper.rb
221
+ - spec/api/adapters_spec.rb
222
+ - spec/api/build_search_spec.rb
223
+ - spec/api/indexer_spec.rb
224
+ - spec/api/query_spec.rb
225
+ - spec/api/search_retrieval_spec.rb
226
+ - spec/api/session_spec.rb
227
+ - spec/api/spec_helper.rb
228
+ - spec/api/sunspot_spec.rb
229
+ - spec/integration/dynamic_fields_spec.rb
223
230
  - spec/integration/faceting_spec.rb
224
- - spec/integration/scoped_search_spec.rb
225
231
  - spec/integration/keyword_search_spec.rb
226
- - spec/integration/dynamic_fields_spec.rb
232
+ - spec/integration/scoped_search_spec.rb
233
+ - spec/integration/spec_helper.rb
227
234
  - spec/integration/stored_fields_spec.rb
228
235
  - spec/integration/test_pagination.rb
229
- - spec/mocks/mock_record.rb
230
- - spec/mocks/blog.rb
231
236
  - spec/mocks/adapters.rb
237
+ - spec/mocks/blog.rb
238
+ - spec/mocks/comment.rb
239
+ - spec/mocks/connection.rb
232
240
  - spec/mocks/mock_adapter.rb
233
- - spec/mocks/user.rb
241
+ - spec/mocks/mock_record.rb
234
242
  - spec/mocks/photo.rb
235
243
  - spec/mocks/post.rb
236
- - spec/mocks/comment.rb
237
- - spec/mocks/connection.rb
238
- - spec/api/search_retrieval_spec.rb
239
- - spec/api/spec_helper.rb
240
- - spec/api/session_spec.rb
241
- - spec/api/adapters_spec.rb
242
- - spec/api/build_search_spec.rb
243
- - spec/api/sunspot_spec.rb
244
- - spec/api/indexer_spec.rb
245
- - spec/api/query_spec.rb
244
+ - spec/mocks/user.rb
245
+ - spec/spec_helper.rb