skalee-thinking-sphinx 1.3.14.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENCE +20 -0
- data/README.textile +201 -0
- data/Rakefile +3 -0
- data/VERSION +1 -0
- data/contribute.rb +385 -0
- data/cucumber.yml +1 -0
- data/features/abstract_inheritance.feature +10 -0
- data/features/alternate_primary_key.feature +27 -0
- data/features/attribute_transformation.feature +22 -0
- data/features/attribute_updates.feature +51 -0
- data/features/deleting_instances.feature +67 -0
- data/features/direct_attributes.feature +11 -0
- data/features/excerpts.feature +13 -0
- data/features/extensible_delta_indexing.feature +9 -0
- data/features/facets.feature +82 -0
- data/features/facets_across_model.feature +29 -0
- data/features/handling_edits.feature +92 -0
- data/features/retry_stale_indexes.feature +24 -0
- data/features/searching_across_models.feature +20 -0
- data/features/searching_by_index.feature +40 -0
- data/features/searching_by_model.feature +175 -0
- data/features/searching_with_find_arguments.feature +56 -0
- data/features/sphinx_detection.feature +25 -0
- data/features/sphinx_scopes.feature +42 -0
- data/features/step_definitions/alpha_steps.rb +16 -0
- data/features/step_definitions/beta_steps.rb +7 -0
- data/features/step_definitions/common_steps.rb +188 -0
- data/features/step_definitions/extensible_delta_indexing_steps.rb +7 -0
- data/features/step_definitions/facet_steps.rb +96 -0
- data/features/step_definitions/find_arguments_steps.rb +36 -0
- data/features/step_definitions/gamma_steps.rb +15 -0
- data/features/step_definitions/scope_steps.rb +15 -0
- data/features/step_definitions/search_steps.rb +89 -0
- data/features/step_definitions/sphinx_steps.rb +35 -0
- data/features/sti_searching.feature +19 -0
- data/features/support/database.example.yml +3 -0
- data/features/support/db/.gitignore +1 -0
- data/features/support/db/fixtures/alphas.rb +10 -0
- data/features/support/db/fixtures/authors.rb +1 -0
- data/features/support/db/fixtures/betas.rb +10 -0
- data/features/support/db/fixtures/boxes.rb +9 -0
- data/features/support/db/fixtures/categories.rb +1 -0
- data/features/support/db/fixtures/cats.rb +3 -0
- data/features/support/db/fixtures/comments.rb +24 -0
- data/features/support/db/fixtures/developers.rb +29 -0
- data/features/support/db/fixtures/dogs.rb +3 -0
- data/features/support/db/fixtures/extensible_betas.rb +10 -0
- data/features/support/db/fixtures/foxes.rb +3 -0
- data/features/support/db/fixtures/gammas.rb +10 -0
- data/features/support/db/fixtures/music.rb +4 -0
- data/features/support/db/fixtures/people.rb +1001 -0
- data/features/support/db/fixtures/posts.rb +6 -0
- data/features/support/db/fixtures/robots.rb +14 -0
- data/features/support/db/fixtures/tags.rb +27 -0
- data/features/support/db/migrations/create_alphas.rb +8 -0
- data/features/support/db/migrations/create_animals.rb +5 -0
- data/features/support/db/migrations/create_authors.rb +3 -0
- data/features/support/db/migrations/create_authors_posts.rb +6 -0
- data/features/support/db/migrations/create_betas.rb +5 -0
- data/features/support/db/migrations/create_boxes.rb +5 -0
- data/features/support/db/migrations/create_categories.rb +3 -0
- data/features/support/db/migrations/create_comments.rb +10 -0
- data/features/support/db/migrations/create_developers.rb +9 -0
- data/features/support/db/migrations/create_extensible_betas.rb +5 -0
- data/features/support/db/migrations/create_gammas.rb +3 -0
- data/features/support/db/migrations/create_genres.rb +3 -0
- data/features/support/db/migrations/create_music.rb +6 -0
- data/features/support/db/migrations/create_people.rb +13 -0
- data/features/support/db/migrations/create_posts.rb +5 -0
- data/features/support/db/migrations/create_robots.rb +4 -0
- data/features/support/db/migrations/create_taggings.rb +5 -0
- data/features/support/db/migrations/create_tags.rb +4 -0
- data/features/support/env.rb +21 -0
- data/features/support/lib/generic_delta_handler.rb +8 -0
- data/features/support/models/alpha.rb +22 -0
- data/features/support/models/animal.rb +5 -0
- data/features/support/models/author.rb +3 -0
- data/features/support/models/beta.rb +8 -0
- data/features/support/models/box.rb +8 -0
- data/features/support/models/cat.rb +3 -0
- data/features/support/models/category.rb +4 -0
- data/features/support/models/comment.rb +10 -0
- data/features/support/models/developer.rb +16 -0
- data/features/support/models/dog.rb +3 -0
- data/features/support/models/extensible_beta.rb +9 -0
- data/features/support/models/fox.rb +5 -0
- data/features/support/models/gamma.rb +5 -0
- data/features/support/models/genre.rb +3 -0
- data/features/support/models/medium.rb +5 -0
- data/features/support/models/music.rb +8 -0
- data/features/support/models/person.rb +23 -0
- data/features/support/models/post.rb +21 -0
- data/features/support/models/robot.rb +12 -0
- data/features/support/models/tag.rb +3 -0
- data/features/support/models/tagging.rb +4 -0
- data/ginger_scenarios.rb +28 -0
- data/init.rb +5 -0
- data/install.rb +5 -0
- data/lib/cucumber/thinking_sphinx/external_world.rb +8 -0
- data/lib/cucumber/thinking_sphinx/internal_world.rb +126 -0
- data/lib/cucumber/thinking_sphinx/sql_logger.rb +20 -0
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +19 -0
- data/lib/thinking_sphinx/active_record/delta.rb +47 -0
- data/lib/thinking_sphinx/active_record/has_many_association.rb +29 -0
- data/lib/thinking_sphinx/active_record/scopes.rb +75 -0
- data/lib/thinking_sphinx/active_record.rb +348 -0
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +143 -0
- data/lib/thinking_sphinx/association.rb +164 -0
- data/lib/thinking_sphinx/attribute.rb +362 -0
- data/lib/thinking_sphinx/auto_version.rb +22 -0
- data/lib/thinking_sphinx/class_facet.rb +15 -0
- data/lib/thinking_sphinx/configuration.rb +300 -0
- data/lib/thinking_sphinx/context.rb +68 -0
- data/lib/thinking_sphinx/core/array.rb +7 -0
- data/lib/thinking_sphinx/core/string.rb +15 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +62 -0
- data/lib/thinking_sphinx/deltas.rb +28 -0
- data/lib/thinking_sphinx/deploy/capistrano.rb +100 -0
- data/lib/thinking_sphinx/excerpter.rb +22 -0
- data/lib/thinking_sphinx/facet.rb +125 -0
- data/lib/thinking_sphinx/facet_search.rb +136 -0
- data/lib/thinking_sphinx/field.rb +82 -0
- data/lib/thinking_sphinx/index/builder.rb +296 -0
- data/lib/thinking_sphinx/index/faux_column.rb +110 -0
- data/lib/thinking_sphinx/index.rb +157 -0
- data/lib/thinking_sphinx/property.rb +162 -0
- data/lib/thinking_sphinx/rails_additions.rb +150 -0
- data/lib/thinking_sphinx/search.rb +769 -0
- data/lib/thinking_sphinx/search_methods.rb +439 -0
- data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
- data/lib/thinking_sphinx/source/sql.rb +130 -0
- data/lib/thinking_sphinx/source.rb +153 -0
- data/lib/thinking_sphinx/tasks.rb +131 -0
- data/lib/thinking_sphinx/test.rb +52 -0
- data/lib/thinking_sphinx.rb +225 -0
- data/rails/init.rb +16 -0
- data/recipes/thinking_sphinx.rb +3 -0
- data/spec/fixtures/data.sql +32 -0
- data/spec/fixtures/database.yml.default +3 -0
- data/spec/fixtures/models.rb +145 -0
- data/spec/fixtures/structure.sql +125 -0
- data/spec/spec_helper.rb +60 -0
- data/spec/sphinx_helper.rb +81 -0
- data/spec/thinking_sphinx/active_record/delta_spec.rb +128 -0
- data/spec/thinking_sphinx/active_record/has_many_association_spec.rb +55 -0
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +177 -0
- data/spec/thinking_sphinx/active_record_spec.rb +622 -0
- data/spec/thinking_sphinx/association_spec.rb +239 -0
- data/spec/thinking_sphinx/attribute_spec.rb +570 -0
- data/spec/thinking_sphinx/auto_version_spec.rb +39 -0
- data/spec/thinking_sphinx/configuration_spec.rb +234 -0
- data/spec/thinking_sphinx/context_spec.rb +119 -0
- data/spec/thinking_sphinx/core/array_spec.rb +9 -0
- data/spec/thinking_sphinx/core/string_spec.rb +9 -0
- data/spec/thinking_sphinx/excerpter_spec.rb +57 -0
- data/spec/thinking_sphinx/facet_search_spec.rb +176 -0
- data/spec/thinking_sphinx/facet_spec.rb +333 -0
- data/spec/thinking_sphinx/field_spec.rb +154 -0
- data/spec/thinking_sphinx/index/builder_spec.rb +479 -0
- data/spec/thinking_sphinx/index/faux_column_spec.rb +30 -0
- data/spec/thinking_sphinx/index_spec.rb +183 -0
- data/spec/thinking_sphinx/rails_additions_spec.rb +203 -0
- data/spec/thinking_sphinx/search_methods_spec.rb +152 -0
- data/spec/thinking_sphinx/search_spec.rb +1181 -0
- data/spec/thinking_sphinx/source_spec.rb +235 -0
- data/spec/thinking_sphinx_spec.rb +204 -0
- data/tasks/distribution.rb +41 -0
- data/tasks/rails.rake +1 -0
- data/tasks/testing.rb +72 -0
- data/vendor/after_commit/.gitignore +1 -0
- data/vendor/after_commit/lib/after_commit/active_record.rb +122 -0
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +168 -0
- data/vendor/after_commit/lib/after_commit/test_bypass.rb +30 -0
- data/vendor/after_commit/lib/after_commit.rb +70 -0
- data/vendor/riddle/lib/riddle/0.9.8.rb +1 -0
- data/vendor/riddle/lib/riddle/0.9.9/client/filter.rb +22 -0
- data/vendor/riddle/lib/riddle/0.9.9/client.rb +49 -0
- data/vendor/riddle/lib/riddle/0.9.9/configuration/searchd.rb +28 -0
- data/vendor/riddle/lib/riddle/0.9.9.rb +7 -0
- data/vendor/riddle/lib/riddle/auto_version.rb +11 -0
- data/vendor/riddle/lib/riddle/client/filter.rb +62 -0
- data/vendor/riddle/lib/riddle/client/message.rb +70 -0
- data/vendor/riddle/lib/riddle/client/response.rb +94 -0
- data/vendor/riddle/lib/riddle/client.rb +745 -0
- data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +49 -0
- data/vendor/riddle/lib/riddle/configuration/index.rb +149 -0
- data/vendor/riddle/lib/riddle/configuration/indexer.rb +20 -0
- data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
- data/vendor/riddle/lib/riddle/configuration/searchd.rb +28 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +43 -0
- data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
- data/vendor/riddle/lib/riddle/configuration/sql_source.rb +53 -0
- data/vendor/riddle/lib/riddle/configuration/xml_source.rb +29 -0
- data/vendor/riddle/lib/riddle/configuration.rb +33 -0
- data/vendor/riddle/lib/riddle/controller.rb +78 -0
- data/vendor/riddle/lib/riddle.rb +51 -0
- metadata +312 -0
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::ActiveRecord::Scopes do
|
4
|
+
after :each do
|
5
|
+
Alpha.remove_sphinx_scopes
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be included into models with indexes" do
|
9
|
+
Alpha.included_modules.should include(ThinkingSphinx::ActiveRecord::Scopes)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not be included into models without indexes" do
|
13
|
+
Gamma.included_modules.should_not include(
|
14
|
+
ThinkingSphinx::ActiveRecord::Scopes
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.sphinx_scope' do
|
19
|
+
before :each do
|
20
|
+
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should define a method on the model" do
|
24
|
+
Alpha.should respond_to(:by_name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.sphinx_scopes' do
|
29
|
+
before :each do
|
30
|
+
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return an array of defined scope names as symbols" do
|
34
|
+
Alpha.sphinx_scopes.should == [:by_name]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.default_sphinx_scope' do
|
39
|
+
before :each do
|
40
|
+
Alpha.sphinx_scope(:scope_used_as_default_scope) { {:conditions => {:name => 'name'}} }
|
41
|
+
Alpha.default_sphinx_scope :scope_used_as_default_scope
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return an array of defined scope names as symbols" do
|
45
|
+
Alpha.sphinx_scopes.should == [:scope_used_as_default_scope]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have a default_sphinx_scope" do
|
49
|
+
Alpha.has_default_sphinx_scope?.should be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.remove_sphinx_scopes' do
|
54
|
+
before :each do
|
55
|
+
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
56
|
+
Alpha.remove_sphinx_scopes
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should remove sphinx scope methods" do
|
60
|
+
Alpha.should_not respond_to(:by_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should empty the list of sphinx scopes" do
|
64
|
+
Alpha.sphinx_scopes.should be_empty
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '.example_default_scope' do
|
69
|
+
before :each do
|
70
|
+
Alpha.sphinx_scope(:foo_scope){ {:conditions => {:name => 'foo'}} }
|
71
|
+
Alpha.default_sphinx_scope :foo_scope
|
72
|
+
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
73
|
+
Alpha.sphinx_scope(:by_foo) { |foo| {:conditions => {:foo => foo}} }
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should return a ThinkingSphinx::Search object" do
|
77
|
+
Alpha.search.should be_a(ThinkingSphinx::Search)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should apply the default scope options to the underlying search object" do
|
81
|
+
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
82
|
+
search.search.options[:conditions].should == {:name => 'foo'}
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should apply the default scope options and scope options to the underlying search object" do
|
86
|
+
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
87
|
+
search.by_foo('foo').search.options[:conditions].should == {:foo => 'foo', :name => 'foo'}
|
88
|
+
end
|
89
|
+
|
90
|
+
# FIXME: Probably the other way around is more logical? How to do this?
|
91
|
+
it "should apply the default scope options after other scope options to the underlying search object" do
|
92
|
+
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
93
|
+
search.by_name('bar').search.options[:conditions].should == {:name => 'foo'}
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '.example_scope' do
|
98
|
+
before :each do
|
99
|
+
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
100
|
+
Alpha.sphinx_scope(:by_foo) { |foo| {:conditions => {:foo => foo}} }
|
101
|
+
Alpha.sphinx_scope(:with_betas) { {:classes => [Beta]} }
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should return a ThinkingSphinx::Search object" do
|
105
|
+
Alpha.by_name('foo').should be_a(ThinkingSphinx::Search)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should set the classes option" do
|
109
|
+
Alpha.by_name('foo').options[:classes].should == [Alpha]
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should be able to be called on a ThinkingSphinx::Search object" do
|
113
|
+
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
114
|
+
lambda {
|
115
|
+
search.by_name('foo')
|
116
|
+
}.should_not raise_error
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return the search object it gets called upon" do
|
120
|
+
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
121
|
+
search.by_name('foo').should == search
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should apply the scope options to the underlying search object" do
|
125
|
+
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
126
|
+
search.by_name('foo').options[:conditions].should == {:name => 'foo'}
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should combine hash option scopes such as :conditions" do
|
130
|
+
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
131
|
+
search.by_name('foo').by_foo('bar').options[:conditions].
|
132
|
+
should == {:name => 'foo', :foo => 'bar'}
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should combine array option scopes such as :classes" do
|
136
|
+
search = ThinkingSphinx::Search.new(:classes => [Alpha])
|
137
|
+
search.with_betas.options[:classes].should == [Alpha, Beta]
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '.search_count_with_scope' do
|
142
|
+
before :each do
|
143
|
+
@config = ThinkingSphinx::Configuration.instance
|
144
|
+
@client = Riddle::Client.new
|
145
|
+
|
146
|
+
@config.stub!(:client => @client)
|
147
|
+
@client.stub!(:query => {:matches => [], :total_found => 43})
|
148
|
+
Alpha.sphinx_scope(:by_name) { |name| {:conditions => {:name => name}} }
|
149
|
+
Alpha.sphinx_scope(:ids_only) { {:ids_only => true} }
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should return the total number of results" do
|
153
|
+
Alpha.by_name('foo').search_count.should == 43
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should not make any calls to the database" do
|
157
|
+
Alpha.should_not_receive(:find)
|
158
|
+
|
159
|
+
Alpha.by_name('foo').search_count
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should not leave the :ids_only option set and the results populated if it was not set before" do
|
163
|
+
stored_scope = Alpha.by_name('foo')
|
164
|
+
stored_scope.search_count
|
165
|
+
stored_scope.options[:ids_only].should be_false
|
166
|
+
stored_scope.populated?.should be_false
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should leave the :ids_only option set and the results populated if it was set before" do
|
170
|
+
stored_scope = Alpha.by_name('foo').ids_only
|
171
|
+
stored_scope.search_count
|
172
|
+
stored_scope.options[:ids_only].should be_true
|
173
|
+
stored_scope.populated?.should be_true
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
end
|