thinking-sphinx 1.3.4 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +15 -4
- data/VERSION +1 -0
- data/features/alternate_primary_key.feature +1 -1
- data/features/attribute_updates.feature +11 -5
- data/features/deleting_instances.feature +3 -0
- data/features/searching_by_index.feature +40 -0
- data/features/step_definitions/alpha_steps.rb +5 -1
- data/features/step_definitions/beta_steps.rb +1 -1
- data/features/step_definitions/common_steps.rb +12 -1
- data/features/step_definitions/sphinx_steps.rb +8 -4
- data/features/support/db/fixtures/tags.rb +1 -1
- data/features/support/env.rb +3 -0
- data/features/support/models/alpha.rb +11 -0
- data/lib/cucumber/thinking_sphinx/internal_world.rb +7 -6
- data/lib/thinking_sphinx.rb +40 -31
- data/lib/thinking_sphinx/active_record.rb +164 -195
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +9 -6
- data/lib/thinking_sphinx/configuration.rb +1 -1
- data/lib/thinking_sphinx/deltas/default_delta.rb +14 -20
- data/lib/thinking_sphinx/index.rb +76 -19
- data/lib/thinking_sphinx/index/builder.rb +2 -2
- data/lib/thinking_sphinx/search.rb +7 -0
- data/lib/thinking_sphinx/search_methods.rb +22 -4
- data/lib/thinking_sphinx/source.rb +6 -6
- data/lib/thinking_sphinx/source/sql.rb +4 -2
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/delta_spec.rb +4 -6
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/has_many_association_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/scopes_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record_spec.rb +254 -94
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/association_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/attribute_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/configuration_spec.rb +2 -2
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/array_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/string_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/excerpter_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_search_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/field_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/builder_spec.rb +10 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/faux_column_spec.rb +0 -0
- data/spec/thinking_sphinx/index_spec.rb +177 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/rails_additions_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_methods_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_spec.rb +33 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/source_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx_spec.rb → thinking_sphinx_spec.rb} +62 -50
- data/tasks/distribution.rb +3 -3
- metadata +27 -31
- data/VERSION.yml +0 -5
- data/features/support/db/active_record.rb +0 -40
- data/features/support/db/database.yml +0 -5
- data/features/support/db/mysql.rb +0 -3
- data/features/support/db/postgresql.rb +0 -3
- data/features/support/post_database.rb +0 -43
- data/spec/lib/thinking_sphinx/index_spec.rb +0 -45
File without changes
|
File without changes
|
@@ -3,8 +3,8 @@ require 'spec/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
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -466,4 +466,14 @@ describe ThinkingSphinx::Index::Builder do
|
|
466
466
|
@index.local_options[:index_exact_words].should be_true
|
467
467
|
end
|
468
468
|
end
|
469
|
+
|
470
|
+
context 'with an explicit name' do
|
471
|
+
it "should set the index's name using the provided value" do
|
472
|
+
index = ThinkingSphinx::Index::Builder.generate(Person, 'custom') do
|
473
|
+
indexes first_name
|
474
|
+
end
|
475
|
+
|
476
|
+
index.name.should == 'custom'
|
477
|
+
end
|
478
|
+
end
|
469
479
|
end
|
File without changes
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::Index do
|
4
|
+
describe "prefix_fields method" do
|
5
|
+
before :each do
|
6
|
+
@index = ThinkingSphinx::Index.new(Person)
|
7
|
+
|
8
|
+
@field_a = stub('field', :prefixes => true)
|
9
|
+
@field_b = stub('field', :prefixes => false)
|
10
|
+
@field_c = stub('field', :prefixes => true)
|
11
|
+
|
12
|
+
@index.stub!(:fields => [@field_a, @field_b, @field_c])
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return fields that are flagged as prefixed" do
|
16
|
+
@index.prefix_fields.should include(@field_a)
|
17
|
+
@index.prefix_fields.should include(@field_c)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not return fields that aren't flagged as prefixed" do
|
21
|
+
@index.prefix_fields.should_not include(@field_b)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "infix_fields method" do
|
26
|
+
before :each do
|
27
|
+
@index = ThinkingSphinx::Index.new(Person)
|
28
|
+
|
29
|
+
@field_a = stub('field', :infixes => true)
|
30
|
+
@field_b = stub('field', :infixes => false)
|
31
|
+
@field_c = stub('field', :infixes => true)
|
32
|
+
|
33
|
+
@index.stub!(:fields => [@field_a, @field_b, @field_c])
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return fields that are flagged as infixed" do
|
37
|
+
@index.infix_fields.should include(@field_a)
|
38
|
+
@index.infix_fields.should include(@field_c)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not return fields that aren't flagged as infixed" do
|
42
|
+
@index.infix_fields.should_not include(@field_b)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '.name_for' do
|
47
|
+
it "should return the model's name downcased" do
|
48
|
+
ThinkingSphinx::Index.name_for(Alpha).should == 'alpha'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should separate words by underscores" do
|
52
|
+
ThinkingSphinx::Index.name_for(ActiveRecord).should == 'active_record'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should separate namespaces by underscores" do
|
56
|
+
ThinkingSphinx::Index.name_for(ActiveRecord::Base).
|
57
|
+
should == 'active_record_base'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#name' do
|
62
|
+
it "should return the downcased name of the index's model" do
|
63
|
+
ThinkingSphinx::Index.new(Alpha).name.should == 'alpha'
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should return a custom name if one is set" do
|
67
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
68
|
+
index.name = 'custom'
|
69
|
+
index.name.should == 'custom'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#core_name' do
|
74
|
+
it "should take the index's name and append _core" do
|
75
|
+
ThinkingSphinx::Index.new(Alpha).core_name.should == 'alpha_core'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#delta_name' do
|
80
|
+
it "should take the index's name and append _delta" do
|
81
|
+
ThinkingSphinx::Index.new(Alpha).delta_name.should == 'alpha_delta'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#all_names' do
|
86
|
+
it "should return the core index name by default" do
|
87
|
+
ThinkingSphinx::Index.new(Alpha).all_names.should == ['alpha_core']
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should return both core and delta names if deltas are enabled" do
|
91
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
92
|
+
index.delta_object = stub('delta')
|
93
|
+
|
94
|
+
index.all_names.should == ['alpha_core', 'alpha_delta']
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should respect custom names" do
|
98
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
99
|
+
index.name = 'custom'
|
100
|
+
|
101
|
+
index.all_names.should == ['custom_core']
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should respect custom names when deltas are enabled" do
|
105
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
106
|
+
index.name = 'custom'
|
107
|
+
index.delta_object = stub('delta')
|
108
|
+
|
109
|
+
index.all_names.should == ['custom_core', 'custom_delta']
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#to_riddle' do
|
114
|
+
it "should return two Riddle indexes if deltas are disabled" do
|
115
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
116
|
+
|
117
|
+
index.to_riddle(0).length.should == 2
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should return three Riddle indexes if deltas are enabled" do
|
121
|
+
index = ThinkingSphinx::Index.new(Beta)
|
122
|
+
index.delta_object = stub('delta')
|
123
|
+
|
124
|
+
index.to_riddle(0).length.should == 3
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should include a distributed index" do
|
128
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
129
|
+
|
130
|
+
index.to_riddle(0).last.
|
131
|
+
should be_a(Riddle::Configuration::DistributedIndex)
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'core index' do
|
135
|
+
before :each do
|
136
|
+
@index = ThinkingSphinx::Index.new(Alpha).to_riddle(0).first
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should use the core name" do
|
140
|
+
@index.name.should == 'alpha_core'
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'delta index' do
|
145
|
+
before :each do
|
146
|
+
index = ThinkingSphinx::Index.new(Beta)
|
147
|
+
index.delta_object = stub('delta')
|
148
|
+
@index = index.to_riddle(0)[1]
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should use the delta name" do
|
152
|
+
@index.name.should == 'beta_delta'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'distributed index' do
|
157
|
+
it "should use the index's name" do
|
158
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
159
|
+
|
160
|
+
index.to_riddle(0).last.name.should == 'alpha'
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should add the core index" do
|
164
|
+
index = ThinkingSphinx::Index.new(Alpha)
|
165
|
+
|
166
|
+
index.to_riddle(0).last.local_indexes.should include('alpha_core')
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should add the delta index if there is one" do
|
170
|
+
index = ThinkingSphinx::Index.new(Beta)
|
171
|
+
index.delta_object = stub('delta')
|
172
|
+
|
173
|
+
index.to_riddle(0).last.local_indexes.should include('beta_delta')
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
File without changes
|
File without changes
|
@@ -302,6 +302,23 @@ describe ThinkingSphinx::Search do
|
|
302
302
|
@client.match_mode.should == :extended2
|
303
303
|
end
|
304
304
|
end
|
305
|
+
|
306
|
+
describe 'sphinx_select' do
|
307
|
+
it "should default to *" do
|
308
|
+
ThinkingSphinx::Search.new.first
|
309
|
+
|
310
|
+
@client.select.should == "*"
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should get set on the client if specified" do
|
314
|
+
ThinkingSphinx::Search.new('general',
|
315
|
+
:sphinx_select => "*, foo as bar"
|
316
|
+
).first
|
317
|
+
|
318
|
+
@client.select.should == "*, foo as bar"
|
319
|
+
end
|
320
|
+
|
321
|
+
end
|
305
322
|
|
306
323
|
describe 'pagination' do
|
307
324
|
it "should set the limit using per_page" do
|
@@ -834,6 +851,14 @@ describe ThinkingSphinx::Search do
|
|
834
851
|
|
835
852
|
ThinkingSphinx::Search.new.total_pages.should == 2
|
836
853
|
end
|
854
|
+
|
855
|
+
it "should return 0 if there is no index and therefore no results" do
|
856
|
+
@client.stub!(:query => {
|
857
|
+
:matches => [], :total_found => nil, :total => nil
|
858
|
+
})
|
859
|
+
|
860
|
+
ThinkingSphinx::Search.new.total_pages.should == 0
|
861
|
+
end
|
837
862
|
end
|
838
863
|
|
839
864
|
describe '#next_page' do
|
@@ -860,6 +885,14 @@ describe ThinkingSphinx::Search do
|
|
860
885
|
it "should return the total number of results, not just the amount on the page" do
|
861
886
|
ThinkingSphinx::Search.new.total_entries.should == 41
|
862
887
|
end
|
888
|
+
|
889
|
+
it "should return 0 if there is no index and therefore no results" do
|
890
|
+
@client.stub!(:query => {
|
891
|
+
:matches => [], :total_found => nil
|
892
|
+
})
|
893
|
+
|
894
|
+
ThinkingSphinx::Search.new.total_entries.should == 0
|
895
|
+
end
|
863
896
|
end
|
864
897
|
|
865
898
|
describe '#offset' do
|
File without changes
|
@@ -1,76 +1,90 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
2
|
|
3
3
|
describe ThinkingSphinx do
|
4
|
-
|
5
|
-
|
4
|
+
describe '.define_indexes?' do
|
5
|
+
it "should define indexes by default" do
|
6
|
+
ThinkingSphinx.define_indexes?.should be_true
|
7
|
+
end
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
describe '.define_indexes=' do
|
11
|
+
it "should disable index definition" do
|
12
|
+
ThinkingSphinx.define_indexes = false
|
13
|
+
ThinkingSphinx.define_indexes?.should be_false
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
it "should enable index definition" do
|
17
|
+
ThinkingSphinx.define_indexes = false
|
18
|
+
ThinkingSphinx.define_indexes?.should be_false
|
19
|
+
ThinkingSphinx.define_indexes = true
|
20
|
+
ThinkingSphinx.define_indexes?.should be_true
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
|
-
|
21
|
-
|
22
|
-
|
24
|
+
describe '.deltas_enabled?' do
|
25
|
+
it "should index deltas by default" do
|
26
|
+
ThinkingSphinx.deltas_enabled = nil
|
27
|
+
ThinkingSphinx.deltas_enabled?.should be_true
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
31
|
+
describe '.deltas_enabled=' do
|
32
|
+
it "should disable delta indexing" do
|
33
|
+
ThinkingSphinx.deltas_enabled = false
|
34
|
+
ThinkingSphinx.deltas_enabled?.should be_false
|
35
|
+
end
|
29
36
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
it "should enable delta indexing" do
|
38
|
+
ThinkingSphinx.deltas_enabled = false
|
39
|
+
ThinkingSphinx.deltas_enabled?.should be_false
|
40
|
+
ThinkingSphinx.deltas_enabled = true
|
41
|
+
ThinkingSphinx.deltas_enabled?.should be_true
|
42
|
+
end
|
35
43
|
end
|
36
44
|
|
37
|
-
|
38
|
-
|
39
|
-
|
45
|
+
describe '.updates_enabled?' do
|
46
|
+
it "should update indexes by default" do
|
47
|
+
ThinkingSphinx.updates_enabled = nil
|
48
|
+
ThinkingSphinx.updates_enabled?.should be_true
|
49
|
+
end
|
40
50
|
end
|
41
51
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
52
|
+
describe '.updates_enabled=' do
|
53
|
+
it "should disable index updating" do
|
54
|
+
ThinkingSphinx.updates_enabled = false
|
55
|
+
ThinkingSphinx.updates_enabled?.should be_false
|
56
|
+
end
|
46
57
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
58
|
+
it "should enable index updating" do
|
59
|
+
ThinkingSphinx.updates_enabled = false
|
60
|
+
ThinkingSphinx.updates_enabled?.should be_false
|
61
|
+
ThinkingSphinx.updates_enabled = true
|
62
|
+
ThinkingSphinx.updates_enabled?.should be_true
|
63
|
+
end
|
52
64
|
end
|
53
65
|
|
54
|
-
|
55
|
-
|
56
|
-
|
66
|
+
describe '.sphinx_running?' do
|
67
|
+
it "should always say Sphinx is running if flagged as being on a remote machine" do
|
68
|
+
ThinkingSphinx.remote_sphinx = true
|
69
|
+
ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
|
57
70
|
|
58
|
-
|
59
|
-
|
71
|
+
ThinkingSphinx.sphinx_running?.should be_true
|
72
|
+
end
|
60
73
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
74
|
+
it "should actually pay attention to Sphinx if not on a remote machine" do
|
75
|
+
ThinkingSphinx.remote_sphinx = false
|
76
|
+
ThinkingSphinx.stub!(:sphinx_running_by_pid? => false)
|
77
|
+
ThinkingSphinx.sphinx_running?.should be_false
|
65
78
|
|
66
|
-
|
67
|
-
|
79
|
+
ThinkingSphinx.stub!(:sphinx_running_by_pid? => true)
|
80
|
+
ThinkingSphinx.sphinx_running?.should be_true
|
81
|
+
end
|
68
82
|
end
|
69
83
|
|
70
84
|
describe '.version' do
|
71
85
|
it "should return the version from the stored YAML file" do
|
72
86
|
version = Jeweler::VersionHelper.new(
|
73
|
-
File.join(File.dirname(__FILE__), '
|
87
|
+
File.join(File.dirname(__FILE__), '..')
|
74
88
|
).to_s
|
75
89
|
|
76
90
|
ThinkingSphinx.version.should == version
|
@@ -94,9 +108,7 @@ describe ThinkingSphinx do
|
|
94
108
|
:connection => @connection
|
95
109
|
)
|
96
110
|
|
97
|
-
|
98
|
-
class_variable_set :@@use_group_by_shortcut, nil
|
99
|
-
end
|
111
|
+
Thread.current[:thinking_sphinx_use_group_by_shortcut] = nil
|
100
112
|
end
|
101
113
|
|
102
114
|
it "should return true if no ONLY_FULL_GROUP_BY" do
|
data/tasks/distribution.rb
CHANGED
@@ -20,7 +20,7 @@ Jeweler::Tasks.new do |gem|
|
|
20
20
|
"README.textile",
|
21
21
|
"tasks/**/*.rb",
|
22
22
|
"tasks/**/*.rake",
|
23
|
-
"VERSION
|
23
|
+
"VERSION"
|
24
24
|
]
|
25
25
|
gem.test_files = FileList[
|
26
26
|
"features/**/*",
|
@@ -28,8 +28,8 @@ Jeweler::Tasks.new do |gem|
|
|
28
28
|
]
|
29
29
|
|
30
30
|
gem.add_dependency 'activerecord', '>= 1.15.6'
|
31
|
-
gem.add_dependency 'riddle', '>= 1.0.
|
32
|
-
gem.add_dependency 'after_commit', '>= 1.0.
|
31
|
+
gem.add_dependency 'riddle', '>= 1.0.2'
|
32
|
+
gem.add_dependency 'after_commit', '>= 1.0.5'
|
33
33
|
|
34
34
|
gem.post_install_message = <<-MESSAGE
|
35
35
|
If you're upgrading, you should read this:
|