thinking-sphinx 2.0.9 → 2.0.10

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.
@@ -5,95 +5,95 @@ describe ThinkingSphinx::Search do
5
5
  before :each do
6
6
  @config = ThinkingSphinx::Configuration.instance
7
7
  @client = Riddle::Client.new
8
-
8
+
9
9
  @config.stub!(:client => @client)
10
10
  @client.stub!(:query => {:matches => [], :total_found => 41, :total => 41})
11
11
  end
12
-
12
+
13
13
  it "not request results from the client if not accessing items" do
14
14
  @config.should_not_receive(:client)
15
-
15
+
16
16
  ThinkingSphinx::Search.new.class
17
17
  end
18
-
18
+
19
19
  it "should request results if access is required" do
20
20
  @config.should_receive(:client)
21
-
21
+
22
22
  ThinkingSphinx::Search.new.first
23
23
  end
24
-
24
+
25
25
  describe '#respond_to?' do
26
26
  it "should respond to Array methods" do
27
27
  ThinkingSphinx::Search.new.respond_to?(:each).should be_true
28
28
  end
29
-
29
+
30
30
  it "should respond to Search methods" do
31
31
  ThinkingSphinx::Search.new.respond_to?(:per_page).should be_true
32
32
  end
33
33
  end
34
-
34
+
35
35
  describe '#populated?' do
36
36
  before :each do
37
37
  @search = ThinkingSphinx::Search.new
38
38
  end
39
-
39
+
40
40
  it "should be false if the client request has not been made" do
41
41
  @search.populated?.should be_false
42
42
  end
43
-
43
+
44
44
  it "should be true once the client request has been made" do
45
45
  @search.first
46
46
  @search.should be_populated
47
47
  end
48
-
48
+
49
49
  it "should be populated if :populate is set to true" do
50
50
  search = ThinkingSphinx::Search.new(:populate => true)
51
51
  search.should be_populated
52
52
  end
53
53
  end
54
-
54
+
55
55
  describe '#error?' do
56
56
  before :each do
57
57
  @search = ThinkingSphinx::Search.new
58
58
  end
59
-
59
+
60
60
  it "should be false if client requests have not resulted in an error" do
61
61
  @search.should_receive(:error).and_return(nil)
62
62
  @search.error?.should_not be_true
63
63
  end
64
-
64
+
65
65
  it "should be true when client requests result in an error" do
66
66
  @search.should_receive(:error).and_return("error message")
67
67
  @search.error?.should be_true
68
68
  end
69
69
  end
70
-
70
+
71
71
  describe '#warning?' do
72
72
  before :each do
73
73
  @search = ThinkingSphinx::Search.new
74
74
  end
75
-
75
+
76
76
  it "should be false if client requests have not resulted in a warning" do
77
77
  @search.should_receive(:warning).and_return(nil)
78
78
  @search.warning?.should_not be_true
79
79
  end
80
-
80
+
81
81
  it "should be true when client requests result in an error" do
82
82
  @search.should_receive(:warning).and_return("warning message")
83
83
  @search.warning?.should be_true
84
84
  end
85
85
  end
86
-
86
+
87
87
  describe '#results' do
88
88
  it "should populate search results before returning" do
89
89
  @search = ThinkingSphinx::Search.new
90
90
  @search.populated?.should be_false
91
-
91
+
92
92
  @search.results
93
93
  @search.populated?.should be_true
94
94
  end
95
95
  end
96
-
96
+
97
97
  describe '#method_missing' do
98
98
  before :each do
99
99
  Alpha.sphinx_scope(:by_name) { |name|
@@ -101,126 +101,116 @@ describe ThinkingSphinx::Search do
101
101
  }
102
102
  Alpha.sphinx_scope(:ids_only) { {:ids_only => true} }
103
103
  end
104
-
104
+
105
105
  after :each do
106
106
  Alpha.remove_sphinx_scopes
107
107
  end
108
-
108
+
109
109
  it "should handle Array methods" do
110
110
  ThinkingSphinx::Search.new.private_methods.should be_an(Array)
111
111
  end
112
-
112
+
113
113
  it "should raise a NoMethodError exception if unknown method" do
114
114
  lambda {
115
115
  ThinkingSphinx::Search.new.foo
116
116
  }.should raise_error(NoMethodError)
117
117
  end
118
-
118
+
119
119
  it "should not request results from client if method does not exist" do
120
120
  @client.should_not_receive(:query)
121
-
121
+
122
122
  lambda {
123
123
  ThinkingSphinx::Search.new.foo
124
124
  }.should raise_error(NoMethodError)
125
125
  end
126
-
126
+
127
127
  it "should accept sphinx scopes" do
128
128
  search = ThinkingSphinx::Search.new(:classes => [Alpha])
129
-
129
+
130
130
  lambda {
131
131
  search.by_name('Pat')
132
132
  }.should_not raise_error(NoMethodError)
133
133
  end
134
-
134
+
135
135
  it "should return itself when using a sphinx scope" do
136
136
  search = ThinkingSphinx::Search.new(:classes => [Alpha])
137
137
  search.by_name('Pat').object_id.should == search.object_id
138
138
  end
139
-
139
+
140
140
  it "should keep the same search object when chaining multiple scopes" do
141
141
  search = ThinkingSphinx::Search.new(:classes => [Alpha])
142
142
  search.by_name('Pat').ids_only.object_id.should == search.object_id
143
143
  end
144
144
  end
145
-
145
+
146
146
  describe '.search' do
147
147
  it "return the output of ThinkingSphinx.search" do
148
148
  @results = [] # to confirm same object
149
149
  ThinkingSphinx.stub!(:search => @results)
150
150
 
151
- ActiveSupport::Deprecation.silence do
152
- ThinkingSphinx::Search.search.object_id.should == @results.object_id
153
- end
151
+ ThinkingSphinx.search.object_id.should == @results.object_id
154
152
  end
155
153
  end
156
-
154
+
157
155
  describe '.search_for_ids' do
158
156
  it "return the output of ThinkingSphinx.search_for_ids" do
159
157
  @results = [] # to confirm same object
160
158
  ThinkingSphinx.stub!(:search_for_ids => @results)
161
159
 
162
- ActiveSupport::Deprecation.silence do
163
- ThinkingSphinx::Search.search_for_ids.object_id.
164
- should == @results.object_id
165
- end
160
+ ThinkingSphinx.search_for_ids.object_id.
161
+ should == @results.object_id
166
162
  end
167
163
  end
168
-
164
+
169
165
  describe '.search_for_id' do
170
166
  it "return the output of ThinkingSphinx.search_for_ids" do
171
167
  @results = [] # to confirm same object
172
168
  ThinkingSphinx.stub!(:search_for_id => @results)
173
169
 
174
- ActiveSupport::Deprecation.silence do
175
- ThinkingSphinx::Search.search_for_id.object_id.
176
- should == @results.object_id
177
- end
170
+ ThinkingSphinx.search_for_id.object_id.
171
+ should == @results.object_id
178
172
  end
179
173
  end
180
-
174
+
181
175
  describe '.count' do
182
176
  it "return the output of ThinkingSphinx.search" do
183
177
  @results = [] # to confirm same object
184
178
  ThinkingSphinx.stub!(:count => @results)
185
179
 
186
- ActiveSupport::Deprecation.silence do
187
- ThinkingSphinx::Search.count.object_id.should == @results.object_id
188
- end
180
+ ThinkingSphinx.count.object_id.should == @results.object_id
189
181
  end
190
182
  end
191
-
183
+
192
184
  describe '.facets' do
193
185
  it "return the output of ThinkingSphinx.facets" do
194
186
  @results = [] # to confirm same object
195
187
  ThinkingSphinx.stub!(:facets => @results)
196
188
 
197
- ActiveSupport::Deprecation.silence do
198
- ThinkingSphinx::Search.facets.object_id.should == @results.object_id
199
- end
189
+ ThinkingSphinx.facets.object_id.should == @results.object_id
200
190
  end
201
191
  end
202
-
192
+
203
193
  describe '.matching_fields' do
204
194
  it "should return objects with indexes matching 1's in the bitmask" do
205
195
  fields = ['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta', 'eta']
206
196
  ThinkingSphinx::Search.matching_fields(fields, 85).
207
197
  should == ['alpha', 'gamma', 'epsilon', 'eta']
208
-
198
+
209
199
  ThinkingSphinx::Search.matching_fields(fields, 42).
210
200
  should == ['beta', 'delta', 'zeta']
211
201
  end
212
202
  end
213
-
203
+
214
204
  describe '#populate' do
215
205
  before :each do
216
206
  @alpha_a, @alpha_b = Alpha.new, Alpha.new
217
207
  @beta_a, @beta_b = Beta.new, Beta.new
218
-
208
+
219
209
  @alpha_a.stub! :id => 1, :read_attribute => 1
220
210
  @alpha_b.stub! :id => 2, :read_attribute => 2
221
211
  @beta_a.stub! :id => 1, :read_attribute => 1
222
212
  @beta_b.stub! :id => 2, :read_attribute => 2
223
-
213
+
224
214
  @client.stub! :query => {
225
215
  :matches => minimal_result_hashes(@alpha_a, @beta_b, @alpha_b, @beta_a),
226
216
  :fields => ["one", "two", "three", "four", "five"]
@@ -228,14 +218,14 @@ describe ThinkingSphinx::Search do
228
218
  Alpha.stub! :find => [@alpha_a, @alpha_b]
229
219
  Beta.stub! :find => [@beta_a, @beta_b]
230
220
  end
231
-
221
+
232
222
  it "should issue only one select per model" do
233
223
  Alpha.should_receive(:find).once.and_return([@alpha_a, @alpha_b])
234
224
  Beta.should_receive(:find).once.and_return([@beta_a, @beta_b])
235
-
225
+
236
226
  ThinkingSphinx::Search.new.first
237
227
  end
238
-
228
+
239
229
  it "should mix the results from different models" do
240
230
  search = ThinkingSphinx::Search.new
241
231
  search[0].should be_a(Alpha)
@@ -243,7 +233,7 @@ describe ThinkingSphinx::Search do
243
233
  search[2].should be_a(Alpha)
244
234
  search[3].should be_a(Beta)
245
235
  end
246
-
236
+
247
237
  it "should maintain the Xoopit ordering for results" do
248
238
  search = ThinkingSphinx::Search.new
249
239
  search[0].id.should == 1
@@ -251,40 +241,40 @@ describe ThinkingSphinx::Search do
251
241
  search[2].id.should == 2
252
242
  search[3].id.should == 1
253
243
  end
254
-
244
+
255
245
  it "should use the requested classes to generate the index argument" do
256
246
  @client.should_receive(:query) do |query, index, comment|
257
247
  index.should == 'alpha_core,beta_core,beta_delta'
258
248
  end
259
-
249
+
260
250
  ThinkingSphinx::Search.new(:classes => [Alpha, Beta]).first
261
251
  end
262
-
252
+
263
253
  it "should restrict includes to the relevant classes" do
264
254
  Alpha.should_receive(:find) do |type, options|
265
255
  options[:include].should == [:betas]
266
256
  [@alpha_a, @alpha_b]
267
257
  end
268
-
258
+
269
259
  Beta.should_receive(:find) do |type, options|
270
260
  options[:include].should == [:gammas]
271
261
  [@beta_a, @beta_b]
272
262
  end
273
-
263
+
274
264
  ThinkingSphinx::Search.new(:include => [:betas, :gammas]).first
275
265
  end
276
-
266
+
277
267
  it "should restrict single includes to the relevant classes" do
278
268
  Alpha.should_receive(:find) do |type, options|
279
269
  options[:include].should == :betas
280
270
  [@alpha_a, @alpha_b]
281
271
  end
282
-
272
+
283
273
  Beta.should_receive(:find) do |type, options|
284
274
  options[:include].should be_nil
285
275
  [@beta_a, @beta_b]
286
276
  end
287
-
277
+
288
278
  ThinkingSphinx::Search.new(:include => :betas).first
289
279
  end
290
280
 
@@ -301,71 +291,71 @@ describe ThinkingSphinx::Search do
301
291
 
302
292
  ThinkingSphinx::Search.new(:include => [:thetas, {:betas => :gammas}]).first
303
293
  end
304
-
294
+
305
295
  it "should respect hash includes" do
306
296
  Alpha.should_receive(:find) do |type, options|
307
297
  options[:include].should == {:betas => :gammas}
308
298
  [@alpha_a, @alpha_b]
309
299
  end
310
-
300
+
311
301
  Beta.should_receive(:find) do |type, options|
312
302
  options[:include].should be_nil
313
303
  [@beta_a, @beta_b]
314
304
  end
315
-
305
+
316
306
  ThinkingSphinx::Search.new(:include => {:betas => :gammas}).first
317
307
  end
318
-
308
+
319
309
  it "should respect includes for single class searches" do
320
310
  Alpha.should_receive(:find) do |type, options|
321
311
  options[:include].should == {:betas => :gammas}
322
312
  [@alpha_a, @alpha_b]
323
313
  end
324
-
314
+
325
315
  ThinkingSphinx::Search.new(
326
316
  :include => {:betas => :gammas},
327
317
  :classes => [Alpha]
328
318
  ).first
329
319
  end
330
-
320
+
331
321
  describe 'query' do
332
322
  it "should concatenate arguments with spaces" do
333
323
  @client.should_receive(:query) do |query, index, comment|
334
324
  query.should == 'two words'
335
325
  end
336
-
326
+
337
327
  ThinkingSphinx::Search.new('two', 'words').first
338
328
  end
339
-
329
+
340
330
  it "should append conditions to the query" do
341
331
  @client.should_receive(:query) do |query, index, comment|
342
332
  query.should == 'general @focused specific'
343
333
  end
344
-
334
+
345
335
  ThinkingSphinx::Search.new('general', :conditions => {
346
336
  :focused => 'specific'
347
337
  }).first
348
338
  end
349
-
339
+
350
340
  it "append multiple conditions together" do
351
341
  @client.should_receive(:query) do |query, index, comment|
352
342
  query.should match(/general.+@foo word/)
353
343
  query.should match(/general.+@bar word/)
354
344
  end
355
-
345
+
356
346
  ThinkingSphinx::Search.new('general', :conditions => {
357
347
  :foo => 'word', :bar => 'word'
358
348
  }).first
359
349
  end
360
-
350
+
361
351
  it "should apply stars if requested, and handle full extended syntax" do
362
352
  input = %{a b* c (d | e) 123 5&6 (f_f g) !h "i j" "k l"~10 "m n"/3 @o p -(q|r)}
363
353
  expected = %{*a* b* *c* (*d* | *e*) *123* *5*&*6* (*f_f* *g*) !*h* "i j" "k l"~10 "m n"/3 @o *p* -(*q*|*r*)}
364
-
354
+
365
355
  @client.should_receive(:query) do |query, index, comment|
366
356
  query.should == expected
367
357
  end
368
-
358
+
369
359
  ThinkingSphinx::Search.new(input, :star => true).first
370
360
  end
371
361
 
@@ -373,7 +363,7 @@ describe ThinkingSphinx::Search do
373
363
  @client.should_receive(:query) do |query, index, comment|
374
364
  query.should == '*foo*@*bar*.*com*'
375
365
  end
376
-
366
+
377
367
  ThinkingSphinx::Search.new('foo@bar.com', :star => true).first
378
368
  end
379
369
 
@@ -381,77 +371,77 @@ describe ThinkingSphinx::Search do
381
371
  @client.should_receive(:query) do |query, index, comment|
382
372
  query.should == '*foo@bar.com* -*foo-bar*'
383
373
  end
384
-
374
+
385
375
  ThinkingSphinx::Search.new(
386
376
  'foo@bar.com -foo-bar', :star => /[\w@.-]+/u
387
377
  ).first
388
378
  end
389
-
379
+
390
380
  it "should ignore multi-field limitations" do
391
381
  @client.should_receive(:query) do |query, index, comment|
392
382
  query.should == '@(foo,bar) *baz*'
393
383
  end
394
-
384
+
395
385
  ThinkingSphinx::Search.new('@(foo,bar) baz', :star => true).first
396
386
  end
397
-
387
+
398
388
  it "should ignore multi-field limitations with spaces" do
399
389
  @client.should_receive(:query) do |query, index, comment|
400
390
  query.should == '@(foo bar) *baz*'
401
391
  end
402
-
392
+
403
393
  ThinkingSphinx::Search.new('@(foo bar) baz', :star => true).first
404
394
  end
405
-
395
+
406
396
  it "should ignore multi-field limitations in the middle of queries" do
407
397
  @client.should_receive(:query) do |query, index, comment|
408
398
  query.should == '*baz* @foo *bar* @(foo,bar) *baz*'
409
399
  end
410
-
400
+
411
401
  ThinkingSphinx::Search.new(
412
402
  'baz @foo bar @(foo,bar) baz', :star => true
413
403
  ).first
414
404
  end
415
405
  end
416
-
406
+
417
407
  describe 'comment' do
418
408
  it "should add comment if explicitly provided" do
419
409
  @client.should_receive(:query) do |query, index, comment|
420
410
  comment.should == 'custom log'
421
411
  end
422
-
412
+
423
413
  ThinkingSphinx::Search.new(:comment => 'custom log').first
424
414
  end
425
-
415
+
426
416
  it "should default to a blank comment" do
427
417
  @client.should_receive(:query) do |query, index, comment|
428
418
  comment.should == ''
429
419
  end
430
-
420
+
431
421
  ThinkingSphinx::Search.new.first
432
422
  end
433
423
  end
434
-
424
+
435
425
  describe 'match mode' do
436
426
  it "should default to :all" do
437
427
  ThinkingSphinx::Search.new.first
438
-
428
+
439
429
  @client.match_mode.should == :all
440
430
  end
441
-
431
+
442
432
  it "should default to :extended if conditions are supplied" do
443
433
  ThinkingSphinx::Search.new('general', :conditions => {
444
434
  :foo => 'word', :bar => 'word'
445
435
  }).first
446
-
436
+
447
437
  @client.match_mode.should == :extended
448
438
  end
449
-
439
+
450
440
  it "should use explicit match modes" do
451
441
  ThinkingSphinx::Search.new('general', :conditions => {
452
442
  :foo => 'word', :bar => 'word'
453
443
  }, :match_mode => :extended2).first
454
-
444
+
455
445
  @client.match_mode.should == :extended2
456
446
  end
457
447
  end
@@ -459,59 +449,59 @@ describe ThinkingSphinx::Search do
459
449
  describe 'sphinx_select' do
460
450
  it "should default to *" do
461
451
  ThinkingSphinx::Search.new.first
462
-
452
+
463
453
  @client.select.should == "*"
464
454
  end
465
-
455
+
466
456
  it "should get set on the client if specified" do
467
457
  ThinkingSphinx::Search.new('general',
468
458
  :sphinx_select => "*, foo as bar"
469
459
  ).first
470
-
460
+
471
461
  @client.select.should == "*, foo as bar"
472
462
  end
473
463
 
474
464
  end
475
-
465
+
476
466
  describe 'pagination' do
477
467
  it "should set the limit using per_page" do
478
468
  ThinkingSphinx::Search.new(:per_page => 30).first
479
469
  @client.limit.should == 30
480
470
  end
481
-
471
+
482
472
  it "should set the offset if pagination is requested" do
483
473
  ThinkingSphinx::Search.new(:page => 3).first
484
474
  @client.offset.should == 40
485
475
  end
486
-
476
+
487
477
  it "should set the offset by the per_page value" do
488
478
  ThinkingSphinx::Search.new(:page => 3, :per_page => 30).first
489
479
  @client.offset.should == 60
490
480
  end
491
481
  end
492
-
482
+
493
483
  describe 'filters' do
494
484
  it "should filter out deleted values by default" do
495
485
  ThinkingSphinx::Search.new.first
496
-
486
+
497
487
  filter = @client.filters.last
498
488
  filter.values.should == [0]
499
489
  filter.attribute.should == 'sphinx_deleted'
500
490
  filter.exclude?.should be_false
501
491
  end
502
-
492
+
503
493
  it "should add class filters for explicit classes" do
504
494
  ThinkingSphinx::Search.new(:classes => [Alpha, Beta]).first
505
-
495
+
506
496
  filter = @client.filters.last
507
497
  filter.values.should == [Alpha.to_crc32, Beta.to_crc32]
508
498
  filter.attribute.should == 'class_crc'
509
499
  filter.exclude?.should be_false
510
500
  end
511
-
501
+
512
502
  it "should add class filters for subclasses of requested classes" do
513
503
  ThinkingSphinx::Search.new(:classes => [Person]).first
514
-
504
+
515
505
  filter = @client.filters.last
516
506
  filter.values.should == [
517
507
  Parent.to_crc32, Admin::Person.to_crc32,
@@ -520,127 +510,127 @@ describe ThinkingSphinx::Search do
520
510
  filter.attribute.should == 'class_crc'
521
511
  filter.exclude?.should be_false
522
512
  end
523
-
513
+
524
514
  it "should append inclusive filters of integers" do
525
515
  ThinkingSphinx::Search.new(:with => {:int => 1}).first
526
-
516
+
527
517
  filter = @client.filters.last
528
518
  filter.values.should == [1]
529
519
  filter.attribute.should == 'int'
530
520
  filter.exclude?.should be_false
531
521
  end
532
-
522
+
533
523
  it "should append inclusive filters of floats" do
534
524
  ThinkingSphinx::Search.new(:with => {:float => 1.5}).first
535
-
525
+
536
526
  filter = @client.filters.last
537
527
  filter.values.should == [1.5]
538
528
  filter.attribute.should == 'float'
539
529
  filter.exclude?.should be_false
540
530
  end
541
-
531
+
542
532
  it "should append inclusive filters of booleans" do
543
533
  ThinkingSphinx::Search.new(:with => {:boolean => true}).first
544
-
534
+
545
535
  filter = @client.filters.last
546
536
  filter.values.should == [true]
547
537
  filter.attribute.should == 'boolean'
548
538
  filter.exclude?.should be_false
549
539
  end
550
-
540
+
551
541
  it "should append inclusive filters of arrays" do
552
542
  ThinkingSphinx::Search.new(:with => {:ints => [1, 2, 3]}).first
553
-
543
+
554
544
  filter = @client.filters.last
555
545
  filter.values.should == [1, 2, 3]
556
546
  filter.attribute.should == 'ints'
557
547
  filter.exclude?.should be_false
558
548
  end
559
-
549
+
560
550
  it "should treat nils in arrays as 0" do
561
551
  ThinkingSphinx::Search.new(:with => {:ints => [nil, 1, 2, 3]}).first
562
-
552
+
563
553
  filter = @client.filters.last
564
554
  filter.values.should == [0, 1, 2, 3]
565
555
  end
566
-
556
+
567
557
  it "should append inclusive filters of time ranges" do
568
558
  first, last = 1.week.ago, Time.now
569
559
  ThinkingSphinx::Search.new(:with => {
570
560
  :time => first..last
571
561
  }).first
572
-
562
+
573
563
  filter = @client.filters.last
574
564
  filter.values.should == (first.to_i..last.to_i)
575
565
  filter.attribute.should == 'time'
576
566
  filter.exclude?.should be_false
577
567
  end
578
-
568
+
579
569
  it "should append exclusive filters of integers" do
580
570
  ThinkingSphinx::Search.new(:without => {:int => 1}).first
581
-
571
+
582
572
  filter = @client.filters.last
583
573
  filter.values.should == [1]
584
574
  filter.attribute.should == 'int'
585
575
  filter.exclude?.should be_true
586
576
  end
587
-
577
+
588
578
  it "should append exclusive filters of floats" do
589
579
  ThinkingSphinx::Search.new(:without => {:float => 1.5}).first
590
-
580
+
591
581
  filter = @client.filters.last
592
582
  filter.values.should == [1.5]
593
583
  filter.attribute.should == 'float'
594
584
  filter.exclude?.should be_true
595
585
  end
596
-
586
+
597
587
  it "should append exclusive filters of booleans" do
598
588
  ThinkingSphinx::Search.new(:without => {:boolean => true}).first
599
-
589
+
600
590
  filter = @client.filters.last
601
591
  filter.values.should == [true]
602
592
  filter.attribute.should == 'boolean'
603
593
  filter.exclude?.should be_true
604
594
  end
605
-
595
+
606
596
  it "should append exclusive filters of arrays" do
607
597
  ThinkingSphinx::Search.new(:without => {:ints => [1, 2, 3]}).first
608
-
598
+
609
599
  filter = @client.filters.last
610
600
  filter.values.should == [1, 2, 3]
611
601
  filter.attribute.should == 'ints'
612
602
  filter.exclude?.should be_true
613
603
  end
614
-
604
+
615
605
  it "should append exclusive filters of time ranges" do
616
606
  first, last = 1.week.ago, Time.now
617
607
  ThinkingSphinx::Search.new(:without => {
618
608
  :time => first..last
619
609
  }).first
620
-
610
+
621
611
  filter = @client.filters.last
622
612
  filter.values.should == (first.to_i..last.to_i)
623
613
  filter.attribute.should == 'time'
624
614
  filter.exclude?.should be_true
625
615
  end
626
-
616
+
627
617
  it "should add separate filters for each item in a with_all value" do
628
618
  ThinkingSphinx::Search.new(:with_all => {:ints => [1, 2, 3]}).first
629
-
619
+
630
620
  filters = @client.filters[-3, 3]
631
621
  filters.each do |filter|
632
622
  filter.attribute.should == 'ints'
633
623
  filter.exclude?.should be_false
634
624
  end
635
-
625
+
636
626
  filters[0].values.should == [1]
637
627
  filters[1].values.should == [2]
638
628
  filters[2].values.should == [3]
639
629
  end
640
-
630
+
641
631
  it "should filter out specific ids using :without_ids" do
642
632
  ThinkingSphinx::Search.new(:without_ids => [4, 5, 6]).first
643
-
633
+
644
634
  filter = @client.filters.last
645
635
  filter.values.should == [4, 5, 6]
646
636
  filter.attribute.should == 'sphinx_internal_id'
@@ -654,7 +644,7 @@ describe ThinkingSphinx::Search do
654
644
  filter.attribute.should_not == 'sphinx_internal_id'
655
645
  end
656
646
  end
657
-
647
+
658
648
  describe 'sort mode' do
659
649
  it "should use :relevance as a default" do
660
650
  ThinkingSphinx::Search.new.first
@@ -692,18 +682,18 @@ describe ThinkingSphinx::Search do
692
682
  @client.sort_mode.should == :attr_desc
693
683
  end
694
684
  end
695
-
685
+
696
686
  describe 'sort by' do
697
687
  it "should presume order symbols are attributes" do
698
688
  ThinkingSphinx::Search.new(:order => :created_at).first
699
689
  @client.sort_by.should == 'created_at'
700
690
  end
701
-
691
+
702
692
  it "replace field names with their sortable attributes" do
703
693
  ThinkingSphinx::Search.new(:order => :name, :classes => [Alpha]).first
704
694
  @client.sort_by.should == 'name_sort'
705
695
  end
706
-
696
+
707
697
  it "should replace field names in strings" do
708
698
  ThinkingSphinx::Search.new(
709
699
  :order => "created_at ASC, name DESC", :classes => [Alpha]
@@ -711,43 +701,43 @@ describe ThinkingSphinx::Search do
711
701
  @client.sort_by.should == 'created_at ASC, name_sort DESC'
712
702
  end
713
703
  end
714
-
704
+
715
705
  describe 'max matches' do
716
706
  it "should use the global setting by default" do
717
707
  ThinkingSphinx::Search.new.first
718
708
  @client.max_matches.should == 1000
719
709
  end
720
-
710
+
721
711
  it "should use explicit setting" do
722
712
  ThinkingSphinx::Search.new(:max_matches => 2000).first
723
713
  @client.max_matches.should == 2000
724
714
  end
725
715
  end
726
-
716
+
727
717
  describe 'field weights' do
728
718
  it "should set field weights as provided" do
729
719
  ThinkingSphinx::Search.new(
730
720
  :field_weights => {'foo' => 10, 'bar' => 5}
731
721
  ).first
732
-
722
+
733
723
  @client.field_weights.should == {
734
724
  'foo' => 10, 'bar' => 5
735
725
  }
736
726
  end
737
-
727
+
738
728
  it "should use field weights set in the index" do
739
729
  ThinkingSphinx::Search.new(:classes => [Alpha]).first
740
-
730
+
741
731
  @client.field_weights.should == {'name' => 10}
742
732
  end
743
733
  end
744
-
734
+
745
735
  describe 'index weights' do
746
736
  it "should send index weights through to the client" do
747
737
  ThinkingSphinx::Search.new(:index_weights => {'foo' => 100}).first
748
738
  @client.index_weights.should == {'foo' => 100}
749
739
  end
750
-
740
+
751
741
  it "should convert classes to their core and delta index names" do
752
742
  ThinkingSphinx::Search.new(:index_weights => {Alpha => 100}).first
753
743
  @client.index_weights.should == {
@@ -756,15 +746,15 @@ describe ThinkingSphinx::Search do
756
746
  }
757
747
  end
758
748
  end
759
-
749
+
760
750
  describe 'grouping' do
761
751
  it "should convert group into group_by and group_function" do
762
752
  ThinkingSphinx::Search.new(:group => :edition).first
763
-
753
+
764
754
  @client.group_function.should == :attr
765
755
  @client.group_by.should == "edition"
766
756
  end
767
-
757
+
768
758
  it "should pass on explicit grouping arguments" do
769
759
  ThinkingSphinx::Search.new(
770
760
  :group_by => 'created_at',
@@ -772,45 +762,45 @@ describe ThinkingSphinx::Search do
772
762
  :group_clause => 'clause',
773
763
  :group_distinct => 'distinct'
774
764
  ).first
775
-
765
+
776
766
  @client.group_by.should == 'created_at'
777
767
  @client.group_function.should == :attr
778
768
  @client.group_clause.should == 'clause'
779
769
  @client.group_distinct.should == 'distinct'
780
770
  end
781
771
  end
782
-
772
+
783
773
  describe 'anchor' do
784
774
  it "should detect lat and lng attributes on the given model" do
785
775
  ThinkingSphinx::Search.new(
786
776
  :geo => [1.0, -1.0],
787
777
  :classes => [Alpha]
788
778
  ).first
789
-
779
+
790
780
  @client.anchor[:latitude_attribute].should == 'lat'
791
781
  @client.anchor[:longitude_attribute].should == 'lng'
792
782
  end
793
-
783
+
794
784
  it "should detect lat and lon attributes on the given model" do
795
785
  ThinkingSphinx::Search.new(
796
786
  :geo => [1.0, -1.0],
797
787
  :classes => [Beta]
798
788
  ).first
799
-
789
+
800
790
  @client.anchor[:latitude_attribute].should == 'lat'
801
791
  @client.anchor[:longitude_attribute].should == 'lon'
802
792
  end
803
-
793
+
804
794
  it "should detect latitude and longitude attributes on the given model" do
805
795
  ThinkingSphinx::Search.new(
806
796
  :geo => [1.0, -1.0],
807
797
  :classes => [Person]
808
798
  ).first
809
-
799
+
810
800
  @client.anchor[:latitude_attribute].should == 'latitude'
811
801
  @client.anchor[:longitude_attribute].should == 'longitude'
812
802
  end
813
-
803
+
814
804
  it "should accept manually defined latitude and longitude attributes" do
815
805
  ThinkingSphinx::Search.new(
816
806
  :geo => [1.0, -1.0],
@@ -818,43 +808,43 @@ describe ThinkingSphinx::Search do
818
808
  :latitude_attr => :updown,
819
809
  :longitude_attr => :leftright
820
810
  ).first
821
-
811
+
822
812
  @client.anchor[:latitude_attribute].should == 'updown'
823
813
  @client.anchor[:longitude_attribute].should == 'leftright'
824
814
  end
825
-
815
+
826
816
  it "should accept manually defined latitude and longitude attributes in the given model" do
827
817
  ThinkingSphinx::Search.new(
828
818
  :geo => [1.0, -1.0],
829
819
  :classes => [Friendship]
830
820
  ).first
831
-
821
+
832
822
  @client.anchor[:latitude_attribute].should == 'person_id'
833
823
  @client.anchor[:longitude_attribute].should == 'person_id'
834
824
  end
835
-
825
+
836
826
  it "should accept geo array for geo-position values" do
837
827
  ThinkingSphinx::Search.new(
838
828
  :geo => [1.0, -1.0],
839
829
  :classes => [Alpha]
840
830
  ).first
841
-
831
+
842
832
  @client.anchor[:latitude].should == 1.0
843
833
  @client.anchor[:longitude].should == -1.0
844
834
  end
845
-
835
+
846
836
  it "should accept lat and lng options for geo-position values" do
847
837
  ThinkingSphinx::Search.new(
848
838
  :lat => 1.0,
849
839
  :lng => -1.0,
850
840
  :classes => [Alpha]
851
841
  ).first
852
-
842
+
853
843
  @client.anchor[:latitude].should == 1.0
854
844
  @client.anchor[:longitude].should == -1.0
855
845
  end
856
846
  end
857
-
847
+
858
848
  describe 'sql ordering' do
859
849
  before :each do
860
850
  @client.stub! :query => {
@@ -862,7 +852,7 @@ describe ThinkingSphinx::Search do
862
852
  }
863
853
  Alpha.stub! :find => [@alpha_a, @alpha_b]
864
854
  end
865
-
855
+
866
856
  it "shouldn't re-sort SQL results based on Sphinx information" do
867
857
  search = ThinkingSphinx::Search.new(
868
858
  :classes => [Alpha],
@@ -871,25 +861,25 @@ describe ThinkingSphinx::Search do
871
861
  search.first.should == @alpha_a
872
862
  search.last.should == @alpha_b
873
863
  end
874
-
864
+
875
865
  it "should use the option for the ActiveRecord::Base#find calls" do
876
866
  Alpha.should_receive(:find) do |mode, options|
877
867
  options[:order].should == 'id'
878
868
  end
879
-
869
+
880
870
  ThinkingSphinx::Search.new(
881
871
  :classes => [Alpha],
882
872
  :sql_order => 'id'
883
873
  ).first
884
874
  end
885
875
  end
886
-
876
+
887
877
  describe ':only option' do
888
878
  it "returns the requested attribute as an array" do
889
879
  ThinkingSphinx::Search.new(:only => :class_crc).first.
890
880
  should == Alpha.to_crc32
891
881
  end
892
-
882
+
893
883
  it "returns multiple attributes as hashes with values" do
894
884
  ThinkingSphinx::Search.new(
895
885
  :only => [:class_crc, :sphinx_internal_id]
@@ -898,12 +888,12 @@ describe ThinkingSphinx::Search do
898
888
  :sphinx_internal_id => @alpha_a.id
899
889
  }
900
890
  end
901
-
891
+
902
892
  it "handles strings for a single attribute name" do
903
893
  ThinkingSphinx::Search.new(:only => 'class_crc').first.
904
894
  should == Alpha.to_crc32
905
895
  end
906
-
896
+
907
897
  it "handles strings for multiple attribute names" do
908
898
  ThinkingSphinx::Search.new(
909
899
  :only => ['class_crc', 'sphinx_internal_id']
@@ -913,82 +903,82 @@ describe ThinkingSphinx::Search do
913
903
  }
914
904
  end
915
905
  end
916
-
906
+
917
907
  context 'result objects' do
918
908
  describe '#excerpts' do
919
909
  before :each do
920
910
  @search = ThinkingSphinx::Search.new
921
911
  end
922
-
912
+
923
913
  it "should add excerpts method if objects don't already have one" do
924
914
  @search.first.should respond_to(:excerpts)
925
915
  end
926
-
916
+
927
917
  it "should return an instance of ThinkingSphinx::Excerpter" do
928
918
  @search.first.excerpts.should be_a(ThinkingSphinx::Excerpter)
929
919
  end
930
-
920
+
931
921
  it "should not add excerpts method if objects already have one" do
932
922
  @search.last.excerpts.should_not be_a(ThinkingSphinx::Excerpter)
933
923
  end
934
-
924
+
935
925
  # Fails in Ruby 1.9 (or maybe it's an RSpec update). Not sure why.
936
926
  it "should set up the excerpter with the instances and search" do
937
927
  [@alpha_a, @beta_b, @alpha_b, @beta_a].each do |object|
938
928
  ThinkingSphinx::Excerpter.should_receive(:new).with(@search, object)
939
929
  end
940
-
930
+
941
931
  @search.first
942
932
  end
943
933
  end
944
-
934
+
945
935
  describe '#sphinx_attributes' do
946
936
  before :each do
947
937
  @search = ThinkingSphinx::Search.new
948
938
  end
949
-
939
+
950
940
  it "should add sphinx_attributes method if objects don't already have one" do
951
941
  @search.last.should respond_to(:sphinx_attributes)
952
942
  end
953
-
943
+
954
944
  it "should return a hash" do
955
945
  @search.last.sphinx_attributes.should be_a(Hash)
956
946
  end
957
-
947
+
958
948
  it "should not add sphinx_attributes if objects have a method of that name already" do
959
949
  @search.first.sphinx_attributes.should_not be_a(Hash)
960
950
  end
961
-
951
+
962
952
  it "should pair sphinx_attributes with the correct hash" do
963
953
  hash = @search.last.sphinx_attributes
964
954
  hash['sphinx_internal_id'].should == @search.last.id
965
955
  hash['class_crc'].should == @search.last.class.to_crc32
966
956
  end
967
957
  end
968
-
958
+
969
959
  describe '#matching_fields' do
970
960
  it "should add matching_fields method if using fieldmask ranking mode" do
971
961
  search = ThinkingSphinx::Search.new :rank_mode => :fieldmask
972
962
  search.first.should respond_to(:matching_fields)
973
963
  end
974
-
964
+
975
965
  it "should not add matching_fields method if object already have one" do
976
966
  search = ThinkingSphinx::Search.new :rank_mode => :fieldmask
977
967
  search.last.matching_fields.should_not be_an(Array)
978
968
  end
979
-
969
+
980
970
  it "should return an array" do
981
971
  search = ThinkingSphinx::Search.new :rank_mode => :fieldmask
982
972
  search.first.matching_fields.should be_an(Array)
983
973
  end
984
-
974
+
985
975
  it "should return the fields that the bitmask match" do
986
976
  search = ThinkingSphinx::Search.new :rank_mode => :fieldmask
987
977
  search.first.matching_fields.should == ['one', 'three', 'five']
988
978
  end
989
979
  end
990
980
  end
991
-
981
+
992
982
  context 'Sphinx errors' do
993
983
  describe '#error?' do
994
984
  before :each do
@@ -1010,110 +1000,110 @@ describe ThinkingSphinx::Search do
1010
1000
  end
1011
1001
  end
1012
1002
  end
1013
-
1003
+
1014
1004
  describe '#current_page' do
1015
1005
  it "should return 1 by default" do
1016
1006
  ThinkingSphinx::Search.new.current_page.should == 1
1017
1007
  end
1018
-
1008
+
1019
1009
  it "should handle string page values" do
1020
1010
  ThinkingSphinx::Search.new(:page => '2').current_page.should == 2
1021
1011
  end
1022
-
1012
+
1023
1013
  it "should handle empty string page values" do
1024
1014
  ThinkingSphinx::Search.new(:page => '').current_page.should == 1
1025
1015
  end
1026
-
1016
+
1027
1017
  it "should return the requested page" do
1028
1018
  ThinkingSphinx::Search.new(:page => 10).current_page.should == 10
1029
1019
  end
1030
1020
  end
1031
-
1021
+
1032
1022
  describe '#per_page' do
1033
1023
  it "should return 20 by default" do
1034
1024
  ThinkingSphinx::Search.new.per_page.should == 20
1035
1025
  end
1036
-
1026
+
1037
1027
  it "should allow for custom values" do
1038
1028
  ThinkingSphinx::Search.new(:per_page => 30).per_page.should == 30
1039
1029
  end
1040
-
1030
+
1041
1031
  it "should prioritise :limit over :per_page if given" do
1042
1032
  ThinkingSphinx::Search.new(
1043
1033
  :per_page => 30, :limit => 40
1044
1034
  ).per_page.should == 40
1045
1035
  end
1046
-
1036
+
1047
1037
  it "should allow for string arguments" do
1048
1038
  ThinkingSphinx::Search.new(:per_page => '10').per_page.should == 10
1049
1039
  end
1050
1040
  end
1051
-
1041
+
1052
1042
  describe '#total_pages' do
1053
1043
  it "should calculate the total pages depending on per_page and total_entries" do
1054
1044
  ThinkingSphinx::Search.new.total_pages.should == 3
1055
1045
  end
1056
-
1046
+
1057
1047
  it "should allow for custom per_page values" do
1058
1048
  ThinkingSphinx::Search.new(:per_page => 30).total_pages.should == 2
1059
1049
  end
1060
-
1050
+
1061
1051
  it "should not overstep the max_matches implied limit" do
1062
1052
  @client.stub!(:query => {
1063
1053
  :matches => [], :total_found => 41, :total => 40
1064
1054
  })
1065
-
1055
+
1066
1056
  ThinkingSphinx::Search.new.total_pages.should == 2
1067
1057
  end
1068
-
1058
+
1069
1059
  it "should return 0 if there is no index and therefore no results" do
1070
1060
  @client.stub!(:query => {
1071
1061
  :matches => [], :total_found => nil, :total => nil
1072
1062
  })
1073
-
1063
+
1074
1064
  ThinkingSphinx::Search.new.total_pages.should == 0
1075
1065
  end
1076
1066
  end
1077
-
1067
+
1078
1068
  describe '#next_page' do
1079
1069
  it "should return one more than the current page" do
1080
1070
  ThinkingSphinx::Search.new.next_page.should == 2
1081
1071
  end
1082
-
1072
+
1083
1073
  it "should return nil if on the last page" do
1084
1074
  ThinkingSphinx::Search.new(:page => 3).next_page.should be_nil
1085
1075
  end
1086
1076
  end
1087
-
1077
+
1088
1078
  describe '#previous_page' do
1089
1079
  it "should return one less than the current page" do
1090
1080
  ThinkingSphinx::Search.new(:page => 2).previous_page.should == 1
1091
1081
  end
1092
-
1082
+
1093
1083
  it "should return nil if on the first page" do
1094
1084
  ThinkingSphinx::Search.new.previous_page.should be_nil
1095
1085
  end
1096
1086
  end
1097
-
1087
+
1098
1088
  describe '#total_entries' do
1099
1089
  it "should return the total number of results, not just the amount on the page" do
1100
1090
  ThinkingSphinx::Search.new.total_entries.should == 41
1101
1091
  end
1102
-
1092
+
1103
1093
  it "should return 0 if there is no index and therefore no results" do
1104
1094
  @client.stub!(:query => {
1105
1095
  :matches => [], :total_found => nil
1106
1096
  })
1107
-
1097
+
1108
1098
  ThinkingSphinx::Search.new.total_entries.should == 0
1109
1099
  end
1110
1100
  end
1111
-
1101
+
1112
1102
  describe '#offset' do
1113
1103
  it "should default to 0" do
1114
1104
  ThinkingSphinx::Search.new.offset.should == 0
1115
1105
  end
1116
-
1106
+
1117
1107
  it "should increase by the per_page value for each page in" do
1118
1108
  ThinkingSphinx::Search.new(:per_page => 25, :page => 2).offset.should == 25
1119
1109
  end
@@ -1122,33 +1112,33 @@ describe ThinkingSphinx::Search do
1122
1112
  ThinkingSphinx::Search.new(:offset => 5).offset.should == 5
1123
1113
  end
1124
1114
  end
1125
-
1115
+
1126
1116
  describe '#indexes' do
1127
1117
  it "should default to '*'" do
1128
1118
  ThinkingSphinx::Search.new.indexes.should == '*'
1129
1119
  end
1130
-
1120
+
1131
1121
  it "should use given class to determine index name" do
1132
1122
  ThinkingSphinx::Search.new(:classes => [Alpha]).indexes.
1133
1123
  should == 'alpha_core'
1134
1124
  end
1135
-
1125
+
1136
1126
  it "should add both core and delta indexes for given classes" do
1137
1127
  ThinkingSphinx::Search.new(:classes => [Alpha, Beta]).indexes.
1138
1128
  should == 'alpha_core,beta_core,beta_delta'
1139
1129
  end
1140
-
1130
+
1141
1131
  it "should respect the :index option" do
1142
1132
  ThinkingSphinx::Search.new(:classes => [Alpha], :index => '*').indexes.
1143
1133
  should == '*'
1144
1134
  end
1145
1135
  end
1146
-
1136
+
1147
1137
  describe '.each_with_groupby_and_count' do
1148
1138
  before :each do
1149
1139
  @alpha = Alpha.new
1150
1140
  @alpha.stub!(:id => 1, :read_attribute => 1)
1151
-
1141
+
1152
1142
  @client.stub! :query => {
1153
1143
  :matches => [{
1154
1144
  :attributes => {
@@ -1162,7 +1152,7 @@ describe ThinkingSphinx::Search do
1162
1152
  }
1163
1153
  Alpha.stub!(:find => [@alpha])
1164
1154
  end
1165
-
1155
+
1166
1156
  it "should yield the match, group and count" do
1167
1157
  search = ThinkingSphinx::Search.new
1168
1158
  search.each_with_groupby_and_count do |obj, group, count|
@@ -1171,7 +1161,7 @@ describe ThinkingSphinx::Search do
1171
1161
  count.should == 5
1172
1162
  end
1173
1163
  end
1174
-
1164
+
1175
1165
  it "should be aliased to each_with_group_and_count" do
1176
1166
  search = ThinkingSphinx::Search.new
1177
1167
  search.each_with_group_and_count do |obj, group, count|
@@ -1181,12 +1171,12 @@ describe ThinkingSphinx::Search do
1181
1171
  end
1182
1172
  end
1183
1173
  end
1184
-
1174
+
1185
1175
  describe '.each_with_weighting' do
1186
1176
  before :each do
1187
1177
  @alpha = Alpha.new
1188
1178
  @alpha.stub!(:id => 1, :read_attribute => 1)
1189
-
1179
+
1190
1180
  @client.stub! :query => {
1191
1181
  :matches => [{
1192
1182
  :attributes => {
@@ -1198,7 +1188,7 @@ describe ThinkingSphinx::Search do
1198
1188
  }
1199
1189
  Alpha.stub!(:find => [@alpha])
1200
1190
  end
1201
-
1191
+
1202
1192
  it "should yield the match and weight" do
1203
1193
  search = ThinkingSphinx::Search.new
1204
1194
  search.each_with_weighting do |obj, weight|
@@ -1207,12 +1197,12 @@ describe ThinkingSphinx::Search do
1207
1197
  end
1208
1198
  end
1209
1199
  end
1210
-
1200
+
1211
1201
  describe '.each_with_*' do
1212
1202
  before :each do
1213
1203
  @alpha = Alpha.new
1214
1204
  @alpha.stub!(:id => 1, :read_attribute => 1)
1215
-
1205
+
1216
1206
  @client.stub! :query => {
1217
1207
  :matches => [{
1218
1208
  :attributes => {
@@ -1226,31 +1216,31 @@ describe ThinkingSphinx::Search do
1226
1216
  }]
1227
1217
  }
1228
1218
  Alpha.stub!(:find => [@alpha])
1229
-
1219
+
1230
1220
  @search = ThinkingSphinx::Search.new
1231
1221
  end
1232
-
1222
+
1233
1223
  it "should yield geodist if requested" do
1234
1224
  @search.each_with_geodist do |obj, distance|
1235
1225
  obj.should == @alpha
1236
1226
  distance.should == 101
1237
1227
  end
1238
1228
  end
1239
-
1229
+
1240
1230
  it "should yield count if requested" do
1241
1231
  @search.each_with_count do |obj, count|
1242
1232
  obj.should == @alpha
1243
1233
  count.should == 103
1244
1234
  end
1245
1235
  end
1246
-
1236
+
1247
1237
  it "should yield groupby if requested" do
1248
1238
  @search.each_with_groupby do |obj, group|
1249
1239
  obj.should == @alpha
1250
1240
  group.should == 102
1251
1241
  end
1252
1242
  end
1253
-
1243
+
1254
1244
  it "should still use the array's each_with_index" do
1255
1245
  @search.each_with_index do |obj, index|
1256
1246
  obj.should == @alpha
@@ -1258,7 +1248,7 @@ describe ThinkingSphinx::Search do
1258
1248
  end
1259
1249
  end
1260
1250
  end
1261
-
1251
+
1262
1252
  describe '#excerpt_for' do
1263
1253
  before :each do
1264
1254
  @client.stub!(:excerpts => ['excerpted string'])
@@ -1268,53 +1258,53 @@ describe ThinkingSphinx::Search do
1268
1258
  })
1269
1259
  @search = ThinkingSphinx::Search.new(:classes => [Alpha])
1270
1260
  end
1271
-
1261
+
1272
1262
  it "should return the Sphinx excerpt value" do
1273
1263
  @search.excerpt_for('string').should == 'excerpted string'
1274
1264
  end
1275
-
1265
+
1276
1266
  it "should use the given model's core index" do
1277
1267
  @client.should_receive(:excerpts) do |options|
1278
1268
  options[:index].should == 'alpha_core'
1279
1269
  end
1280
-
1270
+
1281
1271
  @search.excerpt_for('string')
1282
1272
  end
1283
-
1273
+
1284
1274
  it "should respect the provided index option" do
1285
1275
  @search = ThinkingSphinx::Search.new(:classes => [Alpha], :index => 'foo')
1286
1276
  @client.should_receive(:excerpts) do |options|
1287
1277
  options[:index].should == 'foo'
1288
1278
  end
1289
-
1279
+
1290
1280
  @search.excerpt_for('string')
1291
1281
  end
1292
-
1282
+
1293
1283
  it "should optionally take a second argument to allow for multi-model searches" do
1294
1284
  @client.should_receive(:excerpts) do |options|
1295
1285
  options[:index].should == 'beta_core'
1296
1286
  end
1297
-
1287
+
1298
1288
  @search.excerpt_for('string', Beta)
1299
1289
  end
1300
-
1290
+
1301
1291
  it "should join the words together" do
1302
1292
  @client.should_receive(:excerpts) do |options|
1303
1293
  options[:words].should == @search.results[:words].keys.join(' ')
1304
1294
  end
1305
-
1295
+
1306
1296
  @search.excerpt_for('string', Beta)
1307
1297
  end
1308
-
1298
+
1309
1299
  it "should use the correct index in STI situations" do
1310
1300
  @client.should_receive(:excerpts) do |options|
1311
1301
  options[:index].should == 'person_core'
1312
1302
  end
1313
-
1303
+
1314
1304
  @search.excerpt_for('string', Parent)
1315
1305
  end
1316
1306
  end
1317
-
1307
+
1318
1308
  describe '#search' do
1319
1309
  before :each do
1320
1310
  @search = ThinkingSphinx::Search.new('word',
@@ -1322,31 +1312,31 @@ describe ThinkingSphinx::Search do
1322
1312
  :with => {:int => 5}
1323
1313
  )
1324
1314
  end
1325
-
1315
+
1326
1316
  it "should return itself" do
1327
1317
  @search.search.object_id.should == @search.object_id
1328
1318
  end
1329
-
1319
+
1330
1320
  it "should merge in arguments" do
1331
1321
  @client.should_receive(:query) do |query, index, comments|
1332
1322
  query.should == 'word more @field field'
1333
1323
  end
1334
-
1324
+
1335
1325
  @search.search('more').first
1336
1326
  end
1337
-
1327
+
1338
1328
  it "should merge conditions" do
1339
1329
  @client.should_receive(:query) do |query, index, comments|
1340
1330
  query.should match(/@name plato/)
1341
1331
  query.should match(/@field field/)
1342
1332
  end
1343
-
1333
+
1344
1334
  @search.search(:conditions => {:name => 'plato'}).first
1345
1335
  end
1346
-
1336
+
1347
1337
  it "should merge filters" do
1348
1338
  @search.search(:with => {:float => 1.5}).first
1349
-
1339
+
1350
1340
  @client.filters.detect { |filter|
1351
1341
  filter.attribute == 'float'
1352
1342
  }.should_not be_nil
@@ -1355,34 +1345,34 @@ describe ThinkingSphinx::Search do
1355
1345
  }.should_not be_nil
1356
1346
  end
1357
1347
  end
1358
-
1348
+
1359
1349
  describe '#freeze' do
1360
1350
  before :each do
1361
1351
  @search = ThinkingSphinx::Search.new
1362
1352
  end
1363
-
1353
+
1364
1354
  it "should populate the result set" do
1365
1355
  @search.freeze
1366
1356
  @search.should be_populated
1367
1357
  end
1368
-
1358
+
1369
1359
  it "should freeze the underlying array" do
1370
1360
  @search.freeze
1371
1361
  @search.to_a.should be_frozen
1372
1362
  end
1373
-
1363
+
1374
1364
  it "should return the Search object" do
1375
1365
  @search.freeze.should be_a(ThinkingSphinx::Search)
1376
1366
  end
1377
1367
  end
1378
-
1368
+
1379
1369
  describe '#client' do
1380
1370
  let(:client) { Riddle::Client.new }
1381
1371
  it "should respect the client in options" do
1382
1372
  search = ThinkingSphinx::Search.new :client => client
1383
1373
  search.client.should == client
1384
1374
  end
1385
-
1375
+
1386
1376
  it "should get a new client from the configuration singleton by default" do
1387
1377
  ThinkingSphinx::Configuration.instance.stub!(:client => client)
1388
1378
  ThinkingSphinx::Search.new.client.should == client