sunspot 2.2.7 → 2.5.0

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.
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
@@ -3,28 +3,28 @@ shared_examples_for 'fulltext query' do
3
3
  search do
4
4
  keywords 'keyword search'
5
5
  end
6
- connection.should have_last_search_with(:q => 'keyword search')
6
+ expect(connection).to have_last_search_with(:q => 'keyword search')
7
7
  end
8
8
 
9
9
  it 'ignores keywords if empty' do
10
10
  search do
11
11
  keywords ''
12
12
  end
13
- connection.should_not have_last_search_with(:defType => 'edismax')
13
+ expect(connection).not_to have_last_search_with(:defType => 'edismax')
14
14
  end
15
15
 
16
16
  it 'ignores keywords if nil' do
17
17
  search do
18
18
  keywords nil
19
19
  end
20
- connection.should_not have_last_search_with(:defType => 'edismax')
20
+ expect(connection).not_to have_last_search_with(:defType => 'edismax')
21
21
  end
22
22
 
23
23
  it 'ignores keywords with only whitespace' do
24
24
  search do
25
25
  keywords " \t"
26
26
  end
27
- connection.should_not have_last_search_with(:defType => 'edismax')
27
+ expect(connection).not_to have_last_search_with(:defType => 'edismax')
28
28
  end
29
29
 
30
30
  it 'gracefully ignores keywords block if keywords ignored' do
@@ -37,14 +37,14 @@ shared_examples_for 'fulltext query' do
37
37
  search do
38
38
  keywords 'keyword search'
39
39
  end
40
- connection.should have_last_search_with(:defType => 'edismax')
40
+ expect(connection).to have_last_search_with(:defType => 'edismax')
41
41
  end
42
42
 
43
43
  it 'searches types in filter query if keywords used' do
44
44
  search do
45
45
  keywords 'keyword search'
46
46
  end
47
- connection.should have_last_search_with(:fq => ['type:Post'])
47
+ expect(connection).to have_last_search_with(:fq => ['type:Post'])
48
48
  end
49
49
 
50
50
  describe 'with multiple keyword components' do
@@ -56,20 +56,23 @@ shared_examples_for 'fulltext query' do
56
56
  end
57
57
 
58
58
  it 'puts specified keywords in subquery' do
59
- subqueries(:q).map { |subquery| subquery[:v] }.should ==
59
+ expect(subqueries(:q).map { |subquery| subquery[:v] }).to eq(
60
60
  ['first search', 'second search']
61
+ )
61
62
  end
62
63
 
63
64
  it 'puts specified dismax parameters in subquery' do
64
- subqueries(:q).first[:qf].should == 'title_text'
65
+ expect(subqueries(:q).first[:qf]).to eq('title_text')
65
66
  end
66
67
 
67
68
  it 'puts default dismax parameters in subquery' do
68
- subqueries(:q).last[:qf].split(' ').sort.should == %w(backwards_title_text body_textsv tags_textv title_text)
69
+ expect(subqueries(:q).last[:qf].split(' ').sort).to(
70
+ eq(%w(backwards_title_text body_textsv tags_textv text_array_text title_text))
71
+ )
69
72
  end
70
73
 
71
74
  it 'puts field list in main query' do
72
- connection.should have_last_search_with(:fl => '* score')
75
+ expect(connection).to have_last_search_with(:fl => '* score')
73
76
  end
74
77
  end
75
78
 
@@ -77,21 +80,25 @@ shared_examples_for 'fulltext query' do
77
80
  search = search do
78
81
  keywords 'keyword search'
79
82
  end
80
- connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_textsv tags_textv title_text)
83
+ expect(connection.searches.last[:qf].split(' ').sort).to(
84
+ eq(%w(backwards_title_text body_textsv tags_textv text_array_text title_text))
85
+ )
81
86
  end
82
87
 
83
88
  it 'searches both stored and unstored text fields' do
84
89
  search Post, Namespaced::Comment do
85
90
  keywords 'keyword search'
86
91
  end
87
- connection.searches.last[:qf].split(' ').sort.should == %w(author_name_text backwards_title_text body_text body_textsv tags_textv title_text)
92
+ expect(connection.searches.last[:qf].split(' ').sort).to(
93
+ eq(%w(author_name_text backwards_title_text body_text body_textsv tags_textv text_array_text title_text))
94
+ )
88
95
  end
89
96
 
90
97
  it 'searches only specified text fields when specified' do
91
98
  search do
92
99
  keywords 'keyword search', :fields => [:title, :body]
93
100
  end
94
- connection.searches.last[:qf].split(' ').sort.should == %w(body_textsv title_text)
101
+ expect(connection.searches.last[:qf].split(' ').sort).to eq(%w(body_textsv title_text))
95
102
  end
96
103
 
97
104
  it 'excludes text fields when instructed' do
@@ -100,7 +107,7 @@ shared_examples_for 'fulltext query' do
100
107
  exclude_fields :backwards_title, :body_mlt
101
108
  end
102
109
  end
103
- connection.searches.last[:qf].split(' ').sort.should == %w(body_textsv tags_textv title_text)
110
+ expect(connection.searches.last[:qf].split(' ').sort).to eq(%w(body_textsv tags_textv text_array_text title_text))
104
111
  end
105
112
 
106
113
  it 'assigns boost to fields when specified' do
@@ -109,7 +116,7 @@ shared_examples_for 'fulltext query' do
109
116
  fields :title => 2.0, :body => 0.75
110
117
  end
111
118
  end
112
- connection.searches.last[:qf].split(' ').sort.should == %w(body_textsv^0.75 title_text^2.0)
119
+ expect(connection.searches.last[:qf].split(' ').sort).to eq(%w(body_textsv^0.75 title_text^2.0))
113
120
  end
114
121
 
115
122
  it 'allows assignment of boosted and unboosted fields' do
@@ -124,19 +131,19 @@ shared_examples_for 'fulltext query' do
124
131
  search Post, Namespaced::Comment do
125
132
  keywords 'keyword search', :fields => [:body]
126
133
  end
127
- connection.searches.last[:qf].split(' ').sort.should == %w(body_text body_textsv)
134
+ expect(connection.searches.last[:qf].split(' ').sort).to eq(%w(body_text body_textsv))
128
135
  end
129
136
 
130
137
  it 'requests score when keywords used' do
131
138
  search do
132
139
  keywords 'keyword search'
133
140
  end
134
- connection.should have_last_search_with(:fl => '* score')
141
+ expect(connection).to have_last_search_with(:fl => '* score')
135
142
  end
136
143
 
137
144
  it 'does not request score when keywords not used' do
138
145
  search Post
139
- connection.should_not have_last_search_with(:fl)
146
+ expect(connection).not_to have_last_search_with(:fl)
140
147
  end
141
148
 
142
149
  it 'sets phrase fields' do
@@ -145,7 +152,7 @@ shared_examples_for 'fulltext query' do
145
152
  phrase_fields :title => 2.0
146
153
  end
147
154
  end
148
- connection.should have_last_search_with(:pf => 'title_text^2.0')
155
+ expect(connection).to have_last_search_with(:pf => 'title_text^2.0')
149
156
  end
150
157
 
151
158
  it 'sets phrase fields with boost' do
@@ -154,7 +161,7 @@ shared_examples_for 'fulltext query' do
154
161
  phrase_fields :title => 1.5
155
162
  end
156
163
  end
157
- connection.should have_last_search_with(:pf => 'title_text^1.5')
164
+ expect(connection).to have_last_search_with(:pf => 'title_text^1.5')
158
165
  end
159
166
 
160
167
  it 'sets phrase slop from DSL' do
@@ -163,7 +170,7 @@ shared_examples_for 'fulltext query' do
163
170
  phrase_slop 2
164
171
  end
165
172
  end
166
- connection.should have_last_search_with(:ps => 2)
173
+ expect(connection).to have_last_search_with(:ps => 2)
167
174
  end
168
175
 
169
176
  it 'sets boost for certain fields without restricting fields' do
@@ -172,7 +179,9 @@ shared_examples_for 'fulltext query' do
172
179
  boost_fields :title => 1.5
173
180
  end
174
181
  end
175
- connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_textsv tags_textv title_text^1.5)
182
+ expect(connection.searches.last[:qf].split(' ').sort).to(
183
+ eq(%w(backwards_title_text body_textsv tags_textv text_array_text title_text^1.5))
184
+ )
176
185
  end
177
186
 
178
187
  it 'ignores boost fields that do not apply' do
@@ -181,7 +190,9 @@ shared_examples_for 'fulltext query' do
181
190
  boost_fields :bogus => 1.2, :title => 1.5
182
191
  end
183
192
  end
184
- connection.searches.last[:qf].split(' ').sort.should == %w(backwards_title_text body_textsv tags_textv title_text^1.5)
193
+ expect(connection.searches.last[:qf].split(' ').sort).to(
194
+ eq(%w(backwards_title_text body_textsv tags_textv text_array_text title_text^1.5))
195
+ )
185
196
  end
186
197
 
187
198
  it 'sets default boost with default fields' do
@@ -189,14 +200,14 @@ shared_examples_for 'fulltext query' do
189
200
  keywords 'great pizza'
190
201
  end
191
202
  # Hashes in 1.8 aren't ordered
192
- connection.searches.last[:qf].split(" ").sort.join(" ").should eq 'caption_text^1.5 description_text'
203
+ expect(connection.searches.last[:qf].split(" ").sort.join(" ")).to eq 'caption_text^1.5 description_text'
193
204
  end
194
205
 
195
206
  it 'sets default boost with fields specified in options' do
196
207
  search Photo do
197
208
  keywords 'great pizza', :fields => [:caption]
198
209
  end
199
- connection.should have_last_search_with(:qf => 'caption_text^1.5')
210
+ expect(connection).to have_last_search_with(:qf => 'caption_text^1.5')
200
211
  end
201
212
 
202
213
  it 'sets default boost with fields specified in DSL' do
@@ -205,7 +216,7 @@ shared_examples_for 'fulltext query' do
205
216
  fields :caption
206
217
  end
207
218
  end
208
- connection.should have_last_search_with(:qf => 'caption_text^1.5')
219
+ expect(connection).to have_last_search_with(:qf => 'caption_text^1.5')
209
220
  end
210
221
 
211
222
  it 'overrides default boost when specified in DSL' do
@@ -214,7 +225,7 @@ shared_examples_for 'fulltext query' do
214
225
  fields :caption => 2.0
215
226
  end
216
227
  end
217
- connection.should have_last_search_with(:qf => 'caption_text^2.0')
228
+ expect(connection).to have_last_search_with(:qf => 'caption_text^2.0')
218
229
  end
219
230
 
220
231
  it 'creates boost query' do
@@ -225,7 +236,7 @@ shared_examples_for 'fulltext query' do
225
236
  end
226
237
  end
227
238
  end
228
- connection.should have_last_search_with(:bq => ['average_rating_ft:{2\.0 TO *}^2.0'])
239
+ expect(connection).to have_last_search_with(:bq => ['average_rating_ft:{2\.0 TO *}^2.0'])
229
240
  end
230
241
 
231
242
  it 'creates multiple boost queries' do
@@ -239,7 +250,7 @@ shared_examples_for 'fulltext query' do
239
250
  end
240
251
  end
241
252
  end
242
- connection.should have_last_search_with(
253
+ expect(connection).to have_last_search_with(
243
254
  :bq => [
244
255
  'average_rating_ft:{2\.0 TO *}^2.0',
245
256
  'featured_bs:true^1.5'
@@ -251,65 +262,65 @@ shared_examples_for 'fulltext query' do
251
262
  search do
252
263
  keywords 'great pizza', :minimum_match => 2
253
264
  end
254
- connection.should have_last_search_with(:mm => 2)
265
+ expect(connection).to have_last_search_with(:mm => 2)
255
266
  end
256
267
 
257
268
  it 'sends minimum match parameter from DSL' do
258
269
  search do
259
270
  keywords('great pizza') { minimum_match(2) }
260
271
  end
261
- connection.should have_last_search_with(:mm => 2)
272
+ expect(connection).to have_last_search_with(:mm => 2)
262
273
  end
263
274
 
264
275
  it 'sends tiebreaker parameter from options' do
265
276
  search do
266
277
  keywords 'great pizza', :tie => 0.1
267
278
  end
268
- connection.should have_last_search_with(:tie => 0.1)
279
+ expect(connection).to have_last_search_with(:tie => 0.1)
269
280
  end
270
281
 
271
282
  it 'sends tiebreaker parameter from DSL' do
272
283
  search do
273
284
  keywords('great pizza') { tie(0.1) }
274
285
  end
275
- connection.should have_last_search_with(:tie => 0.1)
286
+ expect(connection).to have_last_search_with(:tie => 0.1)
276
287
  end
277
288
 
278
289
  it 'sends query phrase slop from options' do
279
290
  search do
280
291
  keywords 'great pizza', :query_phrase_slop => 2
281
292
  end
282
- connection.should have_last_search_with(:qs => 2)
293
+ expect(connection).to have_last_search_with(:qs => 2)
283
294
  end
284
295
 
285
296
  it 'sends query phrase slop from DSL' do
286
297
  search do
287
298
  keywords('great pizza') { query_phrase_slop(2) }
288
299
  end
289
- connection.should have_last_search_with(:qs => 2)
300
+ expect(connection).to have_last_search_with(:qs => 2)
290
301
  end
291
302
 
292
303
  it 'allows specification of a text field that only exists in one type' do
293
304
  search Post, Namespaced::Comment do
294
305
  keywords 'keywords', :fields => :author_name
295
306
  end
296
- connection.searches.last[:qf].should == 'author_name_text'
307
+ expect(connection.searches.last[:qf]).to eq('author_name_text')
297
308
  end
298
309
 
299
310
  it 'raises Sunspot::UnrecognizedFieldError for nonexistant fields in keywords' do
300
- lambda do
311
+ expect do
301
312
  search do
302
313
  keywords :text, :fields => :bogus
303
314
  end
304
- end.should raise_error(Sunspot::UnrecognizedFieldError)
315
+ end.to raise_error(Sunspot::UnrecognizedFieldError)
305
316
  end
306
317
 
307
318
  it 'raises Sunspot::UnrecognizedFieldError if a text field that does not exist for any type is specified' do
308
- lambda do
319
+ expect do
309
320
  search Post, Namespaced::Comment do
310
321
  keywords 'fulltext', :fields => :bogus
311
322
  end
312
- end.should raise_error(Sunspot::UnrecognizedFieldError)
323
+ end.to raise_error(Sunspot::UnrecognizedFieldError)
313
324
  end
314
325
 
315
326
  describe 'connective examples' do
@@ -321,7 +332,7 @@ shared_examples_for 'fulltext query' do
321
332
  end
322
333
  end
323
334
 
324
- connection.searches.last[:q].should eq "(_query_:\"{!edismax qf='title_text'}keywords1\" OR _query_:\"{!edismax qf='body_textsv'}keyword2\")"
335
+ expect(connection.searches.last[:q]).to eq "(_query_:\"{!edismax qf='title_text'}keywords1\" OR _query_:\"{!edismax qf='body_textsv'}keyword2\")"
325
336
  end
326
337
 
327
338
  it 'creates a conjunction inside of a disjunction' do
@@ -336,7 +347,7 @@ shared_examples_for 'fulltext query' do
336
347
  end
337
348
  end
338
349
 
339
- connection.searches.last[:q].should eq "(_query_:\"{!edismax qf='body_textsv'}keywords1\" OR (_query_:\"{!edismax qf='body_textsv'}keyword2\" AND _query_:\"{!edismax qf='body_textsv'}keyword3\"))"
350
+ expect(connection.searches.last[:q]).to eq "(_query_:\"{!edismax qf='body_textsv'}keywords1\" OR (_query_:\"{!edismax qf='body_textsv'}keyword2\" AND _query_:\"{!edismax qf='body_textsv'}keyword3\"))"
340
351
  end
341
352
 
342
353
  it 'does nothing special if #all/#any called from the top level or called multiple times' do
@@ -347,7 +358,7 @@ shared_examples_for 'fulltext query' do
347
358
  end
348
359
  end
349
360
 
350
- connection.searches.last[:q].should eq "(_query_:\"{!edismax qf='title_text'}keywords1\" AND _query_:\"{!edismax qf='body_textsv'}keyword2\")"
361
+ expect(connection.searches.last[:q]).to eq "(_query_:\"{!edismax qf='title_text'}keywords1\" AND _query_:\"{!edismax qf='body_textsv'}keyword2\")"
351
362
  end
352
363
 
353
364
  it 'does nothing special if #all/#any are mixed and called multiple times' do
@@ -362,7 +373,7 @@ shared_examples_for 'fulltext query' do
362
373
  end
363
374
  end
364
375
 
365
- connection.searches.last[:q].should eq "(_query_:\"{!edismax qf='title_text'}keywords1\" AND _query_:\"{!edismax qf='body_textsv'}keyword2\")"
376
+ expect(connection.searches.last[:q]).to eq "(_query_:\"{!edismax qf='title_text'}keywords1\" AND _query_:\"{!edismax qf='body_textsv'}keyword2\")"
366
377
 
367
378
  search Post do
368
379
  any do
@@ -375,7 +386,7 @@ shared_examples_for 'fulltext query' do
375
386
  end
376
387
  end
377
388
 
378
- connection.searches.last[:q].should eq "(_query_:\"{!edismax qf='title_text'}keywords1\" OR _query_:\"{!edismax qf='body_textsv'}keyword2\")"
389
+ expect(connection.searches.last[:q]).to eq "(_query_:\"{!edismax qf='title_text'}keywords1\" OR _query_:\"{!edismax qf='body_textsv'}keyword2\")"
379
390
  end
380
391
 
381
392
  it "does not add empty parentheses" do
@@ -392,7 +403,7 @@ shared_examples_for 'fulltext query' do
392
403
  end
393
404
  end
394
405
 
395
- connection.searches.last[:q].should eq "_query_:\"{!edismax qf='title_text'}keywords1\""
406
+ expect(connection.searches.last[:q]).to eq "_query_:\"{!edismax qf='title_text'}keywords1\""
396
407
  end
397
408
  end
398
409
 
@@ -407,11 +418,9 @@ shared_examples_for 'fulltext query' do
407
418
 
408
419
  obj_id = find_ob_id(srch)
409
420
  q_name = "qPhoto#{obj_id}"
410
- fq_name = "f#{q_name}"
411
421
 
412
- connection.searches.last[:q].should eq "(_query_:\"{!join from=photo_container_id_i to=id_i v=$#{q_name} fq=$#{fq_name}}\" OR _query_:\"{!edismax qf='description_text^1.2'}keyword2\")"
413
- connection.searches.last[q_name].should eq "_query_:\"{!edismax qf='caption_text'}keyword1\""
414
- connection.searches.last[fq_name].should eq "type:Photo"
422
+ expect(connection.searches.last[:q]).to eq "(_query_:\"{!join from=photo_container_id_i to=id_i v=$#{q_name}}\" OR _query_:\"{!edismax qf='description_text^1.2'}keyword2\")"
423
+ expect(connection.searches.last[q_name]).to eq "_query_:\"{!field f=type}Photo\"+_query_:\"{!edismax qf='caption_text'}keyword1\""
415
424
  end
416
425
 
417
426
  it "should be able to resolve name conflicts with the :prefix option" do
@@ -424,11 +433,9 @@ shared_examples_for 'fulltext query' do
424
433
 
425
434
  obj_id = find_ob_id(srch)
426
435
  q_name = "qPhoto#{obj_id}"
427
- fq_name = "f#{q_name}"
428
436
 
429
- connection.searches.last[:q].should eq "(_query_:\"{!edismax qf='description_text^1.2'}keyword1\" OR _query_:\"{!join from=photo_container_id_i to=id_i v=$#{q_name} fq=$#{fq_name}}\")"
430
- connection.searches.last[q_name].should eq "_query_:\"{!edismax qf='description_text'}keyword2\""
431
- connection.searches.last[fq_name].should eq "type:Photo"
437
+ expect(connection.searches.last[:q]).to eq "(_query_:\"{!edismax qf='description_text^1.2'}keyword1\" OR _query_:\"{!join from=photo_container_id_i to=id_i v=$#{q_name}}\")"
438
+ expect(connection.searches.last[q_name]).to eq "_query_:\"{!field f=type}Photo\"+_query_:\"{!edismax qf='description_text'}keyword2\""
432
439
  end
433
440
 
434
441
  it "should recognize fields when adding from DSL, e.g. when calling boost_fields" do
@@ -442,11 +449,9 @@ shared_examples_for 'fulltext query' do
442
449
 
443
450
  obj_id = find_ob_id(srch)
444
451
  q_name = "qPhoto#{obj_id}"
445
- fq_name = "f#{q_name}"
446
452
 
447
- connection.searches.last[:q].should eq "(_query_:\"{!edismax qf='description_text^1.5'}keyword1\" OR _query_:\"{!join from=photo_container_id_i to=id_i v=$#{q_name} fq=$#{fq_name}}\")"
448
- connection.searches.last[q_name].should eq "_query_:\"{!edismax qf='description_text^1.3'}keyword1\""
449
- connection.searches.last[fq_name].should eq "type:Photo"
453
+ expect(connection.searches.last[:q]).to eq "(_query_:\"{!edismax qf='description_text^1.5'}keyword1\" OR _query_:\"{!join from=photo_container_id_i to=id_i v=$#{q_name}}\")"
454
+ expect(connection.searches.last[q_name]).to eq "_query_:\"{!field f=type}Photo\"+_query_:\"{!edismax qf='description_text^1.3'}keyword1\""
450
455
  end
451
456
 
452
457
  private
@@ -7,7 +7,7 @@ describe 'function query' do
7
7
  boost(function { :average_rating })
8
8
  end
9
9
  end
10
- connection.should have_last_search_including(:bf, 'average_rating_ft')
10
+ expect(connection).to have_last_search_including(:bf, 'average_rating_ft')
11
11
  end
12
12
 
13
13
  it "should send query to solr with boost function and boost amount" do
@@ -16,7 +16,7 @@ describe 'function query' do
16
16
  boost(function { :average_rating }^5)
17
17
  end
18
18
  end
19
- connection.should have_last_search_including(:bf, 'average_rating_ft^5')
19
+ expect(connection).to have_last_search_including(:bf, 'average_rating_ft^5')
20
20
  end
21
21
 
22
22
  it "should handle boost function with constant float" do
@@ -25,7 +25,7 @@ describe 'function query' do
25
25
  boost(function { 10.5 })
26
26
  end
27
27
  end
28
- connection.should have_last_search_including(:bf, '10.5')
28
+ expect(connection).to have_last_search_including(:bf, '10.5')
29
29
  end
30
30
 
31
31
  it "should handle boost function with constant float and boost amount" do
@@ -34,7 +34,7 @@ describe 'function query' do
34
34
  boost(function { 10.5 }^5)
35
35
  end
36
36
  end
37
- connection.should have_last_search_including(:bf, '10.5^5')
37
+ expect(connection).to have_last_search_including(:bf, '10.5^5')
38
38
  end
39
39
 
40
40
  it "should handle boost function with time literal" do
@@ -43,7 +43,7 @@ describe 'function query' do
43
43
  boost(function { Time.parse('2010-03-25 14:13:00 EDT') })
44
44
  end
45
45
  end
46
- connection.should have_last_search_including(:bf, '2010-03-25T18:13:00Z')
46
+ expect(connection).to have_last_search_including(:bf, '2010-03-25T18:13:00Z')
47
47
  end
48
48
 
49
49
  it "should handle arbitrary functions in a function query block" do
@@ -52,7 +52,7 @@ describe 'function query' do
52
52
  boost(function { product(:average_rating, 10) })
53
53
  end
54
54
  end
55
- connection.should have_last_search_including(:bf, 'product(average_rating_ft,10)')
55
+ expect(connection).to have_last_search_including(:bf, 'product(average_rating_ft,10)')
56
56
  end
57
57
 
58
58
  it "should handle the sub function in a function query block" do
@@ -61,7 +61,7 @@ describe 'function query' do
61
61
  boost(function { sub(:average_rating, 10) })
62
62
  end
63
63
  end
64
- connection.should have_last_search_including(:bf, 'sub(average_rating_ft,10)')
64
+ expect(connection).to have_last_search_including(:bf, 'sub(average_rating_ft,10)')
65
65
  end
66
66
 
67
67
  it "should handle boost amounts on function query block" do
@@ -70,7 +70,7 @@ describe 'function query' do
70
70
  boost(function { sub(:average_rating, 10)^5 })
71
71
  end
72
72
  end
73
- connection.should have_last_search_including(:bf, 'sub(average_rating_ft,10)^5')
73
+ expect(connection).to have_last_search_including(:bf, 'sub(average_rating_ft,10)^5')
74
74
  end
75
75
 
76
76
  it "should handle nested functions in a function query block" do
@@ -79,28 +79,28 @@ describe 'function query' do
79
79
  boost(function { product(:average_rating, sum(:average_rating, 20)) })
80
80
  end
81
81
  end
82
- connection.should have_last_search_including(:bf, 'product(average_rating_ft,sum(average_rating_ft,20))')
82
+ expect(connection).to have_last_search_including(:bf, 'product(average_rating_ft,sum(average_rating_ft,20))')
83
83
  end
84
84
 
85
85
  # TODO SOLR 1.5
86
86
  it "should raise ArgumentError if string literal passed" do
87
- lambda do
87
+ expect do
88
88
  session.search Post do
89
89
  keywords('pizza') do
90
90
  boost(function { "hello world" })
91
91
  end
92
92
  end
93
- end.should raise_error(ArgumentError)
93
+ end.to raise_error(ArgumentError)
94
94
  end
95
95
 
96
96
  it "should raise UnrecognizedFieldError if bogus field name passed" do
97
- lambda do
97
+ expect do
98
98
  session.search Post do
99
99
  keywords('pizza') do
100
100
  boost(function { :bogus })
101
101
  end
102
102
  end
103
- end.should raise_error(Sunspot::UnrecognizedFieldError)
103
+ end.to raise_error(Sunspot::UnrecognizedFieldError)
104
104
  end
105
105
 
106
106
  it "should send query to solr with multiplicative boost function" do
@@ -109,7 +109,7 @@ describe 'function query' do
109
109
  multiplicative_boost(function { :average_rating })
110
110
  end
111
111
  end
112
- connection.should have_last_search_including(:boost, 'average_rating_ft')
112
+ expect(connection).to have_last_search_including(:boost, 'average_rating_ft')
113
113
  end
114
114
 
115
115
  it "should send query to solr with multiplicative boost function and boost amount" do
@@ -118,7 +118,7 @@ describe 'function query' do
118
118
  multiplicative_boost(function { :average_rating }^5)
119
119
  end
120
120
  end
121
- connection.should have_last_search_including(:boost, 'average_rating_ft^5')
121
+ expect(connection).to have_last_search_including(:boost, 'average_rating_ft^5')
122
122
  end
123
123
 
124
124
  it "should handle multiplicative boost function with constant float" do
@@ -127,7 +127,7 @@ describe 'function query' do
127
127
  multiplicative_boost(function { 10.5 })
128
128
  end
129
129
  end
130
- connection.should have_last_search_including(:boost, '10.5')
130
+ expect(connection).to have_last_search_including(:boost, '10.5')
131
131
  end
132
132
 
133
133
  it "should handle multiplicative boost function with constant float and boost amount" do
@@ -136,7 +136,7 @@ describe 'function query' do
136
136
  multiplicative_boost(function { 10.5 }^5)
137
137
  end
138
138
  end
139
- connection.should have_last_search_including(:boost, '10.5^5')
139
+ expect(connection).to have_last_search_including(:boost, '10.5^5')
140
140
  end
141
141
 
142
142
  it "should handle multiplicative boost function with time literal" do
@@ -145,7 +145,7 @@ describe 'function query' do
145
145
  multiplicative_boost(function { Time.parse('2010-03-25 14:13:00 EDT') })
146
146
  end
147
147
  end
148
- connection.should have_last_search_including(:boost, '2010-03-25T18:13:00Z')
148
+ expect(connection).to have_last_search_including(:boost, '2010-03-25T18:13:00Z')
149
149
  end
150
150
 
151
151
  it "should handle arbitrary functions in a function query block" do
@@ -154,7 +154,7 @@ describe 'function query' do
154
154
  multiplicative_boost(function { product(:average_rating, 10) })
155
155
  end
156
156
  end
157
- connection.should have_last_search_including(:boost, 'product(average_rating_ft,10)')
157
+ expect(connection).to have_last_search_including(:boost, 'product(average_rating_ft,10)')
158
158
  end
159
159
 
160
160
  it "should handle the sub function in a multiplicative boost function query block" do
@@ -163,7 +163,7 @@ describe 'function query' do
163
163
  multiplicative_boost(function { sub(:average_rating, 10) })
164
164
  end
165
165
  end
166
- connection.should have_last_search_including(:boost, 'sub(average_rating_ft,10)')
166
+ expect(connection).to have_last_search_including(:boost, 'sub(average_rating_ft,10)')
167
167
  end
168
168
 
169
169
  it "should handle boost amounts on multiplicative boost function query block" do
@@ -172,7 +172,7 @@ describe 'function query' do
172
172
  multiplicative_boost(function { sub(:average_rating, 10)^5 })
173
173
  end
174
174
  end
175
- connection.should have_last_search_including(:boost, 'sub(average_rating_ft,10)^5')
175
+ expect(connection).to have_last_search_including(:boost, 'sub(average_rating_ft,10)^5')
176
176
  end
177
177
 
178
178
  it "should handle nested functions in a multiplicative boost function query block" do
@@ -181,28 +181,28 @@ describe 'function query' do
181
181
  multiplicative_boost(function { product(:average_rating, sum(:average_rating, 20)) })
182
182
  end
183
183
  end
184
- connection.should have_last_search_including(:boost, 'product(average_rating_ft,sum(average_rating_ft,20))')
184
+ expect(connection).to have_last_search_including(:boost, 'product(average_rating_ft,sum(average_rating_ft,20))')
185
185
  end
186
186
 
187
187
  # TODO SOLR 1.5
188
188
  it "should raise ArgumentError if string literal passed to multiplicative boost" do
189
- lambda do
189
+ expect do
190
190
  session.search Post do
191
191
  keywords('pizza') do
192
192
  multiplicative_boost(function { "hello world" })
193
193
  end
194
194
  end
195
- end.should raise_error(ArgumentError)
195
+ end.to raise_error(ArgumentError)
196
196
  end
197
197
 
198
198
  it "should raise UnrecognizedFieldError if bogus field name passed to multiplicative boost" do
199
- lambda do
199
+ expect do
200
200
  session.search Post do
201
201
  keywords('pizza') do
202
202
  multiplicative_boost(function { :bogus })
203
203
  end
204
204
  end
205
- end.should raise_error(Sunspot::UnrecognizedFieldError)
205
+ end.to raise_error(Sunspot::UnrecognizedFieldError)
206
206
  end
207
207
 
208
208
  end
@@ -5,35 +5,35 @@ shared_examples_for 'geohash query' do
5
5
  search do
6
6
  with(:coordinates).near(40.7, -73.5)
7
7
  end
8
- connection.should have_last_search_including(:q, build_geo_query)
8
+ expect(connection).to have_last_search_including(:q, build_geo_query)
9
9
  end
10
10
 
11
11
  it 'searches for nearby points with non-Float arguments' do
12
12
  search do
13
13
  with(:coordinates).near(BigDecimal.new('40.7'), BigDecimal.new('-73.5'))
14
14
  end
15
- connection.should have_last_search_including(:q, build_geo_query)
15
+ expect(connection).to have_last_search_including(:q, build_geo_query)
16
16
  end
17
17
 
18
18
  it 'searches for nearby points with given precision' do
19
19
  search do
20
20
  with(:coordinates).near(40.7, -73.5, :precision => 10)
21
21
  end
22
- connection.should have_last_search_including(:q, build_geo_query(:precision => 10))
22
+ expect(connection).to have_last_search_including(:q, build_geo_query(:precision => 10))
23
23
  end
24
24
 
25
25
  it 'searches for nearby points with given precision factor' do
26
26
  search do
27
27
  with(:coordinates).near(40.7, -73.5, :precision_factor => 1.5)
28
28
  end
29
- connection.should have_last_search_including(:q, build_geo_query(:precision_factor => 1.5))
29
+ expect(connection).to have_last_search_including(:q, build_geo_query(:precision_factor => 1.5))
30
30
  end
31
31
 
32
32
  it 'searches for nearby points with given boost' do
33
33
  search do
34
34
  with(:coordinates).near(40.7, -73.5, :boost => 2.0)
35
35
  end
36
- connection.should have_last_search_including(:q, build_geo_query(:boost => 2.0))
36
+ expect(connection).to have_last_search_including(:q, build_geo_query(:boost => 2.0))
37
37
  end
38
38
 
39
39
  it 'performs both dismax search and location search' do
@@ -42,7 +42,7 @@ shared_examples_for 'geohash query' do
42
42
  with(:coordinates).near(40.7, -73.5)
43
43
  end
44
44
  expected = %Q((_query_:"{!edismax qf='title_text'}pizza" AND (#{build_geo_query})))
45
- connection.should have_last_search_including(:q, expected)
45
+ expect(connection).to have_last_search_including(:q, expected)
46
46
  end
47
47
 
48
48
  private