thinking-sphinx 1.5.0 → 2.0.0.rc1
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.
- data/README.textile +15 -48
- data/VERSION +1 -0
- data/features/attribute_transformation.feature +7 -7
- data/features/attribute_updates.feature +16 -18
- data/features/deleting_instances.feature +13 -16
- data/features/excerpts.feature +0 -8
- data/features/facets.feature +19 -25
- data/features/handling_edits.feature +20 -25
- data/features/searching_across_models.feature +1 -1
- data/features/searching_by_index.feature +5 -6
- data/features/searching_by_model.feature +29 -29
- data/features/sphinx_scopes.feature +0 -26
- data/features/step_definitions/common_steps.rb +6 -18
- data/features/step_definitions/scope_steps.rb +0 -4
- data/features/step_definitions/search_steps.rb +4 -9
- data/features/support/env.rb +10 -3
- data/features/thinking_sphinx/db/fixtures/alphas.rb +10 -8
- data/features/thinking_sphinx/db/fixtures/cats.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/dogs.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/foxes.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/people.rb +1 -1
- data/features/thinking_sphinx/db/fixtures/posts.rb +1 -5
- data/features/thinking_sphinx/db/migrations/create_posts.rb +0 -1
- data/features/thinking_sphinx/models/alpha.rb +0 -1
- data/features/thinking_sphinx/models/beta.rb +0 -5
- data/features/thinking_sphinx/models/developer.rb +1 -6
- data/features/thinking_sphinx/models/music.rb +1 -3
- data/features/thinking_sphinx/models/person.rb +1 -2
- data/features/thinking_sphinx/models/post.rb +0 -1
- data/lib/cucumber/thinking_sphinx/external_world.rb +4 -8
- data/lib/cucumber/thinking_sphinx/internal_world.rb +27 -36
- data/lib/thinking_sphinx.rb +60 -132
- data/lib/thinking_sphinx/active_record.rb +98 -124
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +13 -17
- data/lib/thinking_sphinx/active_record/delta.rb +15 -21
- data/lib/thinking_sphinx/active_record/has_many_association.rb +23 -16
- data/lib/thinking_sphinx/active_record/scopes.rb +0 -18
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +15 -63
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +0 -4
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +24 -65
- data/lib/thinking_sphinx/association.rb +11 -36
- data/lib/thinking_sphinx/attribute.rb +85 -92
- data/lib/thinking_sphinx/auto_version.rb +3 -21
- data/lib/thinking_sphinx/class_facet.rb +3 -8
- data/lib/thinking_sphinx/configuration.rb +58 -114
- data/lib/thinking_sphinx/context.rb +20 -22
- data/lib/thinking_sphinx/core/array.rb +13 -0
- data/lib/thinking_sphinx/deltas.rb +0 -2
- data/lib/thinking_sphinx/deltas/default_delta.rb +22 -18
- data/lib/thinking_sphinx/deploy/capistrano.rb +31 -30
- data/lib/thinking_sphinx/excerpter.rb +1 -2
- data/lib/thinking_sphinx/facet.rb +35 -45
- data/lib/thinking_sphinx/facet_search.rb +24 -58
- data/lib/thinking_sphinx/field.rb +0 -18
- data/lib/thinking_sphinx/index.rb +36 -38
- data/lib/thinking_sphinx/index/builder.rb +59 -74
- data/lib/thinking_sphinx/property.rb +45 -66
- data/lib/thinking_sphinx/railtie.rb +35 -0
- data/lib/thinking_sphinx/search.rb +250 -506
- data/lib/thinking_sphinx/source.rb +31 -50
- data/lib/thinking_sphinx/source/internal_properties.rb +3 -8
- data/lib/thinking_sphinx/source/sql.rb +31 -71
- data/lib/thinking_sphinx/tasks.rb +27 -48
- data/spec/thinking_sphinx/active_record/delta_spec.rb +41 -36
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +0 -96
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +29 -29
- data/spec/thinking_sphinx/active_record_spec.rb +169 -140
- data/spec/thinking_sphinx/association_spec.rb +2 -20
- data/spec/thinking_sphinx/attribute_spec.rb +97 -101
- data/spec/thinking_sphinx/auto_version_spec.rb +11 -75
- data/spec/thinking_sphinx/configuration_spec.rb +62 -63
- data/spec/thinking_sphinx/context_spec.rb +66 -66
- data/spec/thinking_sphinx/facet_search_spec.rb +99 -99
- data/spec/thinking_sphinx/facet_spec.rb +4 -30
- data/spec/thinking_sphinx/field_spec.rb +3 -17
- data/spec/thinking_sphinx/index/builder_spec.rb +132 -169
- data/spec/thinking_sphinx/index_spec.rb +39 -45
- data/spec/thinking_sphinx/search_methods_spec.rb +33 -37
- data/spec/thinking_sphinx/search_spec.rb +269 -491
- data/spec/thinking_sphinx/source_spec.rb +48 -62
- data/spec/thinking_sphinx_spec.rb +49 -49
- data/tasks/distribution.rb +46 -0
- data/tasks/testing.rb +74 -0
- metadata +123 -199
- data/features/field_sorting.feature +0 -18
- data/features/thinking_sphinx/db/.gitignore +0 -1
- data/features/thinking_sphinx/db/fixtures/post_keywords.txt +0 -1
- data/features/thinking_sphinx/models/andrew.rb +0 -17
- data/lib/thinking-sphinx.rb +0 -1
- data/lib/thinking_sphinx/active_record/has_many_association_with_scopes.rb +0 -21
- data/lib/thinking_sphinx/bundled_search.rb +0 -40
- data/lib/thinking_sphinx/connection.rb +0 -71
- data/lib/thinking_sphinx/deltas/delete_job.rb +0 -16
- data/lib/thinking_sphinx/deltas/index_job.rb +0 -17
- data/lib/thinking_sphinx/rails_additions.rb +0 -181
- data/spec/fixtures/data.sql +0 -32
- data/spec/fixtures/database.yml.default +0 -3
- data/spec/fixtures/models.rb +0 -161
- data/spec/fixtures/structure.sql +0 -146
- data/spec/spec_helper.rb +0 -54
- data/spec/sphinx_helper.rb +0 -67
- data/spec/thinking_sphinx/adapters/abstract_adapter_spec.rb +0 -163
- data/spec/thinking_sphinx/connection_spec.rb +0 -77
- data/spec/thinking_sphinx/rails_additions_spec.rb +0 -203
|
@@ -44,30 +44,12 @@ describe ThinkingSphinx::Association do
|
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
it "should generate non-polymorphic 'casted' associations for each polymorphic possibility" do
|
|
47
|
-
Person.stub!(:reflect_on_association)
|
|
48
|
-
and_return(@poly_reflection, nil, nil)
|
|
47
|
+
Person.stub!(:reflect_on_association => @poly_reflection)
|
|
49
48
|
ThinkingSphinx::Association.should_receive(:casted_options).with(
|
|
50
49
|
Person, @poly_reflection
|
|
51
50
|
).twice
|
|
52
51
|
::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
|
|
53
|
-
with(:has_many, :polly_Person, {:casted => :options}, "AR").twice
|
|
54
|
-
and_return(@non_poly_reflection)
|
|
55
|
-
ThinkingSphinx::Association.should_receive(:new).with(
|
|
56
|
-
nil, @non_poly_reflection
|
|
57
|
-
).twice
|
|
58
|
-
|
|
59
|
-
ThinkingSphinx::Association.children(Person, :assoc)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "should use existing non-polymorphic 'casted' associations" do
|
|
63
|
-
Person.stub!(:reflect_on_association).exactly(3).times.
|
|
64
|
-
and_return(@poly_reflection, nil, @non_poly_reflection)
|
|
65
|
-
ThinkingSphinx::Association.should_receive(:casted_options).with(
|
|
66
|
-
Person, @poly_reflection
|
|
67
|
-
).once
|
|
68
|
-
::ActiveRecord::Reflection::AssociationReflection.should_receive(:new).
|
|
69
|
-
with(:has_many, :polly_Person, {:casted => :options}, "AR").once.
|
|
70
|
-
and_return(@non_poly_reflection)
|
|
52
|
+
with(:has_many, :polly_Person, {:casted => :options}, "AR").twice
|
|
71
53
|
ThinkingSphinx::Association.should_receive(:new).with(
|
|
72
54
|
nil, @non_poly_reflection
|
|
73
55
|
).twice
|
|
@@ -68,22 +68,13 @@ describe ThinkingSphinx::Attribute do
|
|
|
68
68
|
|
|
69
69
|
attribute.to_select_sql.should == "CONCAT_WS(' ', IFNULL(`cricket_teams`.`name`, ''), IFNULL(`football_teams`.`name`, ''), IFNULL(`football_teams`.`league`, '')) AS `team`"
|
|
70
70
|
end
|
|
71
|
-
|
|
72
|
-
it "should return nil if polymorphic association data does not exist" do
|
|
73
|
-
attribute = ThinkingSphinx::Attribute.new(@source,
|
|
74
|
-
[ThinkingSphinx::Index::FauxColumn.new(:source, :id)],
|
|
75
|
-
:as => :source_id, :type => :integer
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
attribute.to_select_sql.should be_nil
|
|
79
|
-
end
|
|
80
71
|
end
|
|
81
72
|
|
|
82
73
|
describe '#is_many?' do
|
|
83
74
|
before :each do
|
|
84
|
-
@assoc_a =
|
|
85
|
-
@assoc_b =
|
|
86
|
-
@assoc_c =
|
|
75
|
+
@assoc_a = stub('assoc', :is_many? => true)
|
|
76
|
+
@assoc_b = stub('assoc', :is_many? => true)
|
|
77
|
+
@assoc_c = stub('assoc', :is_many? => true)
|
|
87
78
|
|
|
88
79
|
@attribute = ThinkingSphinx::Attribute.new(
|
|
89
80
|
@source, [ThinkingSphinx::Index::FauxColumn.new(:col_name)]
|
|
@@ -91,9 +82,6 @@ describe ThinkingSphinx::Attribute do
|
|
|
91
82
|
@attribute.associations = {
|
|
92
83
|
:a => @assoc_a, :b => @assoc_b, :c => @assoc_c
|
|
93
84
|
}
|
|
94
|
-
@attribute.associations.values.each { |assoc|
|
|
95
|
-
assoc.stub!(:is_many? => true)
|
|
96
|
-
}
|
|
97
85
|
end
|
|
98
86
|
|
|
99
87
|
it "should return true if all associations return true to is_many?" do
|
|
@@ -298,176 +286,184 @@ describe ThinkingSphinx::Attribute do
|
|
|
298
286
|
end
|
|
299
287
|
|
|
300
288
|
describe "MVA with source query" do
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
289
|
+
before :each do
|
|
290
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
291
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
|
292
|
+
:as => :tag_ids, :source => :query
|
|
293
|
+
)
|
|
294
|
+
end
|
|
306
295
|
|
|
307
296
|
it "should use a query" do
|
|
308
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
297
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
309
298
|
|
|
310
|
-
declaration, query = attribute.config_value.split('; ')
|
|
299
|
+
declaration, query = @attribute.config_value.split('; ')
|
|
311
300
|
declaration.should == "uint tag_ids from query"
|
|
312
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression
|
|
301
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags`"
|
|
313
302
|
end
|
|
314
303
|
end
|
|
315
304
|
|
|
316
305
|
describe "MVA with source query for a delta source" do
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
306
|
+
before :each do
|
|
307
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
308
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
|
309
|
+
:as => :tag_ids, :source => :query
|
|
310
|
+
)
|
|
311
|
+
end
|
|
322
312
|
|
|
323
313
|
it "should use a query" do
|
|
324
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
314
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
325
315
|
|
|
326
|
-
declaration, query = attribute.config_value(nil, true).split('; ')
|
|
316
|
+
declaration, query = @attribute.config_value(nil, true).split('; ')
|
|
327
317
|
declaration.should == "uint tag_ids from query"
|
|
328
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression
|
|
318
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
|
|
329
319
|
end
|
|
330
320
|
end
|
|
331
321
|
|
|
332
322
|
describe "MVA via a HABTM association with a source query" do
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
323
|
+
before :each do
|
|
324
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
325
|
+
[ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
|
|
326
|
+
:as => :link_ids, :source => :query
|
|
327
|
+
)
|
|
328
|
+
end
|
|
338
329
|
|
|
339
330
|
it "should use a ranged query" do
|
|
340
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
331
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
341
332
|
|
|
342
|
-
declaration, query = attribute.config_value.split('; ')
|
|
333
|
+
declaration, query = @attribute.config_value.split('; ')
|
|
343
334
|
declaration.should == "uint link_ids from query"
|
|
344
|
-
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression
|
|
335
|
+
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people`"
|
|
345
336
|
end
|
|
346
337
|
end
|
|
347
338
|
|
|
348
339
|
describe "MVA with ranged source query" do
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
340
|
+
before :each do
|
|
341
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
342
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
|
343
|
+
:as => :tag_ids, :source => :ranged_query
|
|
344
|
+
)
|
|
345
|
+
end
|
|
354
346
|
|
|
355
347
|
it "should use a ranged query" do
|
|
356
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
348
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
357
349
|
|
|
358
|
-
declaration, query, range_query = attribute.config_value.split('; ')
|
|
350
|
+
declaration, query, range_query = @attribute.config_value.split('; ')
|
|
359
351
|
declaration.should == "uint tag_ids from ranged-query"
|
|
360
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression
|
|
352
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
|
|
361
353
|
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
|
362
354
|
end
|
|
363
355
|
end
|
|
364
356
|
|
|
365
357
|
describe "MVA with ranged source query for a delta source" do
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
358
|
+
before :each do
|
|
359
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
360
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
|
361
|
+
:as => :tag_ids, :source => :ranged_query
|
|
362
|
+
)
|
|
363
|
+
end
|
|
371
364
|
|
|
372
365
|
it "should use a ranged query" do
|
|
373
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
366
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
374
367
|
|
|
375
|
-
declaration, query, range_query = attribute.config_value(nil, true).split('; ')
|
|
368
|
+
declaration, query, range_query = @attribute.config_value(nil, true).split('; ')
|
|
376
369
|
declaration.should == "uint tag_ids from ranged-query"
|
|
377
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression
|
|
370
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end AND `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
|
|
378
371
|
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
|
379
372
|
end
|
|
380
373
|
end
|
|
381
374
|
|
|
382
375
|
describe "MVA via a has-many :through with a ranged source query" do
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
376
|
+
before :each do
|
|
377
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
378
|
+
[ThinkingSphinx::Index::FauxColumn.new(:football_teams, :id)],
|
|
379
|
+
:as => :football_team_ids, :source => :ranged_query
|
|
380
|
+
)
|
|
381
|
+
end
|
|
388
382
|
|
|
389
383
|
it "should use a ranged query" do
|
|
390
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
384
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
391
385
|
|
|
392
|
-
declaration, query, range_query = attribute.config_value.split('; ')
|
|
386
|
+
declaration, query, range_query = @attribute.config_value.split('; ')
|
|
393
387
|
declaration.should == "uint football_team_ids from ranged-query"
|
|
394
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression
|
|
388
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`football_team_id` AS `football_team_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
|
|
395
389
|
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
|
396
390
|
end
|
|
397
391
|
end
|
|
398
392
|
|
|
399
393
|
describe "MVA via a has-many :through using a foreign key with a ranged source query" do
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
394
|
+
before :each do
|
|
395
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
396
|
+
[ThinkingSphinx::Index::FauxColumn.new(:friends, :id)],
|
|
397
|
+
:as => :friend_ids, :source => :ranged_query
|
|
398
|
+
)
|
|
399
|
+
end
|
|
405
400
|
|
|
406
401
|
it "should use a ranged query" do
|
|
407
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
402
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
408
403
|
|
|
409
|
-
declaration, query, range_query = attribute.config_value.split('; ')
|
|
404
|
+
declaration, query, range_query = @attribute.config_value.split('; ')
|
|
410
405
|
declaration.should == "uint friend_ids from ranged-query"
|
|
411
|
-
query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression
|
|
406
|
+
query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `friendships`.`friend_id` AS `friend_ids` FROM `friendships` WHERE `friendships`.`person_id` >= $start AND `friendships`.`person_id` <= $end"
|
|
412
407
|
range_query.should == "SELECT MIN(`friendships`.`person_id`), MAX(`friendships`.`person_id`) FROM `friendships`"
|
|
413
408
|
end
|
|
414
409
|
end
|
|
415
410
|
|
|
416
411
|
describe "MVA via a HABTM with a ranged source query" do
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
412
|
+
before :each do
|
|
413
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
414
|
+
[ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
|
|
415
|
+
:as => :link_ids, :source => :ranged_query
|
|
416
|
+
)
|
|
417
|
+
end
|
|
422
418
|
|
|
423
419
|
it "should use a ranged query" do
|
|
424
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
420
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
425
421
|
|
|
426
|
-
declaration, query, range_query = attribute.config_value.split('; ')
|
|
422
|
+
declaration, query, range_query = @attribute.config_value.split('; ')
|
|
427
423
|
declaration.should == "uint link_ids from ranged-query"
|
|
428
|
-
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression
|
|
424
|
+
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people` WHERE `links_people`.`person_id` >= $start AND `links_people`.`person_id` <= $end"
|
|
429
425
|
range_query.should == "SELECT MIN(`links_people`.`person_id`), MAX(`links_people`.`person_id`) FROM `links_people`"
|
|
430
426
|
end
|
|
431
427
|
end
|
|
432
428
|
|
|
433
429
|
describe "MVA via two has-many associations with a ranged source query" do
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
430
|
+
before :each do
|
|
431
|
+
@index = ThinkingSphinx::Index.new(Alpha)
|
|
432
|
+
@source = ThinkingSphinx::Source.new(@index)
|
|
433
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
434
|
+
[ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
|
|
435
|
+
:as => :gamma_values, :source => :ranged_query
|
|
436
|
+
)
|
|
437
|
+
end
|
|
441
438
|
|
|
442
439
|
it "should use a ranged query" do
|
|
443
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
440
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
444
441
|
|
|
445
|
-
declaration, query, range_query = attribute.config_value.split('; ')
|
|
442
|
+
declaration, query, range_query = @attribute.config_value.split('; ')
|
|
446
443
|
declaration.should == "uint gamma_values from ranged-query"
|
|
447
|
-
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression
|
|
444
|
+
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON `gammas`.`beta_id` = `betas`.`id` WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end"
|
|
448
445
|
range_query.should == "SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`"
|
|
449
446
|
end
|
|
450
447
|
end
|
|
451
448
|
|
|
452
449
|
describe "MVA via two has-many associations with a ranged source query for a delta source" do
|
|
453
|
-
let(:index) { ThinkingSphinx::Index.new(Alpha) }
|
|
454
|
-
let(:source) { ThinkingSphinx::Source.new(index) }
|
|
455
|
-
let(:attribute) { ThinkingSphinx::Attribute.new(source,
|
|
456
|
-
[ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
|
|
457
|
-
:as => :gamma_values, :source => :ranged_query)
|
|
458
|
-
}
|
|
459
|
-
let(:adapter) { attribute.send(:adapter) }
|
|
460
|
-
|
|
461
450
|
before :each do
|
|
462
|
-
index
|
|
451
|
+
@index = ThinkingSphinx::Index.new(Alpha)
|
|
452
|
+
@source = ThinkingSphinx::Source.new(@index)
|
|
453
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
454
|
+
[ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
|
|
455
|
+
:as => :gamma_values, :source => :ranged_query
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
@index.delta_object = ThinkingSphinx::Deltas::DefaultDelta.new @index, @index.local_options
|
|
463
459
|
end
|
|
464
460
|
|
|
465
461
|
it "should use a ranged query" do
|
|
466
|
-
attribute.type_to_config.should == :sql_attr_multi
|
|
462
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
467
463
|
|
|
468
|
-
declaration, query, range_query = attribute.config_value(nil, true).split('; ')
|
|
464
|
+
declaration, query, range_query = @attribute.config_value(nil, true).split('; ')
|
|
469
465
|
declaration.should == "uint gamma_values from ranged-query"
|
|
470
|
-
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression
|
|
466
|
+
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON `gammas`.`beta_id` = `betas`.`id` WHERE `betas`.`alpha_id` >= $start AND `betas`.`alpha_id` <= $end AND `betas`.`alpha_id` IN (SELECT `id` FROM `alphas` WHERE `alphas`.`delta` = 1)"
|
|
471
467
|
range_query.should == "SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`"
|
|
472
468
|
end
|
|
473
469
|
end
|
|
@@ -5,97 +5,33 @@ describe ThinkingSphinx::AutoVersion do
|
|
|
5
5
|
before :each do
|
|
6
6
|
@config = ThinkingSphinx::Configuration.instance
|
|
7
7
|
end
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
it "should require 0.9.8 if that is the detected version" do
|
|
10
10
|
ThinkingSphinx::AutoVersion.should_receive(:require).
|
|
11
11
|
with('riddle/0.9.8')
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
@config.stub!(:version => '0.9.8')
|
|
14
14
|
ThinkingSphinx::AutoVersion.detect
|
|
15
15
|
end
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
it "should require 0.9.9 if that is the detected version" do
|
|
18
18
|
ThinkingSphinx::AutoVersion.should_receive(:require).
|
|
19
19
|
with('riddle/0.9.9')
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
@config.stub!(:version => '0.9.9')
|
|
22
22
|
ThinkingSphinx::AutoVersion.detect
|
|
23
23
|
end
|
|
24
|
-
|
|
25
|
-
it "should
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@config.stub!(:version => '1.10-beta')
|
|
30
|
-
ThinkingSphinx::AutoVersion.detect
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "should require 1.10-beta if using 1.10-beta compiled with id64 support" do
|
|
34
|
-
ThinkingSphinx::AutoVersion.should_receive(:require).
|
|
35
|
-
with('riddle/1.10')
|
|
36
|
-
|
|
37
|
-
@config.stub!(:version => '1.10-id64-beta')
|
|
38
|
-
ThinkingSphinx::AutoVersion.detect
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it "should require 2.0.1 if using Sphinx 2.0.1 beta" do
|
|
42
|
-
ThinkingSphinx::AutoVersion.should_receive(:require).
|
|
43
|
-
with('riddle/2.0.1')
|
|
44
|
-
|
|
45
|
-
@config.stub!(:version => '2.0.1-beta')
|
|
46
|
-
ThinkingSphinx::AutoVersion.detect
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "should require 2.0.1 if using Sphinx 2.0.2 dev" do
|
|
50
|
-
ThinkingSphinx::AutoVersion.should_receive(:require).
|
|
51
|
-
with('riddle/2.0.1')
|
|
52
|
-
|
|
53
|
-
@config.stub!(:version => '2.0.2-dev')
|
|
54
|
-
ThinkingSphinx::AutoVersion.detect
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
it "should require 2.1.0 if using Sphinx 2.0.3" do
|
|
58
|
-
ThinkingSphinx::AutoVersion.should_receive(:require).
|
|
59
|
-
with('riddle/2.1.0')
|
|
60
|
-
|
|
61
|
-
@config.stub!(:version => '2.0.3-release')
|
|
62
|
-
ThinkingSphinx::AutoVersion.detect
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "should require 2.1.0 if using Sphinx 2.0.3" do
|
|
66
|
-
ThinkingSphinx::AutoVersion.should_receive(:require).
|
|
67
|
-
with('riddle/2.1.0')
|
|
68
|
-
|
|
69
|
-
@config.stub!(:version => '2.0.4-release')
|
|
70
|
-
ThinkingSphinx::AutoVersion.detect
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it "should require 2.1.0 if using Sphinx 2.0.3" do
|
|
74
|
-
ThinkingSphinx::AutoVersion.should_receive(:require).
|
|
75
|
-
with('riddle/2.1.0')
|
|
76
|
-
|
|
77
|
-
@config.stub!(:version => '2.0.5-release')
|
|
78
|
-
ThinkingSphinx::AutoVersion.detect
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "should require 2.1.0 if using Sphinx 2.1.0 dev" do
|
|
82
|
-
ThinkingSphinx::AutoVersion.should_receive(:require).
|
|
83
|
-
with('riddle/2.1.0')
|
|
84
|
-
|
|
85
|
-
@config.stub!(:version => '2.1.0-dev')
|
|
86
|
-
ThinkingSphinx::AutoVersion.detect
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "should output a warning if the detected version is unsupported" do
|
|
90
|
-
STDERR.should_receive(:puts).with(/unsupported/i)
|
|
91
|
-
|
|
24
|
+
|
|
25
|
+
it "should output a warning if the detected version is something else" do
|
|
26
|
+
STDERR.should_receive(:puts)
|
|
27
|
+
|
|
92
28
|
@config.stub!(:version => '0.9.7')
|
|
93
29
|
ThinkingSphinx::AutoVersion.detect
|
|
94
30
|
end
|
|
95
|
-
|
|
31
|
+
|
|
96
32
|
it "should output a warning if the version cannot be determined" do
|
|
97
|
-
STDERR.should_receive(:puts)
|
|
98
|
-
|
|
33
|
+
STDERR.should_receive(:puts)
|
|
34
|
+
|
|
99
35
|
@config.stub!(:version => nil)
|
|
100
36
|
ThinkingSphinx::AutoVersion.detect
|
|
101
37
|
end
|
|
@@ -3,33 +3,22 @@ require 'spec_helper'
|
|
|
3
3
|
describe ThinkingSphinx::Configuration do
|
|
4
4
|
describe "environment class method" do
|
|
5
5
|
before :each do
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
Thread.current[:thinking_sphinx_environment] = nil
|
|
7
|
+
|
|
8
8
|
ENV["RAILS_ENV"] = nil
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
it "should use
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ThinkingSphinx::Configuration.stub!(:defined? => true)
|
|
17
|
-
Merb.stub!(:environment => "merb_production")
|
|
18
|
-
ThinkingSphinx::Configuration.environment.should == "merb_production"
|
|
19
|
-
|
|
20
|
-
Object.send :remove_const, :Merb
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "should use RAILS_ENV if set" do
|
|
24
|
-
RAILS_ENV = 'global_rails'
|
|
25
|
-
|
|
11
|
+
it "should use Rails.env if set" do
|
|
12
|
+
was = Rails.env
|
|
13
|
+
Rails.env = 'global_rails'
|
|
14
|
+
|
|
26
15
|
ThinkingSphinx::Configuration.environment.should == 'global_rails'
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
|
|
17
|
+
Rails.env = was
|
|
29
18
|
end
|
|
30
19
|
|
|
31
20
|
it "should use the Rails environment value if set" do
|
|
32
|
-
|
|
21
|
+
Rails.stub!(:env => "rails_production")
|
|
33
22
|
ThinkingSphinx::Configuration.environment.should == "rails_production"
|
|
34
23
|
end
|
|
35
24
|
|
|
@@ -37,31 +26,31 @@ describe ThinkingSphinx::Configuration do
|
|
|
37
26
|
ThinkingSphinx::Configuration.environment.should == "development"
|
|
38
27
|
end
|
|
39
28
|
end
|
|
40
|
-
|
|
29
|
+
|
|
41
30
|
describe '#version' do
|
|
42
31
|
before :each do
|
|
43
32
|
@config = ThinkingSphinx::Configuration.instance
|
|
44
33
|
@config.reset
|
|
45
34
|
end
|
|
46
|
-
|
|
35
|
+
|
|
47
36
|
it "should use the given version from sphinx.yml if there is one" do
|
|
48
|
-
open("#{
|
|
37
|
+
open("#{Rails.root}/config/sphinx.yml", "w") do |f|
|
|
49
38
|
f.write YAML.dump({'development' => {'version' => '0.9.7'}})
|
|
50
39
|
end
|
|
51
40
|
@config.reset
|
|
52
|
-
|
|
41
|
+
|
|
53
42
|
@config.version.should == '0.9.7'
|
|
54
|
-
|
|
55
|
-
FileUtils.rm "#{
|
|
43
|
+
|
|
44
|
+
FileUtils.rm "#{Rails.root}/config/sphinx.yml"
|
|
56
45
|
end
|
|
57
|
-
|
|
46
|
+
|
|
58
47
|
it "should detect the version from Riddle otherwise" do
|
|
59
48
|
controller = @config.controller
|
|
60
49
|
controller.stub!(:sphinx_version => '0.9.6')
|
|
61
|
-
|
|
50
|
+
|
|
62
51
|
Riddle::Controller.stub!(:new => controller)
|
|
63
52
|
@config.reset
|
|
64
|
-
|
|
53
|
+
|
|
65
54
|
@config.version.should == '0.9.6'
|
|
66
55
|
end
|
|
67
56
|
end
|
|
@@ -92,7 +81,7 @@ describe ThinkingSphinx::Configuration do
|
|
|
92
81
|
}
|
|
93
82
|
}
|
|
94
83
|
|
|
95
|
-
open("#{
|
|
84
|
+
open("#{Rails.root}/config/sphinx.yml", "w") do |f|
|
|
96
85
|
f.write YAML.dump(@settings)
|
|
97
86
|
end
|
|
98
87
|
end
|
|
@@ -108,7 +97,7 @@ describe ThinkingSphinx::Configuration do
|
|
|
108
97
|
end
|
|
109
98
|
|
|
110
99
|
after :each do
|
|
111
|
-
FileUtils.rm "#{
|
|
100
|
+
FileUtils.rm "#{Rails.root}/config/sphinx.yml"
|
|
112
101
|
end
|
|
113
102
|
end
|
|
114
103
|
|
|
@@ -118,8 +107,6 @@ describe ThinkingSphinx::Configuration do
|
|
|
118
107
|
config.app_root = "/here/somewhere"
|
|
119
108
|
end
|
|
120
109
|
ThinkingSphinx::Configuration.instance.app_root.should == "/here/somewhere"
|
|
121
|
-
|
|
122
|
-
ThinkingSphinx::Configuration.instance.reset
|
|
123
110
|
end
|
|
124
111
|
end
|
|
125
112
|
|
|
@@ -135,14 +122,14 @@ describe ThinkingSphinx::Configuration do
|
|
|
135
122
|
}
|
|
136
123
|
}
|
|
137
124
|
|
|
138
|
-
open("#{
|
|
125
|
+
open("#{Rails.root}/config/sphinx.yml", "w") do |f|
|
|
139
126
|
f.write YAML.dump(@settings)
|
|
140
127
|
end
|
|
141
128
|
|
|
142
129
|
ThinkingSphinx::Configuration.instance.send(:parse_config)
|
|
143
130
|
ThinkingSphinx::Configuration.instance.bin_path.should match(/\/$/)
|
|
144
131
|
|
|
145
|
-
FileUtils.rm "#{
|
|
132
|
+
FileUtils.rm "#{Rails.root}/config/sphinx.yml"
|
|
146
133
|
end
|
|
147
134
|
end
|
|
148
135
|
|
|
@@ -152,7 +139,7 @@ describe ThinkingSphinx::Configuration do
|
|
|
152
139
|
"development" => {"disable_range" => true}
|
|
153
140
|
}
|
|
154
141
|
|
|
155
|
-
open("#{
|
|
142
|
+
open("#{Rails.root}/config/sphinx.yml", "w") do |f|
|
|
156
143
|
f.write YAML.dump(@settings)
|
|
157
144
|
end
|
|
158
145
|
|
|
@@ -165,13 +152,13 @@ describe ThinkingSphinx::Configuration do
|
|
|
165
152
|
end
|
|
166
153
|
|
|
167
154
|
after :each do
|
|
168
|
-
FileUtils.rm "#{
|
|
155
|
+
FileUtils.rm "#{Rails.root}/config/sphinx.yml"
|
|
169
156
|
end
|
|
170
157
|
end
|
|
171
158
|
|
|
172
159
|
it "should insert set index options into the configuration file" do
|
|
173
160
|
config = ThinkingSphinx::Configuration.instance
|
|
174
|
-
|
|
161
|
+
|
|
175
162
|
ThinkingSphinx::Configuration::IndexOptions.each do |option|
|
|
176
163
|
config.reset
|
|
177
164
|
config.index_options[option.to_sym] = "something"
|
|
@@ -187,7 +174,7 @@ describe ThinkingSphinx::Configuration do
|
|
|
187
174
|
it "should insert set source options into the configuration file" do
|
|
188
175
|
config = ThinkingSphinx::Configuration.instance
|
|
189
176
|
config.reset
|
|
190
|
-
|
|
177
|
+
|
|
191
178
|
config.source_options[:sql_query_pre] = ["something"]
|
|
192
179
|
ThinkingSphinx::Configuration::SourceOptions.each do |option|
|
|
193
180
|
config.source_options[option.to_sym] ||= "something"
|
|
@@ -198,25 +185,27 @@ describe ThinkingSphinx::Configuration do
|
|
|
198
185
|
|
|
199
186
|
config.source_options.delete option.to_sym
|
|
200
187
|
end
|
|
201
|
-
|
|
202
|
-
config.source_options[:sql_query_pre] = nil
|
|
188
|
+
|
|
189
|
+
config.source_options[:sql_query_pre] = nil
|
|
203
190
|
end
|
|
204
|
-
|
|
191
|
+
|
|
205
192
|
it "should not blow away delta or utf options if sql pre is specified in config" do
|
|
206
193
|
config = ThinkingSphinx::Configuration.instance
|
|
207
194
|
config.reset
|
|
208
|
-
|
|
195
|
+
|
|
209
196
|
config.source_options[:sql_query_pre] = ["a pre query"]
|
|
210
197
|
config.build
|
|
211
198
|
file = open(config.config_file) { |f| f.read }
|
|
212
|
-
|
|
199
|
+
|
|
213
200
|
file.should match(/sql_query_pre = a pre query\n\s*sql_query_pre = UPDATE `\w+` SET `delta` = 0 WHERE `delta` = 1/im)
|
|
214
201
|
file.should match(/sql_query_pre = a pre query\n\s*sql_query_pre = \n/im)
|
|
215
|
-
|
|
202
|
+
|
|
216
203
|
config.source_options[:sql_query_pre] = nil
|
|
217
204
|
end
|
|
218
205
|
|
|
219
206
|
it "should set any explicit prefixed or infixed fields" do
|
|
207
|
+
ThinkingSphinx::Configuration.instance.build
|
|
208
|
+
|
|
220
209
|
file = open(ThinkingSphinx::Configuration.instance.config_file) { |f|
|
|
221
210
|
f.read
|
|
222
211
|
}
|
|
@@ -225,38 +214,48 @@ describe ThinkingSphinx::Configuration do
|
|
|
225
214
|
end
|
|
226
215
|
|
|
227
216
|
it "should not have prefix fields in indexes where nothing is set" do
|
|
217
|
+
ThinkingSphinx::Configuration.instance.build
|
|
218
|
+
|
|
228
219
|
file = open(ThinkingSphinx::Configuration.instance.config_file) { |f|
|
|
229
220
|
f.read
|
|
230
221
|
}
|
|
231
222
|
file.should_not match(/index alpha_core\s+\{\s+[^\}]*prefix_fields\s+=[^\}]*\}/m)
|
|
232
223
|
end
|
|
233
|
-
|
|
234
|
-
describe '#
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
config.
|
|
239
|
-
config.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
224
|
+
|
|
225
|
+
describe '#client' do
|
|
226
|
+
before :each do
|
|
227
|
+
@config = ThinkingSphinx::Configuration.instance
|
|
228
|
+
@config.address = 'domain.url'
|
|
229
|
+
@config.port = 3333
|
|
230
|
+
@config.configuration.searchd.max_matches = 100
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
it "should return an instance of Riddle::Client" do
|
|
234
|
+
@config.client.should be_a(Riddle::Client)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
it "should use the configuration address" do
|
|
238
|
+
@config.client.server.should == 'domain.url'
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
it "should use the configuration port" do
|
|
242
|
+
@config.client.port.should == 3333
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it "should use the configuration max matches" do
|
|
246
|
+
@config.client.max_matches.should == 100
|
|
248
247
|
end
|
|
249
248
|
end
|
|
250
|
-
|
|
249
|
+
|
|
251
250
|
describe '#models_by_crc' do
|
|
252
251
|
before :each do
|
|
253
252
|
@config = ThinkingSphinx::Configuration.instance
|
|
254
253
|
end
|
|
255
|
-
|
|
254
|
+
|
|
256
255
|
it "should return a hash" do
|
|
257
256
|
@config.models_by_crc.should be_a(Hash)
|
|
258
257
|
end
|
|
259
|
-
|
|
258
|
+
|
|
260
259
|
it "should pair class names to their crc codes" do
|
|
261
260
|
@config.models_by_crc[Person.to_crc32].should == 'Person'
|
|
262
261
|
@config.models_by_crc[Alpha.to_crc32].should == 'Alpha'
|