freelancing-god-thinking-sphinx 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,13 +59,13 @@ describe ThinkingSphinx::Configuration do
59
59
  })
60
60
 
61
61
  @person_index_a = ThinkingSphinx::Index.stub_instance(
62
- :to_config => "", :adapter => :mysql, :delta? => false
62
+ :to_config => "", :adapter => :mysql, :delta? => false, :name => "person"
63
63
  )
64
64
  @person_index_b = ThinkingSphinx::Index.stub_instance(
65
- :to_config => "", :adapter => :mysql, :delta? => false
65
+ :to_config => "", :adapter => :mysql, :delta? => false, :name => "person"
66
66
  )
67
67
  @friendship_index_a = ThinkingSphinx::Index.stub_instance(
68
- :to_config => "", :adapter => :mysql, :delta? => false
68
+ :to_config => "", :adapter => :mysql, :delta? => false, :name => "friendship"
69
69
  )
70
70
 
71
71
  Person.stub_method(:indexes => [@person_index_a, @person_index_b])
@@ -212,6 +212,8 @@ describe ThinkingSphinx::Configuration do
212
212
  "address" => "127.0.0.1",
213
213
  "port" => 3333,
214
214
  "allow_star" => true,
215
+ "min_prefix_len" => 2,
216
+ "min_infix_len" => 3,
215
217
  "mem_limit" => "128M",
216
218
  "max_matches" => 1001,
217
219
  "morphology" => "stem_ru",
@@ -238,21 +240,20 @@ describe ThinkingSphinx::Configuration do
238
240
  before :each do
239
241
  @config = ThinkingSphinx::Configuration.new
240
242
  @model = Class.stub_instance(
241
- :indexes => [],
242
- :name => "SpecModel"
243
+ :indexes => [ThinkingSphinx::Index.new(Person)]
243
244
  )
244
245
  end
245
246
 
246
247
  it "should take its name from the model, with _core appended" do
247
248
  @config.send(:core_index_for_model, @model, "my sources").should match(
248
- /index specmodel_core/
249
+ /index person_core/
249
250
  )
250
251
  end
251
252
 
252
253
  it "should set the path to follow the name" do
253
254
  @config.searchd_file_path = "/my/file/path"
254
255
  @config.send(:core_index_for_model, @model, "my sources").should match(
255
- /path = \/my\/file\/path\/specmodel_core/
256
+ /path = \/my\/file\/path\/person_core/
256
257
  )
257
258
  end
258
259
 
@@ -319,6 +320,16 @@ describe ThinkingSphinx::Configuration do
319
320
  text.should match(/min_infix_len\s+= 1/)
320
321
  end
321
322
 
323
+ it "should use the configuration's infix and prefix length values if set" do
324
+ @config.allow_star = true
325
+ @config.min_prefix_len = 3
326
+ @config.min_infix_len = 2
327
+ text = @config.send(:core_index_for_model, @model, "my sources")
328
+
329
+ text.should match(/min_prefix_len\s+= 3/)
330
+ text.should match(/min_infix_len\s+= 2/)
331
+ end
332
+
322
333
  it "should not include the star-related settings when allow_star is false" do
323
334
  @config.allow_star = false
324
335
  text = @config.send(:core_index_for_model, @model, "my sources")
@@ -329,11 +340,10 @@ describe ThinkingSphinx::Configuration do
329
340
  end
330
341
 
331
342
  it "should set prefix_fields if any fields are flagged explicitly" do
332
- @index = ThinkingSphinx::Index.stub_instance(
343
+ @model.indexes.first.stub_methods(
333
344
  :prefix_fields => ["a", "b", "c"],
334
345
  :infix_fields => ["d", "e", "f"]
335
346
  )
336
- @model.stub_method(:indexes => [@index])
337
347
 
338
348
  @config.send(:core_index_for_model, @model, "my sources").should match(
339
349
  /prefix_fields\s+= a, b, c/
@@ -347,11 +357,10 @@ describe ThinkingSphinx::Configuration do
347
357
  end
348
358
 
349
359
  it "should set infix_fields if any fields are flagged explicitly" do
350
- @index = ThinkingSphinx::Index.stub_instance(
360
+ @model.indexes.first.stub_methods(
351
361
  :prefix_fields => ["a", "b", "c"],
352
362
  :infix_fields => ["d", "e", "f"]
353
363
  )
354
- @model.stub_method(:indexes => [@index])
355
364
 
356
365
  @config.send(:core_index_for_model, @model, "my sources").should match(
357
366
  /infix_fields\s+= d, e, f/
@@ -363,32 +372,54 @@ describe ThinkingSphinx::Configuration do
363
372
  /infix_fields\s+=/
364
373
  )
365
374
  end
375
+
376
+ it "should include html_strip if value is set" do
377
+ @config.html_strip = 1
378
+ text = @config.send(:core_index_for_model, @model, "my sources")
379
+ text.should match(/html_strip\s+= 1/)
380
+ end
381
+
382
+ it "shouldn't include html_strip if value is not set" do
383
+ text = @config.send(:core_index_for_model, @model, "my sources")
384
+ text.should_not match(/html_strip/)
385
+ end
386
+
387
+ it "should include html_remove_elements if values are set" do
388
+ @config.html_remove_elements = 'script'
389
+ text = @config.send(:core_index_for_model, @model, "my sources")
390
+ text.should match(/html_remove_elements\s+= script/)
391
+ end
392
+
393
+ it "shouldn't include html_remove_elements if no values are set" do
394
+ text = @config.send(:core_index_for_model, @model, "my sources")
395
+ text.should_not match(/html_remove_elements/)
396
+ end
366
397
  end
367
398
 
368
399
  describe "delta_index_for_model method" do
369
400
  before :each do
370
401
  @config = ThinkingSphinx::Configuration.new
371
402
  @model = Class.stub_instance(
372
- :name => "SpecModel"
403
+ :indexes => [ThinkingSphinx::Index.new(Person)]
373
404
  )
374
405
  end
375
406
 
376
407
  it "should take its name from the model, with _delta appended" do
377
408
  @config.send(:delta_index_for_model, @model, "delta_sources").should match(
378
- /index specmodel_delta/
409
+ /index person_delta/
379
410
  )
380
411
  end
381
412
 
382
413
  it "should inherit from the equivalent core index" do
383
414
  @config.send(:delta_index_for_model, @model, "delta_sources").should match(
384
- /index specmodel_delta : specmodel_core/
415
+ /index person_delta : person_core/
385
416
  )
386
417
  end
387
418
 
388
419
  it "should set the path to follow the name" do
389
420
  @config.searchd_file_path = "/my/file/path"
390
421
  @config.send(:delta_index_for_model, @model, "delta_sources").should match(
391
- /path = \/my\/file\/path\/specmodel_delta/
422
+ /path = \/my\/file\/path\/person_delta/
392
423
  )
393
424
  end
394
425
  end
@@ -397,14 +428,13 @@ describe ThinkingSphinx::Configuration do
397
428
  before :each do
398
429
  @config = ThinkingSphinx::Configuration.new
399
430
  @model = Class.stub_instance(
400
- :name => "SpecModel",
401
- :indexes => []
431
+ :indexes => [ThinkingSphinx::Index.new(Person)]
402
432
  )
403
433
  end
404
434
 
405
435
  it "should take its name from the model" do
406
436
  @config.send(:distributed_index_for_model, @model).should match(
407
- /index specmodel/
437
+ /index person/
408
438
  )
409
439
  end
410
440
 
@@ -416,18 +446,26 @@ describe ThinkingSphinx::Configuration do
416
446
 
417
447
  it "should include the core as a local source" do
418
448
  @config.send(:distributed_index_for_model, @model).should match(
419
- /local = specmodel_core/
449
+ /local = person_core/
420
450
  )
421
451
  end
422
452
 
423
453
  it "should only include the delta as a local source if an index is flagged to be delta" do
424
454
  @config.send(:distributed_index_for_model, @model).should_not match(
425
- /local = specmodel_delta/
455
+ /local = person_delta/
456
+ )
457
+
458
+ @model.indexes.first.stub_method(:delta? => true)
459
+ @config.send(:distributed_index_for_model, @model).should match(
460
+ /local = person_delta/
426
461
  )
462
+ end
463
+
464
+ it "should handle namespaced models correctly" do
465
+ Person.stub_method(:name => "Namespaced::Model")
427
466
 
428
- @model.stub_method(:indexes => [ThinkingSphinx::Index.stub_instance(:delta? => true)])
429
467
  @config.send(:distributed_index_for_model, @model).should match(
430
- /local = specmodel_delta/
468
+ /index namespaced_model/
431
469
  )
432
470
  end
433
471
  end
@@ -59,6 +59,12 @@ describe ThinkingSphinx::Index do
59
59
  /sql_query_pre\s+= SET NAMES utf8/
60
60
  )
61
61
 
62
+ @index.stub_method(:delta? => true)
63
+ @index.to_config(0, @database, "utf-8").should match(
64
+ /source person_0_delta.+sql_query_pre\s+= SET NAMES utf8/m
65
+ )
66
+
67
+ @index.stub_method(:delta? => false)
62
68
  @index.to_config(0, @database, "non-utf-8").should_not match(
63
69
  /SET NAMES utf8/
64
70
  )
@@ -75,6 +81,24 @@ describe ThinkingSphinx::Index do
75
81
  )
76
82
  end
77
83
 
84
+ it "should not set group_concat_max_len if not specified" do
85
+ @index.to_config(0, @database, "utf-8").should_not match(
86
+ /group_concat_max_len/
87
+ )
88
+ end
89
+
90
+ it "should set group_concat_max_len if specified" do
91
+ @index.options.merge! :group_concat_max_len => 2056
92
+ @index.to_config(0, @database, "utf-8").should match(
93
+ /sql_query_pre\s+= SET SESSION group_concat_max_len = 2056/
94
+ )
95
+
96
+ @index.stub_method(:delta? => true)
97
+ @index.to_config(0, @database, "utf-8").should match(
98
+ /source person_0_delta.+sql_query_pre\s+= SET SESSION group_concat_max_len = 2056/m
99
+ )
100
+ end
101
+
78
102
  it "should use the main query from the index" do
79
103
  @index.to_config(0, @database, "utf-8").should match(
80
104
  /sql_query\s+= SQL/
@@ -146,6 +170,22 @@ describe ThinkingSphinx::Index do
146
170
  end
147
171
  end
148
172
 
173
+ describe "to_sql_query_range method" do
174
+ before :each do
175
+ @index = ThinkingSphinx::Index.new(Person)
176
+ end
177
+
178
+ it "should add COALESCE around MIN and MAX calls if using PostgreSQL" do
179
+ @index.stub_method(:adapter => :postgres)
180
+
181
+ @index.to_sql_query_range.should match(/COALESCE\(MIN.+COALESCE\(MAX/)
182
+ end
183
+
184
+ it "shouldn't add COALESCE if using MySQL" do
185
+ @index.to_sql_query_range.should_not match(/COALESCE/)
186
+ end
187
+ end
188
+
149
189
  describe "prefix_fields method" do
150
190
  before :each do
151
191
  @index = ThinkingSphinx::Index.new(Person)
@@ -167,7 +207,7 @@ describe ThinkingSphinx::Index do
167
207
  end
168
208
  end
169
209
 
170
- describe "infix_fields" do
210
+ describe "infix_fields method" do
171
211
  before :each do
172
212
  @index = ThinkingSphinx::Index.new(Person)
173
213
 
@@ -187,4 +227,41 @@ describe ThinkingSphinx::Index do
187
227
  @index.infix_fields.should_not include(@field_b)
188
228
  end
189
229
  end
230
+
231
+ describe "empty? method" do
232
+ before :each do
233
+ @index = ThinkingSphinx::Index.new(Person)
234
+ config = ThinkingSphinx::Configuration.new
235
+
236
+ `mkdir -p #{config.searchd_file_path}`
237
+ @file_path = "#{config.searchd_file_path}/#{@index.name}_core.spa"
238
+ end
239
+
240
+ after :each do
241
+ `rm #{@file_path}` if File.exists?(@file_path)
242
+ end
243
+
244
+ it "should return true if the core index files are empty" do
245
+ `touch #{@file_path}`
246
+ @index.should be_empty
247
+ end
248
+
249
+ it "should return true if the core index files don't exist" do
250
+ @index.should be_empty
251
+ end
252
+
253
+ it "should return false if the core index files aren't empty" do
254
+ `echo 'a' > #{@file_path}`
255
+ @index.should_not be_empty
256
+ end
257
+
258
+ it "should check the delta files if specified" do
259
+ @index.should be_empty(:delta)
260
+
261
+ `echo 'a' > #{@file_path.gsub(/_core.spa$/, '_delta.spa')}`
262
+ @index.should_not be_empty(:delta)
263
+
264
+ `rm #{@file_path}` if File.exists?(@file_path.gsub(/_core.spa$/, '_delta.spa'))
265
+ end
266
+ end
190
267
  end
@@ -1,6 +1,48 @@
1
1
  require 'spec/spec_helper'
2
2
 
3
3
  describe ThinkingSphinx::Search do
4
+ describe "search_for_id method" do
5
+ before :each do
6
+ @client = Riddle::Client.stub_instance(
7
+ :filters => [],
8
+ :filters= => true,
9
+ :id_range= => true,
10
+ :query => {
11
+ :matches => []
12
+ }
13
+ )
14
+
15
+ ThinkingSphinx::Search.stub_methods(
16
+ :client_from_options => @client,
17
+ :search_conditions => ["", []]
18
+ )
19
+ end
20
+
21
+ it "should set the client id range to focus on the given id" do
22
+ ThinkingSphinx::Search.search_for_id 42, "an_index"
23
+
24
+ @client.should have_received(:id_range=).with(42..42)
25
+ end
26
+
27
+ it "should query on the given index" do
28
+ ThinkingSphinx::Search.search_for_id 42, "an_index"
29
+
30
+ @client.should have_received(:query).with("", "an_index")
31
+ end
32
+
33
+ it "should return true if a record is returned" do
34
+ @client.stub_method(:query => {
35
+ :matches => [24]
36
+ })
37
+
38
+ ThinkingSphinx::Search.search_for_id(42, "an_index").should be_true
39
+ end
40
+
41
+ it "should return false if no records are returned" do
42
+ ThinkingSphinx::Search.search_for_id(42, "an_index").should be_false
43
+ end
44
+ end
45
+
4
46
  describe "instance_from_result method" do
5
47
  before :each do
6
48
  Person.stub_method(:find => true)
@@ -24,6 +24,7 @@ describe ThinkingSphinx do
24
24
  end
25
25
 
26
26
  it "should index deltas by default" do
27
+ ThinkingSphinx.deltas_enabled = nil
27
28
  ThinkingSphinx.deltas_enabled?.should be_true
28
29
  end
29
30
 
@@ -104,4 +105,4 @@ describe ThinkingSphinx do
104
105
  end
105
106
  end
106
107
  end
107
- end
108
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freelancing-god-thinking-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-05 00:00:00 -07:00
12
+ date: 2008-07-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  requirements: []
71
71
 
72
72
  rubyforge_project: thinking-sphinx
73
- rubygems_version: 1.0.1
73
+ rubygems_version: 1.2.0
74
74
  signing_key:
75
75
  specification_version: 2
76
76
  summary: A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching.