sunspot 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/History.txt +10 -0
  4. data/lib/sunspot.rb +6 -6
  5. data/lib/sunspot/batcher.rb +1 -1
  6. data/lib/sunspot/dsl.rb +1 -1
  7. data/lib/sunspot/dsl/field_query.rb +47 -7
  8. data/lib/sunspot/dsl/field_stats.rb +18 -0
  9. data/lib/sunspot/dsl/fields.rb +10 -1
  10. data/lib/sunspot/field.rb +15 -0
  11. data/lib/sunspot/field_factory.rb +33 -0
  12. data/lib/sunspot/indexer.rb +1 -0
  13. data/lib/sunspot/query.rb +1 -1
  14. data/lib/sunspot/query/common_query.rb +5 -0
  15. data/lib/sunspot/query/field_stats.rb +28 -0
  16. data/lib/sunspot/query/geofilt.rb +8 -3
  17. data/lib/sunspot/query/restriction.rb +5 -2
  18. data/lib/sunspot/query/sort.rb +35 -0
  19. data/lib/sunspot/search.rb +2 -1
  20. data/lib/sunspot/search/abstract_search.rb +57 -35
  21. data/lib/sunspot/search/field_facet.rb +4 -4
  22. data/lib/sunspot/search/field_stats.rb +21 -0
  23. data/lib/sunspot/search/stats_facet.rb +25 -0
  24. data/lib/sunspot/search/stats_row.rb +66 -0
  25. data/lib/sunspot/session.rb +6 -6
  26. data/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +6 -4
  27. data/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +16 -8
  28. data/lib/sunspot/setup.rb +6 -0
  29. data/lib/sunspot/version.rb +1 -1
  30. data/spec/api/class_set_spec.rb +3 -3
  31. data/spec/api/indexer/fixed_fields_spec.rb +5 -0
  32. data/spec/api/indexer/removal_spec.rb +13 -3
  33. data/spec/api/query/faceting_examples.rb +19 -0
  34. data/spec/api/query/join_spec.rb +19 -0
  35. data/spec/api/query/standard_spec.rb +1 -0
  36. data/spec/api/query/stats_examples.rb +66 -0
  37. data/spec/api/search/paginated_collection_spec.rb +1 -1
  38. data/spec/api/search/stats_spec.rb +94 -0
  39. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +8 -2
  40. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +14 -2
  41. data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +3 -3
  42. data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +1 -1
  43. data/spec/helpers/search_helper.rb +30 -0
  44. data/spec/integration/highlighting_spec.rb +3 -3
  45. data/spec/integration/indexing_spec.rb +3 -2
  46. data/spec/integration/scoped_search_spec.rb +30 -0
  47. data/spec/integration/stats_spec.rb +47 -0
  48. data/spec/mocks/photo.rb +14 -1
  49. data/sunspot.gemspec +1 -2
  50. data/tasks/rdoc.rake +22 -14
  51. metadata +32 -41
@@ -25,8 +25,8 @@ describe 'keyword highlighting' do
25
25
 
26
26
  it "should process multiple keyword request on different fields with highlights correctly" do
27
27
  search_results = nil
28
- lambda do
29
- search_results = Sunspot.search(Post) do
28
+ expect do
29
+ search_results = Sunspot.search(Post) do
30
30
  keywords 'Lorem ipsum', :fields => [:body] do
31
31
  highlight :body
32
32
  end
@@ -34,7 +34,7 @@ describe 'keyword highlighting' do
34
34
  highlight :title
35
35
  end
36
36
  end
37
- end.should_not raise_error(RSolr::Error::Http)
37
+ end.to_not raise_error
38
38
  search_results.results.length.should eq(1)
39
39
  search_results.results.first.should eq(@posts.last)
40
40
  # this one might be a Solr bug, therefore not related to Sunspot itself
@@ -25,10 +25,11 @@ describe 'indexing' do
25
25
  Sunspot.remove_all!
26
26
  posts = [Post.new(:title => 'birds'), Post.new(:title => 'monkeys')]
27
27
  Sunspot.index!(posts)
28
- Sunspot.remove! do
28
+
29
+ Sunspot.remove!(Post) do
29
30
  with(:title, 'birds')
30
31
  end
31
- Sunspot.search(Post).should have(2).results
32
+ Sunspot.search(Post).should have(1).results
32
33
  end
33
34
 
34
35
 
@@ -457,4 +457,34 @@ describe 'scoped_search' do
457
457
  end
458
458
  end
459
459
  end
460
+
461
+ describe 'ordering by function' do
462
+ before :all do
463
+ Sunspot.remove_all
464
+ @p1 = Post.new(:blog_id => 1, :category_ids => [3])
465
+ @p2 = Post.new(:blog_id => 2, :category_ids => [1])
466
+ Sunspot.index([@p1,@p2])
467
+ Sunspot.commit
468
+ end
469
+ it 'should order by sum' do
470
+ # 1+3 > 2+1
471
+ search = Sunspot.search(Post) {order_by_function :sum, :blog_id, :primary_category_id, :desc}
472
+ search.results.first.should == @p1
473
+ end
474
+ it 'should order by product and sum' do
475
+ # 1 * (1+3) < 2 * (2+1)
476
+ search = Sunspot.search(Post) { order_by_function :product, :blog_id, [:sum,:blog_id,:primary_category_id], :desc}
477
+ search.results.first.should == @p2
478
+ end
479
+ it 'should accept string literals' do
480
+ # (1 * -2) > (2 * -2)
481
+ search = Sunspot.search(Post) {order_by_function :product, :blog_id, '-2', :desc}
482
+ search.results.first.should == @p1
483
+ end
484
+ it 'should accept non-string literals' do
485
+ # (1 * -2) > (2 * -2)
486
+ search = Sunspot.search(Post) {order_by_function :product, :blog_id, -2, :desc}
487
+ search.results.first.should == @p1
488
+ end
489
+ end
460
490
  end
@@ -0,0 +1,47 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe 'search stats' do
4
+ before :each do
5
+ Sunspot.remove_all
6
+ @posts = Post.new(:ratings_average => 4.0, :blog_id => 2),
7
+ Post.new(:ratings_average => 4.0, :blog_id => 1),
8
+ Post.new(:ratings_average => 3.0, :blog_id => 2)
9
+ Sunspot.index!(@posts)
10
+ end
11
+
12
+ it 'returns minimum stats' do
13
+ Sunspot.search(Post) do
14
+ stats :average_rating
15
+ end.stats(:average_rating).min.should == 3.0
16
+ end
17
+
18
+ it 'returns maximum stats' do
19
+ Sunspot.search(Post) do
20
+ stats :average_rating
21
+ end.stats(:average_rating).max.should == 4.0
22
+ end
23
+
24
+ it 'returns count stats' do
25
+ Sunspot.search(Post) do
26
+ stats :average_rating
27
+ end.stats(:average_rating).count.should == 3
28
+ end
29
+
30
+ describe 'facets' do
31
+ it 'returns minimum on facet row with two blog ids' do
32
+ Sunspot.search(Post) do
33
+ stats :average_rating do
34
+ facet :blog_id
35
+ end
36
+ end.stats(:average_rating).facet(:blog_id).rows[1].min.should == 3.0
37
+ end
38
+
39
+ it 'returns maximum on facet row with two blog ids' do
40
+ Sunspot.search(Post) do
41
+ stats :average_rating do
42
+ facet :blog_id
43
+ end
44
+ end.stats(:average_rating).facet(:blog_id).rows[1].max.should == 4.0
45
+ end
46
+ end
47
+ end
@@ -1,11 +1,24 @@
1
1
  class Photo < MockRecord
2
- attr_accessor :caption, :lat, :lng, :size, :average_rating, :created_at
2
+ attr_accessor :caption, :lat, :lng, :size, :average_rating, :created_at, :post_id, :photo_container_id
3
3
  end
4
4
 
5
5
  Sunspot.setup(Photo) do
6
6
  text :caption, :default_boost => 1.5
7
+ string :caption
8
+ integer :photo_container_id
7
9
  boost 0.75
8
10
  integer :size, :trie => true
9
11
  float :average_rating, :trie => true
10
12
  time :created_at, :trie => true
11
13
  end
14
+
15
+ class PhotoContainer < MockRecord
16
+ def id
17
+ 1
18
+ end
19
+ end
20
+
21
+ Sunspot.setup(PhotoContainer) do
22
+ join(:caption, :type => :string, :join_string => 'from=photo_container_id to=id')
23
+ join(:photo_rating, :type => :trie_float, :join_string => 'from=photo_container_id to=id', :as => 'average_rating_ft')
24
+ end
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ['Mat Brown', 'Peer Allan', 'Dmitriy Dzema', 'Benjamin Krause', 'Marcel de Graaf', 'Brandon Keepers', 'Peter Berkenbosch',
10
10
  'Brian Atkinson', 'Tom Coleman', 'Matt Mitchell', 'Nathan Beyer', 'Kieran Topping', 'Nicolas Braem', 'Jeremy Ashkenas',
11
- 'Dylan Vaughn', 'Brian Durand', 'Sam Granieri', 'Nick Zadrozny', 'Jason Ronallo']
11
+ 'Dylan Vaughn', 'Brian Durand', 'Sam Granieri', 'Nick Zadrozny', 'Jason Ronallo', 'Ryan Wallace', 'Nicholas Jakobsen']
12
12
  s.email = ["mat@patch.com"]
13
13
  s.homepage = "http://outoftime.github.com/sunspot"
14
14
  s.summary = 'Library for expressive, powerful interaction with the Solr search engine'
@@ -30,7 +30,6 @@ Gem::Specification.new do |s|
30
30
  s.add_dependency 'pr_geohash', '~>1.0'
31
31
 
32
32
  s.add_development_dependency 'rspec', '~>2.6.0'
33
- s.add_development_dependency 'hanna'
34
33
 
35
34
  s.rdoc_options << '--webcvs=http://github.com/outoftime/sunspot/tree/master/%s' <<
36
35
  '--title' << 'Sunspot - Solr-powered search for Ruby objects - API Documentation' <<
@@ -1,19 +1,27 @@
1
- begin
2
- require 'hanna/rdoctask'
3
- rescue LoadError
4
- if require 'rubygems'
5
- retry
1
+ require 'sunspot/version'
2
+
3
+ rdoc_task =
4
+ begin
5
+ require 'rdoc/task'
6
+ RDoc::Task
7
+ rescue LoadError
8
+ begin
9
+ require 'rake/rdoctask'
10
+ Rake::RDocTask
11
+ rescue
12
+ nil
13
+ end
6
14
  end
7
- # It's OK if hanna isn't installed.
8
- end
9
15
 
10
- Rake::RDocTask.new(:doc) do |rdoc|
11
- version = Sunspot::VERSION
12
- rdoc.title = "Sunspot #{version} - Solr-powered search for Ruby objects - API Documentation"
13
- rdoc.main = 'README.md'
14
- rdoc.rdoc_files.include('README.md', 'lib/sunspot.rb', 'lib/sunspot/**/*.rb')
15
- rdoc.rdoc_dir = 'doc'
16
- rdoc.options << "--webcvs=http://github.com/outoftime/sunspot/tree/v#{version}/%s" << '--title' << 'Sunspot - Solr-powered search for Ruby objects - API Documentation'
16
+ if rdoc_task
17
+ rdoc_task.new(:doc) do |rdoc|
18
+ version = Sunspot::VERSION
19
+ rdoc.title = "Sunspot #{version} - Solr-powered search for Ruby objects - API Documentation"
20
+ rdoc.main = '../README.md'
21
+ rdoc.rdoc_files.include('../README.md', 'lib/sunspot.rb', 'lib/sunspot/**/*.rb')
22
+ rdoc.rdoc_dir = 'doc'
23
+ rdoc.options << "--webcvs=http://github.com/outoftime/sunspot/tree/v#{version}/%s" << '--title' << 'Sunspot - Solr-powered search for Ruby objects - API Documentation'
24
+ end
17
25
  end
18
26
 
19
27
  namespace :doc do
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunspot
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
5
- prerelease:
4
+ version: 2.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Mat Brown
@@ -24,75 +23,55 @@ authors:
24
23
  - Sam Granieri
25
24
  - Nick Zadrozny
26
25
  - Jason Ronallo
26
+ - Ryan Wallace
27
+ - Nicholas Jakobsen
27
28
  autorequire:
28
29
  bindir: bin
29
30
  cert_chain: []
30
- date: 2013-10-25 00:00:00.000000000 Z
31
+ date: 2014-05-07 00:00:00.000000000 Z
31
32
  dependencies:
32
33
  - !ruby/object:Gem::Dependency
33
34
  name: rsolr
34
35
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
36
  requirements:
37
- - - ~>
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: 1.0.7
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
43
  requirements:
45
- - - ~>
44
+ - - "~>"
46
45
  - !ruby/object:Gem::Version
47
46
  version: 1.0.7
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: pr_geohash
50
49
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
50
  requirements:
53
- - - ~>
51
+ - - "~>"
54
52
  - !ruby/object:Gem::Version
55
53
  version: '1.0'
56
54
  type: :runtime
57
55
  prerelease: false
58
56
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
57
  requirements:
61
- - - ~>
58
+ - - "~>"
62
59
  - !ruby/object:Gem::Version
63
60
  version: '1.0'
64
61
  - !ruby/object:Gem::Dependency
65
62
  name: rspec
66
63
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
64
  requirements:
69
- - - ~>
65
+ - - "~>"
70
66
  - !ruby/object:Gem::Version
71
67
  version: 2.6.0
72
68
  type: :development
73
69
  prerelease: false
74
70
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
71
  requirements:
77
- - - ~>
72
+ - - "~>"
78
73
  - !ruby/object:Gem::Version
79
74
  version: 2.6.0
80
- - !ruby/object:Gem::Dependency
81
- name: hanna
82
- requirement: !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- type: :development
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
- requirements:
93
- - - '>='
94
- - !ruby/object:Gem::Version
95
- version: '0'
96
75
  description: |2
97
76
  Sunspot is a library providing a powerful, all-ruby API for the Solr search engine. Sunspot manages the configuration of persistent
98
77
  Ruby classes for search and indexing and exposes Solr's most powerful features through a collection of DSLs. Complex search operations
@@ -103,7 +82,7 @@ executables: []
103
82
  extensions: []
104
83
  extra_rdoc_files: []
105
84
  files:
106
- - .gitignore
85
+ - ".gitignore"
107
86
  - Gemfile
108
87
  - History.txt
109
88
  - LICENSE
@@ -121,6 +100,7 @@ files:
121
100
  - lib/sunspot/dsl/adjustable.rb
122
101
  - lib/sunspot/dsl/field_group.rb
123
102
  - lib/sunspot/dsl/field_query.rb
103
+ - lib/sunspot/dsl/field_stats.rb
124
104
  - lib/sunspot/dsl/fields.rb
125
105
  - lib/sunspot/dsl/fulltext.rb
126
106
  - lib/sunspot/dsl/function.rb
@@ -147,6 +127,7 @@ files:
147
127
  - lib/sunspot/query/dismax.rb
148
128
  - lib/sunspot/query/field_facet.rb
149
129
  - lib/sunspot/query/field_group.rb
130
+ - lib/sunspot/query/field_stats.rb
150
131
  - lib/sunspot/query/filter.rb
151
132
  - lib/sunspot/query/function_query.rb
152
133
  - lib/sunspot/query/geo.rb
@@ -170,6 +151,7 @@ files:
170
151
  - lib/sunspot/search/facet_row.rb
171
152
  - lib/sunspot/search/field_facet.rb
172
153
  - lib/sunspot/search/field_group.rb
154
+ - lib/sunspot/search/field_stats.rb
173
155
  - lib/sunspot/search/group.rb
174
156
  - lib/sunspot/search/highlight.rb
175
157
  - lib/sunspot/search/hit.rb
@@ -179,6 +161,8 @@ files:
179
161
  - lib/sunspot/search/query_facet.rb
180
162
  - lib/sunspot/search/range_facet.rb
181
163
  - lib/sunspot/search/standard_search.rb
164
+ - lib/sunspot/search/stats_facet.rb
165
+ - lib/sunspot/search/stats_row.rb
182
166
  - lib/sunspot/session.rb
183
167
  - lib/sunspot/session_proxy.rb
184
168
  - lib/sunspot/session_proxy/abstract_session_proxy.rb
@@ -220,12 +204,14 @@ files:
220
204
  - spec/api/query/geo_examples.rb
221
205
  - spec/api/query/group_spec.rb
222
206
  - spec/api/query/highlighting_examples.rb
207
+ - spec/api/query/join_spec.rb
223
208
  - spec/api/query/more_like_this_spec.rb
224
209
  - spec/api/query/ordering_pagination_examples.rb
225
210
  - spec/api/query/scope_examples.rb
226
211
  - spec/api/query/spatial_examples.rb
227
212
  - spec/api/query/spec_helper.rb
228
213
  - spec/api/query/standard_spec.rb
214
+ - spec/api/query/stats_examples.rb
229
215
  - spec/api/query/text_field_scoping_examples.rb
230
216
  - spec/api/query/types_spec.rb
231
217
  - spec/api/search/dynamic_fields_spec.rb
@@ -236,6 +222,7 @@ files:
236
222
  - spec/api/search/results_spec.rb
237
223
  - spec/api/search/search_spec.rb
238
224
  - spec/api/search/spec_helper.rb
225
+ - spec/api/search/stats_spec.rb
239
226
  - spec/api/session_proxy/class_sharding_session_proxy_spec.rb
240
227
  - spec/api/session_proxy/id_sharding_session_proxy_spec.rb
241
228
  - spec/api/session_proxy/master_slave_session_proxy_spec.rb
@@ -263,6 +250,7 @@ files:
263
250
  - spec/integration/local_search_spec.rb
264
251
  - spec/integration/more_like_this_spec.rb
265
252
  - spec/integration/scoped_search_spec.rb
253
+ - spec/integration/stats_spec.rb
266
254
  - spec/integration/stored_fields_spec.rb
267
255
  - spec/integration/test_pagination.rb
268
256
  - spec/integration/unicode_spec.rb
@@ -286,32 +274,31 @@ files:
286
274
  homepage: http://outoftime.github.com/sunspot
287
275
  licenses:
288
276
  - MIT
277
+ metadata: {}
289
278
  post_install_message:
290
279
  rdoc_options:
291
- - --webcvs=http://github.com/outoftime/sunspot/tree/master/%s
292
- - --title
280
+ - "--webcvs=http://github.com/outoftime/sunspot/tree/master/%s"
281
+ - "--title"
293
282
  - Sunspot - Solr-powered search for Ruby objects - API Documentation
294
- - --main
283
+ - "--main"
295
284
  - README.rdoc
296
285
  require_paths:
297
286
  - lib
298
287
  required_ruby_version: !ruby/object:Gem::Requirement
299
- none: false
300
288
  requirements:
301
- - - '>='
289
+ - - ">="
302
290
  - !ruby/object:Gem::Version
303
291
  version: '0'
304
292
  required_rubygems_version: !ruby/object:Gem::Requirement
305
- none: false
306
293
  requirements:
307
- - - '>='
294
+ - - ">="
308
295
  - !ruby/object:Gem::Version
309
296
  version: '0'
310
297
  requirements: []
311
298
  rubyforge_project: sunspot
312
- rubygems_version: 1.8.25
299
+ rubygems_version: 2.2.2
313
300
  signing_key:
314
- specification_version: 3
301
+ specification_version: 4
315
302
  summary: Library for expressive, powerful interaction with the Solr search engine
316
303
  test_files:
317
304
  - spec/api/adapters_spec.rb
@@ -337,12 +324,14 @@ test_files:
337
324
  - spec/api/query/geo_examples.rb
338
325
  - spec/api/query/group_spec.rb
339
326
  - spec/api/query/highlighting_examples.rb
327
+ - spec/api/query/join_spec.rb
340
328
  - spec/api/query/more_like_this_spec.rb
341
329
  - spec/api/query/ordering_pagination_examples.rb
342
330
  - spec/api/query/scope_examples.rb
343
331
  - spec/api/query/spatial_examples.rb
344
332
  - spec/api/query/spec_helper.rb
345
333
  - spec/api/query/standard_spec.rb
334
+ - spec/api/query/stats_examples.rb
346
335
  - spec/api/query/text_field_scoping_examples.rb
347
336
  - spec/api/query/types_spec.rb
348
337
  - spec/api/search/dynamic_fields_spec.rb
@@ -353,6 +342,7 @@ test_files:
353
342
  - spec/api/search/results_spec.rb
354
343
  - spec/api/search/search_spec.rb
355
344
  - spec/api/search/spec_helper.rb
345
+ - spec/api/search/stats_spec.rb
356
346
  - spec/api/session_proxy/class_sharding_session_proxy_spec.rb
357
347
  - spec/api/session_proxy/id_sharding_session_proxy_spec.rb
358
348
  - spec/api/session_proxy/master_slave_session_proxy_spec.rb
@@ -380,6 +370,7 @@ test_files:
380
370
  - spec/integration/local_search_spec.rb
381
371
  - spec/integration/more_like_this_spec.rb
382
372
  - spec/integration/scoped_search_spec.rb
373
+ - spec/integration/stats_spec.rb
383
374
  - spec/integration/stored_fields_spec.rb
384
375
  - spec/integration/test_pagination.rb
385
376
  - spec/integration/unicode_spec.rb