moneypools-thinking-sphinx 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/LICENCE +20 -0
  2. data/README.textile +157 -0
  3. data/VERSION.yml +4 -0
  4. data/lib/thinking_sphinx.rb +211 -0
  5. data/lib/thinking_sphinx/active_record.rb +307 -0
  6. data/lib/thinking_sphinx/active_record/attribute_updates.rb +48 -0
  7. data/lib/thinking_sphinx/active_record/delta.rb +87 -0
  8. data/lib/thinking_sphinx/active_record/has_many_association.rb +28 -0
  9. data/lib/thinking_sphinx/active_record/scopes.rb +39 -0
  10. data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
  11. data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
  12. data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +136 -0
  13. data/lib/thinking_sphinx/association.rb +164 -0
  14. data/lib/thinking_sphinx/attribute.rb +340 -0
  15. data/lib/thinking_sphinx/class_facet.rb +15 -0
  16. data/lib/thinking_sphinx/configuration.rb +282 -0
  17. data/lib/thinking_sphinx/core/array.rb +7 -0
  18. data/lib/thinking_sphinx/core/string.rb +15 -0
  19. data/lib/thinking_sphinx/deltas.rb +30 -0
  20. data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
  21. data/lib/thinking_sphinx/deltas/default_delta.rb +68 -0
  22. data/lib/thinking_sphinx/deltas/delayed_delta.rb +34 -0
  23. data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
  24. data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
  25. data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
  26. data/lib/thinking_sphinx/deploy/capistrano.rb +100 -0
  27. data/lib/thinking_sphinx/excerpter.rb +22 -0
  28. data/lib/thinking_sphinx/facet.rb +125 -0
  29. data/lib/thinking_sphinx/facet_search.rb +134 -0
  30. data/lib/thinking_sphinx/field.rb +82 -0
  31. data/lib/thinking_sphinx/index.rb +99 -0
  32. data/lib/thinking_sphinx/index/builder.rb +286 -0
  33. data/lib/thinking_sphinx/index/faux_column.rb +110 -0
  34. data/lib/thinking_sphinx/property.rb +162 -0
  35. data/lib/thinking_sphinx/rails_additions.rb +150 -0
  36. data/lib/thinking_sphinx/search.rb +689 -0
  37. data/lib/thinking_sphinx/search_methods.rb +421 -0
  38. data/lib/thinking_sphinx/source.rb +150 -0
  39. data/lib/thinking_sphinx/source/internal_properties.rb +46 -0
  40. data/lib/thinking_sphinx/source/sql.rb +128 -0
  41. data/lib/thinking_sphinx/tasks.rb +165 -0
  42. data/rails/init.rb +14 -0
  43. data/spec/lib/thinking_sphinx/active_record/delta_spec.rb +130 -0
  44. data/spec/lib/thinking_sphinx/active_record/has_many_association_spec.rb +49 -0
  45. data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +96 -0
  46. data/spec/lib/thinking_sphinx/active_record_spec.rb +364 -0
  47. data/spec/lib/thinking_sphinx/association_spec.rb +239 -0
  48. data/spec/lib/thinking_sphinx/attribute_spec.rb +500 -0
  49. data/spec/lib/thinking_sphinx/configuration_spec.rb +335 -0
  50. data/spec/lib/thinking_sphinx/core/array_spec.rb +9 -0
  51. data/spec/lib/thinking_sphinx/core/string_spec.rb +9 -0
  52. data/spec/lib/thinking_sphinx/excerpter_spec.rb +49 -0
  53. data/spec/lib/thinking_sphinx/facet_search_spec.rb +176 -0
  54. data/spec/lib/thinking_sphinx/facet_spec.rb +333 -0
  55. data/spec/lib/thinking_sphinx/field_spec.rb +154 -0
  56. data/spec/lib/thinking_sphinx/index/builder_spec.rb +455 -0
  57. data/spec/lib/thinking_sphinx/index/faux_column_spec.rb +30 -0
  58. data/spec/lib/thinking_sphinx/index_spec.rb +45 -0
  59. data/spec/lib/thinking_sphinx/rails_additions_spec.rb +203 -0
  60. data/spec/lib/thinking_sphinx/search_methods_spec.rb +152 -0
  61. data/spec/lib/thinking_sphinx/search_spec.rb +1066 -0
  62. data/spec/lib/thinking_sphinx/source_spec.rb +227 -0
  63. data/spec/lib/thinking_sphinx_spec.rb +162 -0
  64. data/tasks/distribution.rb +49 -0
  65. data/tasks/rails.rake +1 -0
  66. data/tasks/testing.rb +83 -0
  67. data/vendor/after_commit/LICENSE +20 -0
  68. data/vendor/after_commit/README +16 -0
  69. data/vendor/after_commit/Rakefile +22 -0
  70. data/vendor/after_commit/init.rb +8 -0
  71. data/vendor/after_commit/lib/after_commit.rb +45 -0
  72. data/vendor/after_commit/lib/after_commit/active_record.rb +114 -0
  73. data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
  74. data/vendor/after_commit/test/after_commit_test.rb +53 -0
  75. data/vendor/riddle/lib/riddle.rb +30 -0
  76. data/vendor/riddle/lib/riddle/client.rb +622 -0
  77. data/vendor/riddle/lib/riddle/client/filter.rb +53 -0
  78. data/vendor/riddle/lib/riddle/client/message.rb +66 -0
  79. data/vendor/riddle/lib/riddle/client/response.rb +84 -0
  80. data/vendor/riddle/lib/riddle/configuration.rb +33 -0
  81. data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
  82. data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
  83. data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
  84. data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
  85. data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
  86. data/vendor/riddle/lib/riddle/configuration/section.rb +43 -0
  87. data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
  88. data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
  89. data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
  90. data/vendor/riddle/lib/riddle/controller.rb +54 -0
  91. metadata +168 -0
@@ -0,0 +1,455 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ThinkingSphinx::Index::Builder do
4
+ describe ".generate without source scope" do
5
+ before :each do
6
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
7
+ indexes first_name, last_name
8
+ has birthday
9
+ has id, :as => :internal_id
10
+
11
+ set_property :sql_range_step => 1000
12
+
13
+ where "birthday <= NOW()"
14
+ group_by "first_name"
15
+ end
16
+
17
+ @source = @index.sources.first
18
+ end
19
+
20
+ it "should return an index" do
21
+ @index.should be_a_kind_of(ThinkingSphinx::Index)
22
+ end
23
+
24
+ it "should have one source for the index" do
25
+ @index.sources.length.should == 1
26
+ end
27
+
28
+ it "should have two fields" do
29
+ @source.fields.length.should == 2
30
+ @source.fields[0].unique_name.should == :first_name
31
+ @source.fields[1].unique_name.should == :last_name
32
+ end
33
+
34
+ it "should have two attributes alongside the four internal ones" do
35
+ @source.attributes.length.should == 6
36
+ @source.attributes[4].unique_name.should == :birthday
37
+ @source.attributes[5].unique_name.should == :internal_id
38
+ end
39
+
40
+ it "should have one condition" do
41
+ @source.conditions.length.should == 1
42
+ @source.conditions.first.should == "birthday <= NOW()"
43
+ end
44
+
45
+ it "should have one grouping" do
46
+ @source.groupings.length.should == 1
47
+ @source.groupings.first.should == "first_name"
48
+ end
49
+
50
+ it "should have one option" do
51
+ @source.options.length.should == 1
52
+ @source.options[:sql_range_step].should == 1000
53
+ end
54
+ end
55
+
56
+ describe 'aliased field' do
57
+ before :each do
58
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
59
+ indexes first_name, :as => 'name'
60
+ end
61
+
62
+ @source = @index.sources.first
63
+ end
64
+
65
+ it "should store the alias as a symbol for consistency" do
66
+ @source.fields.last.unique_name.should == :name
67
+ end
68
+ end
69
+
70
+ describe 'aliased attribute' do
71
+ before :each do
72
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
73
+ indexes first_name
74
+ has :id, :as => 'real_id'
75
+ end
76
+
77
+ @source = @index.sources.first
78
+ end
79
+
80
+ it "should store the alias as a symbol for consistency" do
81
+ @source.attributes.last.unique_name.should == :real_id
82
+ end
83
+ end
84
+
85
+ describe "sortable field" do
86
+ before :each do
87
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
88
+ indexes first_name, :sortable => true
89
+ end
90
+
91
+ @source = @index.sources.first
92
+ end
93
+
94
+ it "should have one field" do
95
+ @source.fields.length.should == 1
96
+ end
97
+
98
+ it "should have one attribute alongside the four internal ones" do
99
+ @source.attributes.length.should == 5
100
+ end
101
+
102
+ it "should set the attribute name to have the _sort suffix" do
103
+ @source.attributes.last.unique_name.should == :first_name_sort
104
+ end
105
+
106
+ it "should set the attribute column to be the same as the field" do
107
+ @source.attributes.last.columns.length.should == 1
108
+ @source.attributes.last.columns.first.__name.should == :first_name
109
+ end
110
+ end
111
+
112
+ describe "faceted field" do
113
+ before :each do
114
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
115
+ indexes first_name, :facet => true
116
+ end
117
+
118
+ @source = @index.sources.first
119
+ end
120
+
121
+ after :each do
122
+ Person.sphinx_facets.delete_at(-1)
123
+ end
124
+
125
+ it "should have one field" do
126
+ @source.fields.length.should == 1
127
+ end
128
+
129
+ it "should have one attribute alongside the four internal ones" do
130
+ @source.attributes.length.should == 5
131
+ end
132
+
133
+ it "should set the attribute name to have the _facet suffix" do
134
+ @source.attributes.last.unique_name.should == :first_name_facet
135
+ end
136
+
137
+ it "should set the attribute type to integer" do
138
+ @source.attributes.last.type.should == :integer
139
+ end
140
+
141
+ it "should set the attribute column to be the same as the field" do
142
+ @source.attributes.last.columns.length.should == 1
143
+ @source.attributes.last.columns.first.__name.should == :first_name
144
+ end
145
+ end
146
+
147
+ describe "faceted integer attribute" do
148
+ before :each do
149
+ @index = ThinkingSphinx::Index::Builder.generate(Alpha) do
150
+ indexes :name
151
+ has value, :facet => true
152
+ end
153
+
154
+ @source = @index.sources.first
155
+ end
156
+
157
+ after :each do
158
+ Alpha.sphinx_facets.delete_at(-1)
159
+ end
160
+
161
+ it "should have just one attribute alongside the four internal ones" do
162
+ @source.attributes.length.should == 5
163
+ end
164
+ end
165
+
166
+ describe "faceted timestamp attribute" do
167
+ before :each do
168
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
169
+ indexes first_name
170
+ has birthday, :facet => true
171
+ end
172
+
173
+ @source = @index.sources.first
174
+ end
175
+
176
+ after :each do
177
+ Person.sphinx_facets.delete_at(-1)
178
+ end
179
+
180
+ it "should have just one attribute alongside the four internal ones" do
181
+ @source.attributes.length.should == 5
182
+ end
183
+ end
184
+
185
+ describe "faceted boolean attribute" do
186
+ before :each do
187
+ @index = ThinkingSphinx::Index::Builder.generate(Beta) do
188
+ indexes :name
189
+ has delta, :facet => true
190
+ end
191
+
192
+ @source = @index.sources.first
193
+ end
194
+
195
+ after :each do
196
+ Beta.sphinx_facets.delete_at(-1)
197
+ end
198
+
199
+ it "should have just one attribute alongside the four internal ones" do
200
+ @source.attributes.length.should == 5
201
+ end
202
+ end
203
+
204
+ describe "faceted float attribute" do
205
+ before :each do
206
+ @index = ThinkingSphinx::Index::Builder.generate(Alpha) do
207
+ indexes :name
208
+ has cost, :facet => true
209
+ end
210
+
211
+ @source = @index.sources.first
212
+ end
213
+
214
+ after :each do
215
+ Alpha.sphinx_facets.delete_at(-1)
216
+ end
217
+
218
+ it "should have just one attribute alongside the four internal ones" do
219
+ @source.attributes.length.should == 5
220
+ end
221
+ end
222
+
223
+ describe "faceted string attribute" do
224
+ before :each do
225
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
226
+ indexes first_name
227
+ has last_name, :facet => true
228
+ end
229
+
230
+ @source = @index.sources.first
231
+ end
232
+
233
+ after :each do
234
+ Person.sphinx_facets.delete_at(-1)
235
+ end
236
+
237
+ it "should have two attributes alongside the four internal ones" do
238
+ @source.attributes.length.should == 6
239
+ end
240
+
241
+ it "should set the facet attribute name to have the _facet suffix" do
242
+ @source.attributes.last.unique_name.should == :last_name_facet
243
+ end
244
+
245
+ it "should set the attribute type to integer" do
246
+ @source.attributes.last.type.should == :integer
247
+ end
248
+
249
+ it "should set the attribute column to be the same as the field" do
250
+ @source.attributes.last.columns.length.should == 1
251
+ @source.attributes.last.columns.first.__name.should == :last_name
252
+ end
253
+ end
254
+
255
+ describe 'faceted manual MVA' do
256
+ before :each do
257
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
258
+ indexes first_name
259
+ has 'SQL STATEMENT', :type => :multi, :as => :sql, :facet => true
260
+ end
261
+
262
+ @source = @index.sources.first
263
+ end
264
+
265
+ after :each do
266
+ Person.sphinx_facets.delete_at(-1)
267
+ end
268
+
269
+ it "should have two attributes alongside the four internal ones" do
270
+ @source.attributes.length.should == 6
271
+ end
272
+
273
+ it "should set the facet attribute name to have the _facet suffix" do
274
+ @source.attributes.last.unique_name.should == :sql_facet
275
+ end
276
+
277
+ it "should keep the original attribute's name set as requested" do
278
+ @source.attributes[-2].unique_name.should == :sql
279
+ end
280
+
281
+ it "should set the attribute type to multi" do
282
+ @source.attributes.last.type.should == :multi
283
+ end
284
+
285
+ it "should set the attribute column to be the same as the field" do
286
+ @source.attributes.last.columns.length.should == 1
287
+ @source.attributes.last.columns.first.__name.should == 'SQL STATEMENT'
288
+ end
289
+ end
290
+
291
+ describe 'faceted MVA field' do
292
+ before :each do
293
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
294
+ indexes tags(:name), :as => :tags, :facet => true
295
+ end
296
+
297
+ @source = @index.sources.first
298
+ end
299
+
300
+ after :each do
301
+ Person.sphinx_facets.delete_at(-1)
302
+ end
303
+
304
+ it "should have one field" do
305
+ @source.fields.length.should == 1
306
+ end
307
+
308
+ it "should have one attribute alongside the four internal ones" do
309
+ @source.attributes.length.should == 5
310
+ end
311
+
312
+ it "should set the attribute name to have the _facet suffix" do
313
+ @source.attributes.last.unique_name.should == :tags_facet
314
+ end
315
+
316
+ it "should set the attribute type to multi" do
317
+ @source.attributes.last.type.should == :multi
318
+ end
319
+
320
+ it "should set the attribute column to be the same as the field" do
321
+ @source.attributes.last.columns.length.should == 1
322
+ @source.attributes.last.columns.first.__name.should == :name
323
+ end
324
+ end
325
+
326
+ describe "no fields" do
327
+ it "should raise an exception" do
328
+ lambda {
329
+ ThinkingSphinx::Index::Builder.generate(Person) do
330
+ #
331
+ end
332
+ }.should raise_error
333
+ end
334
+ end
335
+
336
+ describe "explicit source" do
337
+ before :each do
338
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
339
+ define_source do
340
+ indexes first_name, last_name
341
+ has birthday
342
+ has id, :as => :internal_id
343
+
344
+ set_property :delta => true
345
+
346
+ where "birthday <= NOW()"
347
+ group_by "first_name"
348
+ end
349
+ end
350
+
351
+ @source = @index.sources.first
352
+ end
353
+
354
+ it "should return an index" do
355
+ @index.should be_a_kind_of(ThinkingSphinx::Index)
356
+ end
357
+
358
+ it "should have one source for the index" do
359
+ @index.sources.length.should == 1
360
+ end
361
+
362
+ it "should have two fields" do
363
+ @source.fields.length.should == 2
364
+ @source.fields[0].unique_name.should == :first_name
365
+ @source.fields[1].unique_name.should == :last_name
366
+ end
367
+
368
+ it "should have two attributes alongside the four internal ones" do
369
+ @source.attributes.length.should == 6
370
+ @source.attributes[4].unique_name.should == :birthday
371
+ @source.attributes[5].unique_name.should == :internal_id
372
+ end
373
+ end
374
+
375
+ describe "multiple sources" do
376
+ before :each do
377
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
378
+ define_source do
379
+ indexes first_name
380
+ has birthday
381
+ end
382
+
383
+ define_source do
384
+ indexes last_name
385
+ has :id, :as => :internal_id
386
+ end
387
+ end
388
+ end
389
+
390
+ it "should have two sources" do
391
+ @index.sources.length.should == 2
392
+ end
393
+
394
+ it "should have two fields" do
395
+ @index.fields.length.should == 2
396
+ end
397
+
398
+ it "should have one field in each source" do
399
+ @index.sources.each do |source|
400
+ source.fields.length.should == 1
401
+ end
402
+ end
403
+
404
+ it "should have two attributes alongside the eight internal ones" do
405
+ @index.attributes.length.should == 10
406
+ end
407
+
408
+ it "should have one attribute in each source alongside the four internal ones" do
409
+ @index.sources.each do |source|
410
+ source.attributes.length.should == 5
411
+ end
412
+ end
413
+ end
414
+
415
+ describe "index options" do
416
+ before :each do
417
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
418
+ indexes first_name
419
+
420
+ set_property :charset_type => "utf16"
421
+ set_property :group_concat_max_len => 1024
422
+ end
423
+ end
424
+
425
+ it "should store the index setting for the index" do
426
+ @index.local_options[:charset_type].should == "utf16"
427
+ end
428
+
429
+ it "should store non-Sphinx settings for the index" do
430
+ @index.local_options[:group_concat_max_len].should == 1024
431
+ end
432
+ end
433
+
434
+ describe "delta options" do
435
+ before :each do
436
+ @index = ThinkingSphinx::Index::Builder.generate(Person) do
437
+ indexes first_name
438
+
439
+ set_property :delta => true
440
+ end
441
+ end
442
+
443
+ it "should not keep the delta setting in source options" do
444
+ @index.sources.first.options.should be_empty
445
+ end
446
+
447
+ it "should not keep the delta setting in index options" do
448
+ @index.local_options.should be_empty
449
+ end
450
+
451
+ it "should set the index delta object set" do
452
+ @index.delta_object.should be_a_kind_of(ThinkingSphinx::Deltas::DefaultDelta)
453
+ end
454
+ end
455
+ end