thinking-sphinx 1.5.0 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -291,13 +291,13 @@ describe ThinkingSphinx::Facet do
|
|
291
291
|
person = Person.find(:first)
|
292
292
|
friendship = Friendship.new(:person => person)
|
293
293
|
|
294
|
-
@facet.value(friendship,
|
294
|
+
@facet.value(friendship, 1).should == person.first_name
|
295
295
|
end
|
296
296
|
|
297
297
|
it "should return nil if the association is nil" do
|
298
298
|
friendship = Friendship.new(:person => nil)
|
299
299
|
|
300
|
-
@facet.value(friendship,
|
300
|
+
@facet.value(friendship, 1).should be_nil
|
301
301
|
end
|
302
302
|
|
303
303
|
it "should return multi-level association values" do
|
@@ -308,21 +308,9 @@ describe ThinkingSphinx::Facet do
|
|
308
308
|
field = ThinkingSphinx::Field.new(
|
309
309
|
@source, ThinkingSphinx::Index::FauxColumn.new(:person, :tags, :name)
|
310
310
|
)
|
311
|
-
ThinkingSphinx::Facet.new(field).value(friendship,
|
311
|
+
ThinkingSphinx::Facet.new(field).value(friendship, 'buried'.to_crc32).
|
312
312
|
should == 'buried'
|
313
313
|
end
|
314
|
-
|
315
|
-
it "should not error with multi-level association values containing a nil value" do
|
316
|
-
person = Person.find(:first)
|
317
|
-
tag = person.tags.build(:name => nil)
|
318
|
-
tag = person.tags.build(:name => "buried")
|
319
|
-
friendship = Friendship.new(:person => person)
|
320
|
-
|
321
|
-
field = ThinkingSphinx::Field.new(
|
322
|
-
@source, ThinkingSphinx::Index::FauxColumn.new(:person, :tags, :name)
|
323
|
-
)
|
324
|
-
lambda{ThinkingSphinx::Facet.new(field).value(friendship, {'name_facet' => 'buried'.to_crc32})}.should_not raise_error
|
325
|
-
end
|
326
314
|
end
|
327
315
|
|
328
316
|
describe 'for float attributes' do
|
@@ -338,21 +326,7 @@ describe ThinkingSphinx::Facet do
|
|
338
326
|
it "should translate using the given model" do
|
339
327
|
alpha = Alpha.new(:cost => 10.5)
|
340
328
|
|
341
|
-
@facet.value(alpha,
|
342
|
-
end
|
343
|
-
end
|
344
|
-
|
345
|
-
context 'manual value source' do
|
346
|
-
let(:index) { ThinkingSphinx::Index.new(Alpha) }
|
347
|
-
let(:source) { ThinkingSphinx::Source.new(index) }
|
348
|
-
let(:column) { ThinkingSphinx::Index::FauxColumn.new('LOWER(name)') }
|
349
|
-
let(:field) { ThinkingSphinx::Field.new(source, column) }
|
350
|
-
let(:facet) { ThinkingSphinx::Facet.new(field, :name) }
|
351
|
-
|
352
|
-
it "should use the given value source to figure out the value" do
|
353
|
-
alpha = Alpha.new(:name => 'Foo')
|
354
|
-
|
355
|
-
facet.value(alpha, {'foo_facet' => 'foo'.to_crc32}).should == 'Foo'
|
329
|
+
@facet.value(alpha, 1093140480).should == 10.5
|
356
330
|
end
|
357
331
|
end
|
358
332
|
end
|
@@ -44,17 +44,6 @@ describe ThinkingSphinx::Field do
|
|
44
44
|
@field.unique_name.should == "col_name"
|
45
45
|
end
|
46
46
|
end
|
47
|
-
|
48
|
-
describe '#to_select_sql' do
|
49
|
-
it "should return nil if polymorphic association data does not exist" do
|
50
|
-
field = ThinkingSphinx::Field.new(@source,
|
51
|
-
[ThinkingSphinx::Index::FauxColumn.new(:source, :name)],
|
52
|
-
:as => :source_name
|
53
|
-
)
|
54
|
-
|
55
|
-
field.to_select_sql.should be_nil
|
56
|
-
end
|
57
|
-
end
|
58
47
|
|
59
48
|
describe "prefixes method" do
|
60
49
|
it "should default to false" do
|
@@ -90,9 +79,9 @@ describe ThinkingSphinx::Field do
|
|
90
79
|
|
91
80
|
describe "is_many? method" do
|
92
81
|
before :each do
|
93
|
-
@assoc_a =
|
94
|
-
@assoc_b =
|
95
|
-
@assoc_c =
|
82
|
+
@assoc_a = stub('assoc', :is_many? => true)
|
83
|
+
@assoc_b = stub('assoc', :is_many? => true)
|
84
|
+
@assoc_c = stub('assoc', :is_many? => true)
|
96
85
|
|
97
86
|
@field = ThinkingSphinx::Field.new(
|
98
87
|
@source, [ThinkingSphinx::Index::FauxColumn.new(:col_name)]
|
@@ -100,9 +89,6 @@ describe ThinkingSphinx::Field do
|
|
100
89
|
@field.associations = {
|
101
90
|
:a => @assoc_a, :b => @assoc_b, :c => @assoc_c
|
102
91
|
}
|
103
|
-
@field.associations.values.each { |assoc|
|
104
|
-
assoc.stub!(:is_many? => true)
|
105
|
-
}
|
106
92
|
end
|
107
93
|
|
108
94
|
it "should return true if all associations return true to is_many?" do
|
@@ -1,347 +1,344 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Index::Builder do
|
4
|
-
let(:internal_attribute_count) {
|
5
|
-
Riddle.loaded_version.to_i < 2 ? 3 : 4
|
6
|
-
}
|
7
4
|
describe ".generate without source scope" do
|
8
5
|
before :each do
|
9
6
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
10
7
|
indexes first_name, last_name
|
11
8
|
has birthday
|
12
9
|
has id, :as => :internal_id
|
13
|
-
|
10
|
+
|
14
11
|
set_property :sql_range_step => 1000
|
15
|
-
|
12
|
+
|
16
13
|
where "birthday <= NOW()"
|
17
14
|
group_by "first_name"
|
18
15
|
end
|
19
|
-
|
16
|
+
|
20
17
|
@source = @index.sources.first
|
21
18
|
end
|
22
|
-
|
19
|
+
|
23
20
|
it "should return an index" do
|
24
21
|
@index.should be_a_kind_of(ThinkingSphinx::Index)
|
25
22
|
end
|
26
|
-
|
23
|
+
|
27
24
|
it "should have one source for the index" do
|
28
25
|
@index.sources.length.should == 1
|
29
26
|
end
|
30
|
-
|
27
|
+
|
31
28
|
it "should have two fields" do
|
32
29
|
@source.fields.length.should == 2
|
33
30
|
@source.fields[0].unique_name.should == :first_name
|
34
31
|
@source.fields[1].unique_name.should == :last_name
|
35
32
|
end
|
36
|
-
|
37
|
-
it "should have two attributes alongside the internal ones" do
|
38
|
-
@source.attributes.length.should ==
|
39
|
-
@source.attributes[
|
40
|
-
@source.attributes[
|
33
|
+
|
34
|
+
it "should have two attributes alongside the three internal ones" do
|
35
|
+
@source.attributes.length.should == 5
|
36
|
+
@source.attributes[3].unique_name.should == :birthday
|
37
|
+
@source.attributes[4].unique_name.should == :internal_id
|
41
38
|
end
|
42
|
-
|
39
|
+
|
43
40
|
it "should have one condition" do
|
44
41
|
@source.conditions.length.should == 1
|
45
42
|
@source.conditions.first.should == "birthday <= NOW()"
|
46
43
|
end
|
47
|
-
|
44
|
+
|
48
45
|
it "should have one grouping" do
|
49
46
|
@source.groupings.length.should == 1
|
50
47
|
@source.groupings.first.should == "first_name"
|
51
48
|
end
|
52
|
-
|
49
|
+
|
53
50
|
it "should have one option" do
|
54
51
|
@source.options.length.should == 1
|
55
52
|
@source.options[:sql_range_step].should == 1000
|
56
53
|
end
|
57
54
|
end
|
58
|
-
|
55
|
+
|
59
56
|
describe 'aliased field' do
|
60
57
|
before :each do
|
61
58
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
62
59
|
indexes first_name, :as => 'name'
|
63
60
|
end
|
64
|
-
|
61
|
+
|
65
62
|
@source = @index.sources.first
|
66
63
|
end
|
67
|
-
|
64
|
+
|
68
65
|
it "should store the alias as a symbol for consistency" do
|
69
66
|
@source.fields.last.unique_name.should == :name
|
70
67
|
end
|
71
68
|
end
|
72
|
-
|
69
|
+
|
73
70
|
describe 'aliased attribute' do
|
74
71
|
before :each do
|
75
72
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
76
73
|
indexes first_name
|
77
74
|
has :id, :as => 'real_id'
|
78
75
|
end
|
79
|
-
|
76
|
+
|
80
77
|
@source = @index.sources.first
|
81
78
|
end
|
82
|
-
|
79
|
+
|
83
80
|
it "should store the alias as a symbol for consistency" do
|
84
81
|
@source.attributes.last.unique_name.should == :real_id
|
85
82
|
end
|
86
83
|
end
|
87
|
-
|
84
|
+
|
88
85
|
describe "sortable field" do
|
89
86
|
before :each do
|
90
87
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
91
88
|
indexes first_name, :sortable => true
|
92
89
|
end
|
93
|
-
|
90
|
+
|
94
91
|
@source = @index.sources.first
|
95
92
|
end
|
96
|
-
|
93
|
+
|
97
94
|
it "should have one field" do
|
98
95
|
@source.fields.length.should == 1
|
99
96
|
end
|
100
|
-
|
101
|
-
it "should have one attribute alongside the internal ones" do
|
102
|
-
@source.attributes.length.should ==
|
97
|
+
|
98
|
+
it "should have one attribute alongside the three internal ones" do
|
99
|
+
@source.attributes.length.should == 4
|
103
100
|
end
|
104
|
-
|
101
|
+
|
105
102
|
it "should set the attribute name to have the _sort suffix" do
|
106
103
|
@source.attributes.last.unique_name.should == :first_name_sort
|
107
104
|
end
|
108
|
-
|
105
|
+
|
109
106
|
it "should set the attribute column to be the same as the field" do
|
110
107
|
@source.attributes.last.columns.length.should == 1
|
111
108
|
@source.attributes.last.columns.first.__name.should == :first_name
|
112
109
|
end
|
113
110
|
end
|
114
|
-
|
111
|
+
|
115
112
|
describe '#join' do
|
116
113
|
before :each do
|
117
114
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
118
115
|
indexes first_name
|
119
|
-
|
116
|
+
|
120
117
|
join contacts
|
121
118
|
end
|
122
|
-
|
119
|
+
|
123
120
|
@source = @index.sources.first
|
124
121
|
end
|
125
|
-
|
122
|
+
|
126
123
|
it "should include the explicit join" do
|
127
124
|
@source.joins.length.should == 1
|
128
125
|
end
|
129
126
|
end
|
130
|
-
|
127
|
+
|
131
128
|
describe "faceted field" do
|
132
129
|
before :each do
|
133
130
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
134
131
|
indexes first_name, :facet => true
|
135
132
|
end
|
136
|
-
|
133
|
+
|
137
134
|
@source = @index.sources.first
|
138
135
|
end
|
139
|
-
|
136
|
+
|
140
137
|
after :each do
|
141
138
|
Person.sphinx_facets.delete_at(-1)
|
142
139
|
end
|
143
|
-
|
140
|
+
|
144
141
|
it "should have one field" do
|
145
142
|
@source.fields.length.should == 1
|
146
143
|
end
|
147
|
-
|
148
|
-
it "should have one attribute alongside the internal ones" do
|
149
|
-
@source.attributes.length.should ==
|
144
|
+
|
145
|
+
it "should have one attribute alongside the three internal ones" do
|
146
|
+
@source.attributes.length.should == 4
|
150
147
|
end
|
151
|
-
|
148
|
+
|
152
149
|
it "should set the attribute name to have the _facet suffix" do
|
153
150
|
@source.attributes.last.unique_name.should == :first_name_facet
|
154
151
|
end
|
155
|
-
|
152
|
+
|
156
153
|
it "should set the attribute type to integer" do
|
157
154
|
@source.attributes.last.type.should == :integer
|
158
155
|
end
|
159
|
-
|
156
|
+
|
160
157
|
it "should set the attribute column to be the same as the field" do
|
161
158
|
@source.attributes.last.columns.length.should == 1
|
162
159
|
@source.attributes.last.columns.first.__name.should == :first_name
|
163
160
|
end
|
164
161
|
end
|
165
|
-
|
162
|
+
|
166
163
|
describe "faceted integer attribute" do
|
167
164
|
before :each do
|
168
165
|
@index = ThinkingSphinx::Index::Builder.generate(Alpha) do
|
169
166
|
indexes :name
|
170
167
|
has value, :facet => true
|
171
168
|
end
|
172
|
-
|
169
|
+
|
173
170
|
@source = @index.sources.first
|
174
171
|
end
|
175
|
-
|
172
|
+
|
176
173
|
after :each do
|
177
174
|
Alpha.sphinx_facets.delete_at(-1)
|
178
175
|
end
|
179
|
-
|
180
|
-
it "should have just one attribute alongside the internal ones" do
|
181
|
-
@source.attributes.length.should ==
|
176
|
+
|
177
|
+
it "should have just one attribute alongside the three internal ones" do
|
178
|
+
@source.attributes.length.should == 4
|
182
179
|
end
|
183
180
|
end
|
184
|
-
|
181
|
+
|
185
182
|
describe "faceted timestamp attribute" do
|
186
183
|
before :each do
|
187
184
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
188
185
|
indexes first_name
|
189
186
|
has birthday, :facet => true
|
190
187
|
end
|
191
|
-
|
188
|
+
|
192
189
|
@source = @index.sources.first
|
193
190
|
end
|
194
|
-
|
191
|
+
|
195
192
|
after :each do
|
196
193
|
Person.sphinx_facets.delete_at(-1)
|
197
194
|
end
|
198
|
-
|
199
|
-
it "should have just one attribute alongside the internal ones" do
|
200
|
-
@source.attributes.length.should ==
|
195
|
+
|
196
|
+
it "should have just one attribute alongside the three internal ones" do
|
197
|
+
@source.attributes.length.should == 4
|
201
198
|
end
|
202
199
|
end
|
203
|
-
|
200
|
+
|
204
201
|
describe "faceted boolean attribute" do
|
205
202
|
before :each do
|
206
203
|
@index = ThinkingSphinx::Index::Builder.generate(Beta) do
|
207
204
|
indexes :name
|
208
205
|
has delta, :facet => true
|
209
206
|
end
|
210
|
-
|
207
|
+
|
211
208
|
@source = @index.sources.first
|
212
209
|
end
|
213
|
-
|
210
|
+
|
214
211
|
after :each do
|
215
212
|
Beta.sphinx_facets.delete_at(-1)
|
216
213
|
end
|
217
|
-
|
218
|
-
it "should have just one attribute alongside the internal ones" do
|
219
|
-
@source.attributes.length.should ==
|
214
|
+
|
215
|
+
it "should have just one attribute alongside the three internal ones" do
|
216
|
+
@source.attributes.length.should == 4
|
220
217
|
end
|
221
218
|
end
|
222
|
-
|
219
|
+
|
223
220
|
describe "faceted float attribute" do
|
224
221
|
before :each do
|
225
222
|
@index = ThinkingSphinx::Index::Builder.generate(Alpha) do
|
226
223
|
indexes :name
|
227
224
|
has cost, :facet => true
|
228
225
|
end
|
229
|
-
|
226
|
+
|
230
227
|
@source = @index.sources.first
|
231
228
|
end
|
232
|
-
|
229
|
+
|
233
230
|
after :each do
|
234
231
|
Alpha.sphinx_facets.delete_at(-1)
|
235
232
|
end
|
236
|
-
|
237
|
-
it "should have just one attribute alongside the internal ones" do
|
238
|
-
@source.attributes.length.should ==
|
233
|
+
|
234
|
+
it "should have just one attribute alongside the three internal ones" do
|
235
|
+
@source.attributes.length.should == 4
|
239
236
|
end
|
240
237
|
end
|
241
|
-
|
238
|
+
|
242
239
|
describe "faceted string attribute" do
|
243
240
|
before :each do
|
244
241
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
245
242
|
indexes first_name
|
246
243
|
has last_name, :facet => true
|
247
244
|
end
|
248
|
-
|
245
|
+
|
249
246
|
@source = @index.sources.first
|
250
247
|
end
|
251
|
-
|
248
|
+
|
252
249
|
after :each do
|
253
250
|
Person.sphinx_facets.delete_at(-1)
|
254
251
|
end
|
255
|
-
|
256
|
-
it "should have two attributes alongside the internal ones" do
|
257
|
-
@source.attributes.length.should ==
|
252
|
+
|
253
|
+
it "should have two attributes alongside the three internal ones" do
|
254
|
+
@source.attributes.length.should == 5
|
258
255
|
end
|
259
|
-
|
256
|
+
|
260
257
|
it "should set the facet attribute name to have the _facet suffix" do
|
261
258
|
@source.attributes.last.unique_name.should == :last_name_facet
|
262
259
|
end
|
263
|
-
|
260
|
+
|
264
261
|
it "should set the attribute type to integer" do
|
265
262
|
@source.attributes.last.type.should == :integer
|
266
263
|
end
|
267
|
-
|
264
|
+
|
268
265
|
it "should set the attribute column to be the same as the field" do
|
269
266
|
@source.attributes.last.columns.length.should == 1
|
270
267
|
@source.attributes.last.columns.first.__name.should == :last_name
|
271
268
|
end
|
272
269
|
end
|
273
|
-
|
270
|
+
|
274
271
|
describe 'faceted manual MVA' do
|
275
272
|
before :each do
|
276
273
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
277
274
|
indexes first_name
|
278
275
|
has 'SQL STATEMENT', :type => :multi, :as => :sql, :facet => true
|
279
276
|
end
|
280
|
-
|
277
|
+
|
281
278
|
@source = @index.sources.first
|
282
279
|
end
|
283
|
-
|
280
|
+
|
284
281
|
after :each do
|
285
282
|
Person.sphinx_facets.delete_at(-1)
|
286
283
|
end
|
287
|
-
|
288
|
-
it "should have two attributes alongside the internal ones" do
|
289
|
-
@source.attributes.length.should ==
|
284
|
+
|
285
|
+
it "should have two attributes alongside the three internal ones" do
|
286
|
+
@source.attributes.length.should == 5
|
290
287
|
end
|
291
|
-
|
288
|
+
|
292
289
|
it "should set the facet attribute name to have the _facet suffix" do
|
293
290
|
@source.attributes.last.unique_name.should == :sql_facet
|
294
291
|
end
|
295
|
-
|
292
|
+
|
296
293
|
it "should keep the original attribute's name set as requested" do
|
297
294
|
@source.attributes[-2].unique_name.should == :sql
|
298
295
|
end
|
299
|
-
|
296
|
+
|
300
297
|
it "should set the attribute type to multi" do
|
301
298
|
@source.attributes.last.type.should == :multi
|
302
299
|
end
|
303
|
-
|
300
|
+
|
304
301
|
it "should set the attribute column to be the same as the field" do
|
305
302
|
@source.attributes.last.columns.length.should == 1
|
306
303
|
@source.attributes.last.columns.first.__name.should == 'SQL STATEMENT'
|
307
304
|
end
|
308
305
|
end
|
309
|
-
|
306
|
+
|
310
307
|
describe 'faceted MVA field' do
|
311
308
|
before :each do
|
312
309
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
313
310
|
indexes tags(:name), :as => :tags, :facet => true
|
314
311
|
end
|
315
|
-
|
312
|
+
|
316
313
|
@source = @index.sources.first
|
317
314
|
end
|
318
|
-
|
315
|
+
|
319
316
|
after :each do
|
320
317
|
Person.sphinx_facets.delete_at(-1)
|
321
318
|
end
|
322
|
-
|
319
|
+
|
323
320
|
it "should have one field" do
|
324
321
|
@source.fields.length.should == 1
|
325
322
|
end
|
326
|
-
|
327
|
-
it "should have one attribute alongside the internal ones" do
|
328
|
-
@source.attributes.length.should ==
|
323
|
+
|
324
|
+
it "should have one attribute alongside the three internal ones" do
|
325
|
+
@source.attributes.length.should == 4
|
329
326
|
end
|
330
|
-
|
327
|
+
|
331
328
|
it "should set the attribute name to have the _facet suffix" do
|
332
329
|
@source.attributes.last.unique_name.should == :tags_facet
|
333
330
|
end
|
334
|
-
|
331
|
+
|
335
332
|
it "should set the attribute type to multi" do
|
336
333
|
@source.attributes.last.type.should == :multi
|
337
334
|
end
|
338
|
-
|
335
|
+
|
339
336
|
it "should set the attribute column to be the same as the field" do
|
340
337
|
@source.attributes.last.columns.length.should == 1
|
341
338
|
@source.attributes.last.columns.first.__name.should == :name
|
342
339
|
end
|
343
340
|
end
|
344
|
-
|
341
|
+
|
345
342
|
describe "no fields" do
|
346
343
|
it "should raise an exception" do
|
347
344
|
lambda {
|
@@ -351,7 +348,7 @@ describe ThinkingSphinx::Index::Builder do
|
|
351
348
|
}.should raise_error
|
352
349
|
end
|
353
350
|
end
|
354
|
-
|
351
|
+
|
355
352
|
describe "explicit source" do
|
356
353
|
before :each do
|
357
354
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
@@ -359,38 +356,38 @@ describe ThinkingSphinx::Index::Builder do
|
|
359
356
|
indexes first_name, last_name
|
360
357
|
has birthday
|
361
358
|
has id, :as => :internal_id
|
362
|
-
|
359
|
+
|
363
360
|
set_property :delta => true
|
364
|
-
|
361
|
+
|
365
362
|
where "birthday <= NOW()"
|
366
363
|
group_by "first_name"
|
367
364
|
end
|
368
365
|
end
|
369
|
-
|
366
|
+
|
370
367
|
@source = @index.sources.first
|
371
368
|
end
|
372
|
-
|
369
|
+
|
373
370
|
it "should return an index" do
|
374
371
|
@index.should be_a_kind_of(ThinkingSphinx::Index)
|
375
372
|
end
|
376
|
-
|
373
|
+
|
377
374
|
it "should have one source for the index" do
|
378
375
|
@index.sources.length.should == 1
|
379
376
|
end
|
380
|
-
|
377
|
+
|
381
378
|
it "should have two fields" do
|
382
379
|
@source.fields.length.should == 2
|
383
380
|
@source.fields[0].unique_name.should == :first_name
|
384
381
|
@source.fields[1].unique_name.should == :last_name
|
385
382
|
end
|
386
|
-
|
387
|
-
it "should have two attributes alongside the internal ones" do
|
388
|
-
@source.attributes.length.should ==
|
389
|
-
@source.attributes[
|
390
|
-
@source.attributes[
|
383
|
+
|
384
|
+
it "should have two attributes alongside the three internal ones" do
|
385
|
+
@source.attributes.length.should == 5
|
386
|
+
@source.attributes[3].unique_name.should == :birthday
|
387
|
+
@source.attributes[4].unique_name.should == :internal_id
|
391
388
|
end
|
392
389
|
end
|
393
|
-
|
390
|
+
|
394
391
|
describe "multiple sources" do
|
395
392
|
before :each do
|
396
393
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
@@ -398,135 +395,101 @@ describe ThinkingSphinx::Index::Builder do
|
|
398
395
|
indexes first_name
|
399
396
|
has birthday
|
400
397
|
end
|
401
|
-
|
398
|
+
|
402
399
|
define_source do
|
403
400
|
indexes last_name
|
404
401
|
has :id, :as => :internal_id
|
405
402
|
end
|
406
403
|
end
|
407
404
|
end
|
408
|
-
|
405
|
+
|
409
406
|
it "should have two sources" do
|
410
407
|
@index.sources.length.should == 2
|
411
408
|
end
|
412
|
-
|
409
|
+
|
413
410
|
it "should have two fields" do
|
414
411
|
@index.fields.length.should == 2
|
415
412
|
end
|
416
|
-
|
413
|
+
|
417
414
|
it "should have one field in each source" do
|
418
415
|
@index.sources.each do |source|
|
419
416
|
source.fields.length.should == 1
|
420
417
|
end
|
421
418
|
end
|
422
|
-
|
419
|
+
|
423
420
|
it "should have two attributes alongside the six internal ones" do
|
424
|
-
@index.attributes.length.should ==
|
421
|
+
@index.attributes.length.should == 8
|
425
422
|
end
|
426
|
-
|
427
|
-
it "should have one attribute in each source alongside the internal ones" do
|
423
|
+
|
424
|
+
it "should have one attribute in each source alongside the three internal ones" do
|
428
425
|
@index.sources.each do |source|
|
429
|
-
source.attributes.length.should ==
|
426
|
+
source.attributes.length.should == 4
|
430
427
|
end
|
431
428
|
end
|
432
429
|
end
|
433
|
-
|
434
|
-
describe "multiple local indexes" do
|
435
|
-
before :each do
|
436
|
-
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
437
|
-
indexes first_name
|
438
|
-
|
439
|
-
use_local_index :other_local_index_1
|
440
|
-
use_local_indices "other_local_index_2", "other_local_index_3"
|
441
|
-
end
|
442
|
-
end
|
443
|
-
|
444
|
-
it "should have three additional indexes" do
|
445
|
-
@index.additional_indices.length.should == 3
|
446
|
-
end
|
447
|
-
|
448
|
-
it "should append _core to the name of each local index" do
|
449
|
-
@index.additional_indices[0].should eql("other_local_index_1_core")
|
450
|
-
@index.additional_indices[1].should eql("other_local_index_2_core")
|
451
|
-
@index.additional_indices[2].should eql("other_local_index_3_core")
|
452
|
-
end
|
453
|
-
end
|
454
|
-
|
430
|
+
|
455
431
|
describe "index options" do
|
456
432
|
before :each do
|
457
433
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
458
434
|
indexes first_name
|
459
|
-
|
435
|
+
|
460
436
|
set_property :charset_type => "utf16"
|
461
437
|
set_property :group_concat_max_len => 1024
|
462
438
|
end
|
463
439
|
end
|
464
|
-
|
440
|
+
|
465
441
|
it "should store the index setting for the index" do
|
466
442
|
@index.local_options[:charset_type].should == "utf16"
|
467
443
|
end
|
468
|
-
|
444
|
+
|
469
445
|
it "should store non-Sphinx settings for the index" do
|
470
446
|
@index.local_options[:group_concat_max_len].should == 1024
|
471
447
|
end
|
472
448
|
end
|
473
|
-
|
449
|
+
|
474
450
|
describe "delta options" do
|
475
451
|
before :each do
|
476
452
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
477
453
|
indexes first_name
|
478
|
-
|
454
|
+
|
479
455
|
set_property :delta => true
|
480
456
|
end
|
481
457
|
end
|
482
|
-
|
458
|
+
|
483
459
|
it "should not keep the delta setting in source options" do
|
484
460
|
@index.sources.first.options.should be_empty
|
485
461
|
end
|
486
|
-
|
462
|
+
|
487
463
|
it "should not keep the delta setting in index options" do
|
488
464
|
@index.local_options.should be_empty
|
489
465
|
end
|
490
|
-
|
466
|
+
|
491
467
|
it "should set the index delta object set" do
|
492
468
|
@index.delta_object.should be_a_kind_of(ThinkingSphinx::Deltas::DefaultDelta)
|
493
469
|
end
|
494
470
|
end
|
495
|
-
|
471
|
+
|
496
472
|
context 'index options' do
|
497
473
|
before :each do
|
498
474
|
@index = ThinkingSphinx::Index::Builder.generate(Person) do
|
499
475
|
indexes first_name
|
500
|
-
|
476
|
+
|
501
477
|
set_property :index_exact_words => true
|
502
478
|
end
|
503
479
|
end
|
504
|
-
|
480
|
+
|
505
481
|
it "should track the index_exact_words option to the index" do
|
506
482
|
@index.local_options[:index_exact_words].should be_true
|
507
483
|
end
|
508
484
|
end
|
509
|
-
|
485
|
+
|
510
486
|
context 'with an explicit name' do
|
511
487
|
it "should set the index's name using the provided value" do
|
512
488
|
index = ThinkingSphinx::Index::Builder.generate(Person, 'custom') do
|
513
489
|
indexes first_name
|
514
490
|
end
|
515
|
-
|
491
|
+
|
516
492
|
index.name.should == 'custom'
|
517
493
|
end
|
518
494
|
end
|
519
|
-
|
520
|
-
describe "sanitize_sql" do
|
521
|
-
def index
|
522
|
-
@index ||= ThinkingSphinx::Index::Builder.generate(Person) do
|
523
|
-
indexes first_name, last_name
|
524
|
-
where sanitize_sql(["gender = ?", "female"])
|
525
|
-
end
|
526
|
-
end
|
527
|
-
|
528
|
-
it "should be aliased to ActiveRecord::Base.sanitize_sql" do
|
529
|
-
index.sources.first.conditions.first.should == index.model.send(:sanitize_sql, ["gender = ?", "female"])
|
530
|
-
end
|
531
|
-
end
|
532
495
|
end
|