thinking-sphinx 1.4.11 → 1.4.12

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