sunspot 2.2.7 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/Appraisals +7 -0
  5. data/Gemfile +0 -8
  6. data/lib/sunspot/adapters.rb +4 -1
  7. data/lib/sunspot/configuration.rb +1 -0
  8. data/lib/sunspot/data_extractor.rb +36 -6
  9. data/lib/sunspot/dsl/field_query.rb +11 -0
  10. data/lib/sunspot/dsl/field_stats.rb +7 -0
  11. data/lib/sunspot/dsl/fields.rb +16 -0
  12. data/lib/sunspot/dsl/group.rb +10 -0
  13. data/lib/sunspot/dsl/scope.rb +23 -18
  14. data/lib/sunspot/field.rb +11 -0
  15. data/lib/sunspot/field_factory.rb +6 -2
  16. data/lib/sunspot/query/abstract_json_field_facet.rb +70 -0
  17. data/lib/sunspot/query/bbox.rb +5 -1
  18. data/lib/sunspot/query/date_field_json_facet.rb +25 -0
  19. data/lib/sunspot/query/field_json_facet.rb +19 -0
  20. data/lib/sunspot/query/field_stats.rb +35 -2
  21. data/lib/sunspot/query/group.rb +4 -5
  22. data/lib/sunspot/query/join.rb +2 -4
  23. data/lib/sunspot/query/range_json_facet.rb +28 -0
  24. data/lib/sunspot/query/restriction.rb +19 -4
  25. data/lib/sunspot/query.rb +3 -3
  26. data/lib/sunspot/schema.rb +10 -2
  27. data/lib/sunspot/search/abstract_search.rb +14 -1
  28. data/lib/sunspot/search/field_json_facet.rb +33 -0
  29. data/lib/sunspot/search/hit.rb +6 -1
  30. data/lib/sunspot/search/hit_enumerable.rb +4 -1
  31. data/lib/sunspot/search/json_facet_row.rb +40 -0
  32. data/lib/sunspot/search/json_facet_stats.rb +23 -0
  33. data/lib/sunspot/search/standard_search.rb +2 -3
  34. data/lib/sunspot/search/stats_json_row.rb +82 -0
  35. data/lib/sunspot/search/stats_row.rb +3 -1
  36. data/lib/sunspot/search.rb +4 -3
  37. data/lib/sunspot/session.rb +13 -5
  38. data/lib/sunspot/setup.rb +31 -0
  39. data/lib/sunspot/util.rb +23 -0
  40. data/lib/sunspot/version.rb +1 -1
  41. data/spec/api/adapters_spec.rb +32 -19
  42. data/spec/api/batcher_spec.rb +15 -15
  43. data/spec/api/binding_spec.rb +3 -3
  44. data/spec/api/class_set_spec.rb +3 -3
  45. data/spec/api/data_extractor_spec.rb +39 -0
  46. data/spec/api/hit_enumerable_spec.rb +32 -9
  47. data/spec/api/indexer/attributes_spec.rb +31 -31
  48. data/spec/api/indexer/batch_spec.rb +8 -7
  49. data/spec/api/indexer/dynamic_fields_spec.rb +8 -8
  50. data/spec/api/indexer/fixed_fields_spec.rb +12 -12
  51. data/spec/api/indexer/fulltext_spec.rb +8 -8
  52. data/spec/api/indexer/removal_spec.rb +14 -14
  53. data/spec/api/indexer_spec.rb +2 -2
  54. data/spec/api/query/advanced_manipulation_examples.rb +3 -3
  55. data/spec/api/query/connectives_examples.rb +26 -14
  56. data/spec/api/query/dsl_spec.rb +17 -9
  57. data/spec/api/query/dynamic_fields_examples.rb +18 -18
  58. data/spec/api/query/faceting_examples.rb +62 -62
  59. data/spec/api/query/fulltext_examples.rb +63 -58
  60. data/spec/api/query/function_spec.rb +26 -26
  61. data/spec/api/query/geo_examples.rb +6 -6
  62. data/spec/api/query/group_spec.rb +6 -6
  63. data/spec/api/query/highlighting_examples.rb +26 -26
  64. data/spec/api/query/join_spec.rb +2 -2
  65. data/spec/api/query/more_like_this_spec.rb +29 -29
  66. data/spec/api/query/ordering_pagination_examples.rb +25 -25
  67. data/spec/api/query/scope_examples.rb +39 -39
  68. data/spec/api/query/spatial_examples.rb +3 -3
  69. data/spec/api/query/spellcheck_examples.rb +3 -3
  70. data/spec/api/query/standard_spec.rb +1 -1
  71. data/spec/api/query/stats_examples.rb +8 -8
  72. data/spec/api/query/text_field_scoping_examples.rb +5 -5
  73. data/spec/api/query/types_spec.rb +4 -4
  74. data/spec/api/search/cursor_paginated_collection_spec.rb +12 -12
  75. data/spec/api/search/dynamic_fields_spec.rb +4 -4
  76. data/spec/api/search/faceting_spec.rb +55 -52
  77. data/spec/api/search/highlighting_spec.rb +7 -7
  78. data/spec/api/search/hits_spec.rb +43 -29
  79. data/spec/api/search/paginated_collection_spec.rb +18 -18
  80. data/spec/api/search/results_spec.rb +13 -13
  81. data/spec/api/search/search_spec.rb +3 -3
  82. data/spec/api/search/stats_spec.rb +10 -10
  83. data/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +19 -18
  84. data/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +9 -9
  85. data/spec/api/session_proxy/master_slave_session_proxy_spec.rb +10 -6
  86. data/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +10 -10
  87. data/spec/api/session_proxy/sharding_session_proxy_spec.rb +14 -13
  88. data/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +2 -2
  89. data/spec/api/session_proxy/spec_helper.rb +1 -1
  90. data/spec/api/session_proxy/thread_local_session_proxy_spec.rb +9 -5
  91. data/spec/api/session_spec.rb +42 -42
  92. data/spec/api/sunspot_spec.rb +7 -4
  93. data/spec/helpers/integration_helper.rb +1 -0
  94. data/spec/integration/atomic_updates_spec.rb +25 -11
  95. data/spec/integration/dynamic_fields_spec.rb +10 -10
  96. data/spec/integration/faceting_spec.rb +252 -39
  97. data/spec/integration/field_grouping_spec.rb +35 -16
  98. data/spec/integration/field_lists_spec.rb +57 -0
  99. data/spec/integration/geospatial_spec.rb +34 -8
  100. data/spec/integration/highlighting_spec.rb +5 -5
  101. data/spec/integration/indexing_spec.rb +5 -5
  102. data/spec/integration/join_spec.rb +45 -0
  103. data/spec/integration/keyword_search_spec.rb +47 -45
  104. data/spec/integration/local_search_spec.rb +4 -4
  105. data/spec/integration/more_like_this_spec.rb +7 -7
  106. data/spec/integration/scoped_search_spec.rb +108 -108
  107. data/spec/integration/spellcheck_spec.rb +52 -7
  108. data/spec/integration/stats_spec.rb +54 -13
  109. data/spec/integration/stored_fields_spec.rb +1 -1
  110. data/spec/integration/test_pagination.rb +4 -4
  111. data/spec/integration/unicode_spec.rb +1 -1
  112. data/spec/mocks/adapters.rb +33 -0
  113. data/spec/mocks/photo.rb +14 -4
  114. data/spec/mocks/post.rb +9 -1
  115. data/spec/spec_helper.rb +11 -10
  116. data/sunspot.gemspec +3 -1
  117. metadata +49 -6
@@ -15,7 +15,7 @@ describe "geospatial search" do
15
15
  with(:coordinates_new).in_radius(32, -68, 1)
16
16
  }.results
17
17
 
18
- results.should include(@post)
18
+ expect(results).to include(@post)
19
19
  end
20
20
 
21
21
  it "filters out posts not in the radius" do
@@ -23,18 +23,44 @@ describe "geospatial search" do
23
23
  with(:coordinates_new).in_radius(33, -68, 1)
24
24
  }.results
25
25
 
26
- results.should_not include(@post)
26
+ expect(results).not_to include(@post)
27
27
  end
28
28
 
29
- it "allows conjunction queries" do
29
+ it "filters out posts in the radius" do
30
+ results = Sunspot.search(Post) {
31
+ without(:coordinates_new).in_radius(32, -68, 1)
32
+ }.results
33
+
34
+ expect(results).not_to include(@post)
35
+ end
36
+
37
+ it "allows conjunction queries with radius" do
38
+ post = Post.new(:title => "Howdy",
39
+ :coordinates => Sunspot::Util::Coordinates.new(35, -68))
40
+
41
+ Sunspot.index!(post)
42
+
30
43
  results = Sunspot.search(Post) {
31
44
  any_of do
32
45
  with(:coordinates_new).in_radius(32, -68, 1)
33
46
  with(:coordinates_new).in_radius(35, 68, 1)
47
+ without(:coordinates_new).in_radius(35, -68, 1)
48
+ end
49
+ }.results
50
+
51
+ expect(results).to include(@post)
52
+ expect(results).not_to include(post)
53
+ end
54
+
55
+ it "allows conjunction queries with bounding box" do
56
+ results = Sunspot.search(Post) {
57
+ any_of do
58
+ with(:coordinates_new).in_bounding_box([31, -69], [33, -67])
59
+ with(:coordinates_new).in_bounding_box([35, 68], [36, 69])
34
60
  end
35
61
  }.results
36
62
 
37
- results.should include(@post)
63
+ expect(results).to include(@post)
38
64
  end
39
65
  end
40
66
 
@@ -52,7 +78,7 @@ describe "geospatial search" do
52
78
  with(:coordinates_new).in_bounding_box [31, -69], [33, -67]
53
79
  }.results
54
80
 
55
- results.should include(@post)
81
+ expect(results).to include(@post)
56
82
  end
57
83
 
58
84
  it "filters out posts not in the bounding box" do
@@ -60,7 +86,7 @@ describe "geospatial search" do
60
86
  with(:coordinates_new).in_bounding_box [20, -70], [21, -69]
61
87
  }.results
62
88
 
63
- results.should_not include(@post)
89
+ expect(results).not_to include(@post)
64
90
  end
65
91
  end
66
92
 
@@ -82,7 +108,7 @@ describe "geospatial search" do
82
108
  order_by_geodist(:coordinates_new, 32, -68)
83
109
  }.results
84
110
 
85
- results.should == @posts.reverse
111
+ expect(results).to eq(@posts.reverse)
86
112
  end
87
113
 
88
114
  it "orders posts by distance descending" do
@@ -90,7 +116,7 @@ describe "geospatial search" do
90
116
  order_by_geodist(:coordinates_new, 32, -68, :desc)
91
117
  }.results
92
118
 
93
- results.should == @posts
119
+ expect(results).to eq(@posts)
94
120
  end
95
121
  end
96
122
  end
@@ -11,16 +11,16 @@ describe 'keyword highlighting' do
11
11
  end
12
12
 
13
13
  it 'should include highlights in the results' do
14
- @search_result.hits.first.highlights.length.should == 1
14
+ expect(@search_result.hits.first.highlights.length).to eq(1)
15
15
  end
16
16
 
17
17
  it 'should return formatted highlight fragments' do
18
- @search_result.hits.first.highlights(:body).first.format.should == 'And the <em>fox</em> laughed'
18
+ expect(@search_result.hits.first.highlights(:body).first.format).to eq('And the <em>fox</em> laughed')
19
19
  end
20
20
 
21
21
  it 'should be empty for non-keyword searches' do
22
22
  search_result = Sunspot.search(Post){ with :blog_id, 1 }
23
- search_result.hits.first.highlights.should be_empty
23
+ expect(search_result.hits.first.highlights).to be_empty
24
24
  end
25
25
 
26
26
  it "should process multiple keyword request on different fields with highlights correctly" do
@@ -35,8 +35,8 @@ describe 'keyword highlighting' do
35
35
  end
36
36
  end
37
37
  end.to_not raise_error
38
- search_results.results.length.should eq(1)
39
- search_results.results.first.should eq(@posts.last)
38
+ expect(search_results.results.length).to eq(1)
39
+ expect(search_results.results.first).to eq(@posts.last)
40
40
  # this one might be a Solr bug, therefore not related to Sunspot itself
41
41
  # search_results.hits.first.highlights.should_not be_empty
42
42
  end
@@ -2,23 +2,23 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe 'indexing' do
4
4
  it 'should index non-multivalued field with newlines' do
5
- lambda do
5
+ expect do
6
6
  Sunspot.index!(Post.new(:title => "A\nTitle"))
7
- end.should_not raise_error
7
+ end.not_to raise_error
8
8
  end
9
9
 
10
10
  it 'should correctly remove by model instance' do
11
11
  post = Post.new(:title => 'test post')
12
12
  Sunspot.index!(post)
13
13
  Sunspot.remove!(post)
14
- Sunspot.search(Post) { with(:title, 'test post') }.results.should be_empty
14
+ expect(Sunspot.search(Post) { with(:title, 'test post') }.results).to be_empty
15
15
  end
16
16
 
17
17
  it 'should correctly delete by ID' do
18
18
  post = Post.new(:title => 'test post')
19
19
  Sunspot.index!(post)
20
20
  Sunspot.remove_by_id!(Post, post.id)
21
- Sunspot.search(Post) { with(:title, 'test post') }.results.should be_empty
21
+ expect(Sunspot.search(Post) { with(:title, 'test post') }.results).to be_empty
22
22
  end
23
23
 
24
24
  it 'removes documents by query' do
@@ -29,7 +29,7 @@ describe 'indexing' do
29
29
  Sunspot.remove!(Post) do
30
30
  with(:title, 'birds')
31
31
  end
32
- Sunspot.search(Post).should have(1).results
32
+ expect(Sunspot.search(Post).results.size).to eq(1)
33
33
  end
34
34
 
35
35
 
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+
3
+ describe "searching by joined fields" do
4
+ before :each do
5
+ Sunspot.remove_all!
6
+
7
+ @container1 = PhotoContainer.new(:id => 1)
8
+ @container2 = PhotoContainer.new(:id => 2).tap { |c| allow(c).to receive(:id).and_return(2) }
9
+ @container3 = PhotoContainer.new(:id => 3).tap { |c| allow(c).to receive(:id).and_return(3) }
10
+
11
+ @picture = Picture.new(:photo_container_id => @container1.id, :description => "one")
12
+ @photo1 = Photo.new(:photo_container_id => @container1.id, :description => "two")
13
+ @photo2 = Photo.new(:photo_container_id => @container2.id, :description => "three")
14
+
15
+ Sunspot.index!(@container1, @container2, @photo1, @photo2, @picture)
16
+ end
17
+
18
+ it "matches by joined fields" do
19
+ {
20
+ "one" => [],
21
+ "two" => [@container1],
22
+ "three" => [@container2]
23
+ }.each do |key, res|
24
+ results = Sunspot.search(PhotoContainer) {
25
+ fulltext(key, :fields => [:photo_description])
26
+ }.results
27
+
28
+ expect(results).to eq res
29
+ end
30
+ end
31
+
32
+ it "doesn't match by joined fields with the same name from other collections" do
33
+ {
34
+ "one" => [@container1],
35
+ "two" => [],
36
+ "three" => []
37
+ }.each do |key, res|
38
+ results = Sunspot.search(PhotoContainer) {
39
+ fulltext(key, :fields => [:picture_description])
40
+ }.results
41
+
42
+ expect(results).to eq res
43
+ end
44
+ end
45
+ end
@@ -19,8 +19,8 @@ describe 'keyword search' do
19
19
  context 'edismax' do
20
20
  it 'matches with wildcards' do
21
21
  results = Sunspot.search(Post) { keywords '*oas*' }.results
22
- [0,2].each { |i| results.should include(@posts[i])}
23
- [1].each { |i| results.should_not include(@posts[i])}
22
+ [0,2].each { |i| expect(results).to include(@posts[i])}
23
+ [1].each { |i| expect(results).not_to include(@posts[i])}
24
24
  end
25
25
 
26
26
  it 'matches multiple keywords on different fields with wildcards using subqueries' do
@@ -28,52 +28,52 @@ describe 'keyword search' do
28
28
  keywords 'insuffic*',:fields=>[:title]
29
29
  keywords 'win*',:fields=>[:body]
30
30
  end.results
31
- [0].each {|i| results.should include(@posts[i])}
32
- [1,2].each {|i| results.should_not include(@posts[i])}
31
+ [0].each {|i| expect(results).to include(@posts[i])}
32
+ [1,2].each {|i| expect(results).not_to include(@posts[i])}
33
33
  end
34
34
 
35
35
  it 'matches with proximity' do
36
36
  results = Sunspot.search(Post) { keywords '"wind buffer"~4' }.results
37
- [0,1].each {|i| results.should_not include(@posts[i])}
38
- [2].each {|i| results.should include(@posts[i])}
37
+ [0,1].each {|i| expect(results).not_to include(@posts[i])}
38
+ [2].each {|i| expect(results).to include(@posts[i])}
39
39
  end
40
40
 
41
41
  it 'does not match if not within proximity' do
42
42
  results = Sunspot.search(Post) { keywords '"wind buffer"~1' }.results
43
- results.should == []
43
+ expect(results).to eq([])
44
44
  end
45
45
  end
46
46
 
47
47
  it 'matches a single keyword out of a single field' do
48
48
  results = Sunspot.search(Post) { keywords 'toast' }.results
49
- [0, 2].each { |i| results.should include(@posts[i]) }
50
- [1].each { |i| results.should_not include(@posts[i]) }
49
+ [0, 2].each { |i| expect(results).to include(@posts[i]) }
50
+ [1].each { |i| expect(results).not_to include(@posts[i]) }
51
51
  end
52
52
 
53
53
  it 'matches multiple words out of a single field' do
54
54
  results = Sunspot.search(Post) { keywords 'elects toast' }.results
55
- results.should == [@posts[0]]
55
+ expect(results).to eq([@posts[0]])
56
56
  end
57
57
 
58
58
  it 'matches multiple words in multiple fields' do
59
59
  results = Sunspot.search(Post) { keywords 'toast wind' }.results
60
- [0, 2].each { |i| results.should include(@posts[i]) }
61
- [1].each { |i| results.should_not include(@posts[i]) }
60
+ [0, 2].each { |i| expect(results).to include(@posts[i]) }
61
+ [1].each { |i| expect(results).not_to include(@posts[i]) }
62
62
  end
63
63
 
64
64
  it 'matches multiple types' do
65
65
  results = Sunspot.search(Post, Namespaced::Comment) do
66
66
  keywords 'toast'
67
67
  end.results
68
- [@posts[0], @posts[2], @comment].each { |obj| results.should include(obj) }
69
- results.should_not include(@posts[1])
68
+ [@posts[0], @posts[2], @comment].each { |obj| expect(results).to include(obj) }
69
+ expect(results).not_to include(@posts[1])
70
70
  end
71
71
 
72
72
  it 'matches keywords from only the fields specified' do
73
73
  results = Sunspot.search(Post) do
74
74
  keywords 'moron', :fields => [:title]
75
75
  end.results
76
- results.should == [@posts[1]]
76
+ expect(results).to eq([@posts[1]])
77
77
  end
78
78
 
79
79
  it 'matches multiple keywords on different fields using subqueries' do
@@ -81,13 +81,13 @@ describe 'keyword search' do
81
81
  keywords 'moron', :fields => [:title]
82
82
  keywords 'wind', :fields => [:body]
83
83
  end
84
- search.results.should == []
84
+ expect(search.results).to eq([])
85
85
 
86
86
  search = Sunspot.search(Post) do
87
87
  keywords 'moron', :fields => [:title]
88
88
  keywords 'buffer', :fields => [:body]
89
89
  end
90
- search.results.should == [@posts[1]]
90
+ expect(search.results).to eq([@posts[1]])
91
91
  end
92
92
 
93
93
  it 'matches multiple keywords with escaped characters' do
@@ -95,7 +95,7 @@ describe 'keyword search' do
95
95
  keywords 'spirit', :fields => [:title]
96
96
  keywords 'host\'s', :fields => [:body]
97
97
  end
98
- search.results.should == [@posts[2]]
98
+ expect(search.results).to eq([@posts[2]])
99
99
  end
100
100
 
101
101
  it 'matches multiple keywords with phrase-based search' do
@@ -104,7 +104,7 @@ describe 'keyword search' do
104
104
  keywords '"interpret the buffer"', :fields => [:body]
105
105
  keywords '"does the"', :fields => [:body]
106
106
  end
107
- search.results.should == [@posts[2]]
107
+ expect(search.results).to eq([@posts[2]])
108
108
  end
109
109
 
110
110
  it 'matches multiple keywords different options' do
@@ -112,7 +112,7 @@ describe 'keyword search' do
112
112
  keywords 'insufficient nonexistent', :fields => [:title], :minimum_match => 1
113
113
  keywords 'wind does', :fields => [:body], :minimum_match => 2
114
114
  end
115
- search.results.should == [@posts[0]]
115
+ expect(search.results).to eq([@posts[0]])
116
116
  end
117
117
  end
118
118
 
@@ -125,9 +125,10 @@ describe 'keyword search' do
125
125
 
126
126
  it 'should assign a higher score to the result matching the higher-boosted field' do
127
127
  search = Sunspot.search(Post) { keywords 'rhinoceros' }
128
- search.hits.map { |hit| hit.primary_key }.should ==
128
+ expect(search.hits.map { |hit| hit.primary_key }).to eq(
129
129
  @posts.map { |post| post.id.to_s }
130
- search.hits.first.score.should > search.hits.last.score
130
+ )
131
+ expect(search.hits.first.score).to be > search.hits.last.score
131
132
  end
132
133
  end
133
134
 
@@ -142,9 +143,10 @@ describe 'keyword search' do
142
143
 
143
144
  it 'should assign a higher score to the higher-boosted document' do
144
145
  search = Sunspot.search(Post) { keywords 'test' }
145
- search.hits.map { |hit| hit.primary_key }.should ==
146
+ expect(search.hits.map { |hit| hit.primary_key }).to eq(
146
147
  @posts.map { |post| post.id.to_s }
147
- search.hits.first.score.should > search.hits.last.score
148
+ )
149
+ expect(search.hits.first.score).to be > search.hits.last.score
148
150
  end
149
151
  end
150
152
 
@@ -164,8 +166,8 @@ describe 'keyword search' do
164
166
  phrase_fields :body => 2.0
165
167
  end
166
168
  end.hits
167
- hits.first.instance.should == @comments.first
168
- hits.first.score.should > hits.last.score
169
+ expect(hits.first.instance).to eq(@comments.first)
170
+ expect(hits.first.score).to be > hits.last.score
169
171
  end
170
172
 
171
173
  it 'assigns a higher score to documents in which the search terms appear in a boosted field' do
@@ -174,8 +176,8 @@ describe 'keyword search' do
174
176
  fields :body => 2.0, :author_name => 0.75
175
177
  end
176
178
  end.hits
177
- hits.first.instance.should == @comments.first
178
- hits.first.score.should > hits.last.score
179
+ expect(hits.first.instance).to eq(@comments.first)
180
+ expect(hits.first.score).to be > hits.last.score
179
181
  end
180
182
 
181
183
  it 'assigns a higher score to documents in which the search terms appear in a higher boosted phrase field' do
@@ -184,8 +186,8 @@ describe 'keyword search' do
184
186
  phrase_fields :body => 2.0, :author_name => 0.75
185
187
  end
186
188
  end.hits
187
- hits.first.instance.should == @comments.first
188
- hits.first.score.should > hits.last.score
189
+ expect(hits.first.instance).to eq(@comments.first)
190
+ expect(hits.first.score).to be > hits.last.score
189
191
  end
190
192
  end
191
193
 
@@ -210,8 +212,8 @@ describe 'keyword search' do
210
212
  end
211
213
  query.without(@posts[1])
212
214
  end
213
- search.results.should == [@posts[0], @posts[2]]
214
- search.hits[0].score.should > search.hits[1].score
215
+ expect(search.results).to eq([@posts[0], @posts[2]])
216
+ expect(search.hits[0].score).to be > search.hits[1].score
215
217
  end
216
218
 
217
219
  it 'should assign scores in order of multiple boost query match' do
@@ -221,9 +223,9 @@ describe 'keyword search' do
221
223
  boost(1.5) { with(:average_rating).greater_than(3.0) }
222
224
  end
223
225
  end
224
- search.results.should == @posts
225
- search.hits[0].score.should > search.hits[1].score
226
- search.hits[1].score.should > search.hits[2].score
226
+ expect(search.results).to eq(@posts)
227
+ expect(search.hits[0].score).to be > search.hits[1].score
228
+ expect(search.hits[1].score).to be > search.hits[2].score
227
229
  end
228
230
  end
229
231
 
@@ -241,11 +243,11 @@ describe 'keyword search' do
241
243
  end
242
244
 
243
245
  it 'should match documents that contain the minimum_match number of search terms' do
244
- @search.results.should include(@posts[0])
246
+ expect(@search.results).to include(@posts[0])
245
247
  end
246
248
 
247
249
  it 'should not match documents that do not contain the minimum_match number of search terms' do
248
- @search.results.should_not include(@posts[1])
250
+ expect(@search.results).not_to include(@posts[1])
249
251
  end
250
252
  end
251
253
 
@@ -264,15 +266,15 @@ describe 'keyword search' do
264
266
  end
265
267
 
266
268
  it 'should match exact phrase' do
267
- @search.results.should include(@posts[0])
269
+ expect(@search.results).to include(@posts[0])
268
270
  end
269
271
 
270
272
  it 'should match phrase divided by query phrase slop terms' do
271
- @search.results.should include(@posts[1])
273
+ expect(@search.results).to include(@posts[1])
272
274
  end
273
275
 
274
276
  it 'should not match phrase divided by more than query phrase slop terms' do
275
- @search.results.should_not include(@posts[2])
277
+ expect(@search.results).not_to include(@posts[2])
276
278
  end
277
279
  end
278
280
 
@@ -298,15 +300,15 @@ describe 'keyword search' do
298
300
  end
299
301
 
300
302
  it 'should give phrase field boost to exact match' do
301
- @sorted_hits[0].score.should > @sorted_hits[1].score
303
+ expect(@sorted_hits[0].score).to be > @sorted_hits[1].score
302
304
  end
303
305
 
304
306
  it 'should give phrase field boost to match within slop' do
305
- @sorted_hits[2].score.should > @sorted_hits[3].score
307
+ expect(@sorted_hits[2].score).to be > @sorted_hits[3].score
306
308
  end
307
309
 
308
310
  it 'should not give phrase field boost to match beyond slop' do
309
- @sorted_hits[4].score.should == @sorted_hits[5].score
311
+ expect(@sorted_hits[4].score).to eq(@sorted_hits[5].score)
310
312
  end
311
313
  end
312
314
 
@@ -316,8 +318,8 @@ describe 'keyword search' do
316
318
  end
317
319
 
318
320
  after :each do
319
- @search.results.should == @posts
320
- @search.hits.first.score.should > @search.hits.last.score
321
+ expect(@search.results).to eq(@posts)
322
+ expect(@search.hits.first.score).to be > @search.hits.last.score
321
323
  end
322
324
 
323
325
  it 'boosts via function query with float' do
@@ -25,13 +25,13 @@ describe 'local search' do
25
25
  end
26
26
 
27
27
  it 'should return results in geo order' do
28
- @search.results.should == @posts
28
+ expect(@search.results).to eq(@posts)
29
29
  end
30
30
 
31
31
  it 'should asssign higher score to closer locations' do
32
32
  hits = @search.hits
33
33
  hits[1..-1].each_with_index do |hit, i|
34
- hit.score.should < hits[i].score
34
+ expect(hit.score).to be < hits[i].score
35
35
  end
36
36
  end
37
37
  end
@@ -51,13 +51,13 @@ describe 'local search' do
51
51
  end
52
52
 
53
53
  it 'should take both fulltext and distance into account in ordering' do
54
- @search.results.should == @posts
54
+ expect(@search.results).to eq(@posts)
55
55
  end
56
56
 
57
57
  it 'should take both fulltext and distance into account in scoring' do
58
58
  hits = @search.hits
59
59
  hits[1..-1].each_with_index do |hit, i|
60
- hit.score.should < hits[i].score
60
+ expect(hit.score).to be < hits[i].score
61
61
  end
62
62
  end
63
63
  end
@@ -14,30 +14,30 @@ describe 'more_like_this' do
14
14
  end
15
15
 
16
16
  it 'should return results for all MLT fields' do
17
- Sunspot.more_like_this(@posts.first).results.to_set.should == @posts[1..3].to_set
17
+ expect(Sunspot.more_like_this(@posts.first).results.to_set).to eq(@posts[1..3].to_set)
18
18
  end
19
19
 
20
20
  it 'should return results for specified text field' do
21
- Sunspot.more_like_this(@posts.first) do
21
+ expect(Sunspot.more_like_this(@posts.first) do
22
22
  fields :body
23
- end.results.to_set.should == @posts[2..3].to_set
23
+ end.results.to_set).to eq(@posts[2..3].to_set)
24
24
  end
25
25
 
26
26
  it 'should return empty result set if no results' do
27
- Sunspot.more_like_this(@posts.last) do
27
+ expect(Sunspot.more_like_this(@posts.last) do
28
28
  with(:title, 'bogus')
29
- end.results.should == []
29
+ end.results).to eq([])
30
30
  end
31
31
 
32
32
  describe 'when non-indexed object searched' do
33
33
  before(:each) { @mlt = Sunspot.more_like_this(Post.new) }
34
34
 
35
35
  it 'should return empty result set' do
36
- @mlt.results.should == []
36
+ expect(@mlt.results).to eq([])
37
37
  end
38
38
 
39
39
  it 'shoult return a total of 0' do
40
- @mlt.total.should == 0
40
+ expect(@mlt.total).to eq(0)
41
41
  end
42
42
  end
43
43
  end