thinking-sphinx 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +2 -0
- data/VERSION +1 -1
- data/features/searching_by_model.feature +13 -0
- data/features/support/env.rb +2 -1
- 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/posts.rb +5 -1
- data/features/thinking_sphinx/db/migrations/create_posts.rb +1 -0
- data/features/thinking_sphinx/models/developer.rb +1 -0
- data/features/thinking_sphinx/models/music.rb +3 -1
- data/features/thinking_sphinx/models/post.rb +1 -0
- data/lib/thinking_sphinx.rb +2 -2
- data/lib/thinking_sphinx/active_record.rb +32 -2
- data/lib/thinking_sphinx/active_record/delta.rb +0 -27
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +4 -0
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +4 -0
- data/lib/thinking_sphinx/association.rb +55 -5
- data/lib/thinking_sphinx/attribute.rb +17 -10
- data/lib/thinking_sphinx/auto_version.rb +1 -1
- data/lib/thinking_sphinx/class_facet.rb +7 -3
- data/lib/thinking_sphinx/configuration.rb +3 -3
- data/lib/thinking_sphinx/facet.rb +1 -0
- data/lib/thinking_sphinx/facet_search.rb +5 -1
- data/lib/thinking_sphinx/field.rb +16 -0
- data/lib/thinking_sphinx/search.rb +21 -5
- data/lib/thinking_sphinx/sinatra.rb +7 -0
- data/lib/thinking_sphinx/source.rb +33 -2
- data/lib/thinking_sphinx/source/internal_properties.rb +8 -3
- data/lib/thinking_sphinx/source/sql.rb +10 -1
- data/spec/thinking_sphinx/attribute_spec.rb +86 -94
- data/spec/thinking_sphinx/auto_version_spec.rb +8 -0
- data/spec/thinking_sphinx/facet_search_spec.rb +12 -6
- data/spec/thinking_sphinx/index/builder_spec.rb +32 -29
- data/spec/thinking_sphinx/search_spec.rb +14 -11
- metadata +5 -4
@@ -19,6 +19,8 @@ module ThinkingSphinx
|
|
19
19
|
# - :sortable => true
|
20
20
|
# - :infixes => true
|
21
21
|
# - :prefixes => true
|
22
|
+
# - :file => true
|
23
|
+
# - :with => :attribute # or :wordcount
|
22
24
|
#
|
23
25
|
# Alias is only required in three circumstances: when there's
|
24
26
|
# another attribute or field with the same name, when the column name is
|
@@ -58,6 +60,8 @@ module ThinkingSphinx
|
|
58
60
|
@sortable = options[:sortable] || false
|
59
61
|
@infixes = options[:infixes] || false
|
60
62
|
@prefixes = options[:prefixes] || false
|
63
|
+
@file = options[:file] || false
|
64
|
+
@with = options[:with]
|
61
65
|
|
62
66
|
source.fields << self
|
63
67
|
end
|
@@ -78,5 +82,17 @@ module ThinkingSphinx
|
|
78
82
|
|
79
83
|
"#{clause} AS #{quote_column(unique_name)}"
|
80
84
|
end
|
85
|
+
|
86
|
+
def file?
|
87
|
+
@file
|
88
|
+
end
|
89
|
+
|
90
|
+
def with_attribute?
|
91
|
+
@with == :attribute
|
92
|
+
end
|
93
|
+
|
94
|
+
def with_wordcount?
|
95
|
+
@with == :wordcount
|
96
|
+
end
|
81
97
|
end
|
82
98
|
end
|
@@ -22,7 +22,7 @@ module ThinkingSphinx
|
|
22
22
|
undef_method method
|
23
23
|
}
|
24
24
|
|
25
|
-
HashOptions = [:conditions, :with, :without, :with_all]
|
25
|
+
HashOptions = [:conditions, :with, :without, :with_all, :without_any]
|
26
26
|
ArrayOptions = [:classes, :without_ids]
|
27
27
|
|
28
28
|
attr_reader :args, :options
|
@@ -482,9 +482,12 @@ module ThinkingSphinx
|
|
482
482
|
|
483
483
|
def match_hash(object)
|
484
484
|
@results[:matches].detect { |match|
|
485
|
+
class_crc = object.class.name
|
486
|
+
class_crc = object.class.to_crc32 if Riddle.loaded_version.to_i < 2
|
487
|
+
|
485
488
|
match[:attributes]['sphinx_internal_id'] == object.
|
486
489
|
primary_key_for_sphinx &&
|
487
|
-
match[:attributes][
|
490
|
+
match[:attributes][crc_attribute] == class_crc
|
488
491
|
}
|
489
492
|
end
|
490
493
|
|
@@ -722,6 +725,11 @@ module ThinkingSphinx
|
|
722
725
|
Array(values).collect { |value|
|
723
726
|
Riddle::Client::Filter.new attrib.to_s, filter_value(value)
|
724
727
|
}
|
728
|
+
}.flatten +
|
729
|
+
(options[:without_any] || {}).collect { |attrib, values|
|
730
|
+
Array(values).collect { |value|
|
731
|
+
Riddle::Client::Filter.new attrib.to_s, filter_value(value), true
|
732
|
+
}
|
725
733
|
}.flatten
|
726
734
|
end
|
727
735
|
|
@@ -877,7 +885,7 @@ module ThinkingSphinx
|
|
877
885
|
return single_class_results if one_class
|
878
886
|
|
879
887
|
groups = results[:matches].group_by { |match|
|
880
|
-
match[:attributes][
|
888
|
+
match[:attributes][crc_attribute]
|
881
889
|
}
|
882
890
|
groups.each do |crc, group|
|
883
891
|
group.replace(
|
@@ -887,7 +895,7 @@ module ThinkingSphinx
|
|
887
895
|
|
888
896
|
results[:matches].collect do |match|
|
889
897
|
groups.detect { |crc, group|
|
890
|
-
crc == match[:attributes][
|
898
|
+
crc == match[:attributes][crc_attribute]
|
891
899
|
}[1].compact.detect { |obj|
|
892
900
|
obj.primary_key_for_sphinx == match[:attributes]["sphinx_internal_id"]
|
893
901
|
}
|
@@ -899,7 +907,11 @@ module ThinkingSphinx
|
|
899
907
|
end
|
900
908
|
|
901
909
|
def class_from_crc(crc)
|
902
|
-
|
910
|
+
if Riddle.loaded_version.to_i < 2
|
911
|
+
config.models_by_crc[crc].constantize
|
912
|
+
else
|
913
|
+
crc.constantize
|
914
|
+
end
|
903
915
|
end
|
904
916
|
|
905
917
|
def each_with_attribute(attribute, &block)
|
@@ -952,5 +964,9 @@ module ThinkingSphinx
|
|
952
964
|
|
953
965
|
results_count
|
954
966
|
end
|
967
|
+
|
968
|
+
def crc_attribute
|
969
|
+
Riddle.loaded_version.to_i < 2 ? 'class_crc' : 'sphinx_internal_class'
|
970
|
+
end
|
955
971
|
end
|
956
972
|
end
|
@@ -23,8 +23,8 @@ module ThinkingSphinx
|
|
23
23
|
@database_configuration = @model.connection.
|
24
24
|
instance_variable_get(:@config).clone
|
25
25
|
|
26
|
-
@base =
|
27
|
-
@model, [],
|
26
|
+
@base = join_dependency_class.new(
|
27
|
+
@model, [], initial_joins
|
28
28
|
)
|
29
29
|
|
30
30
|
unless @model.descends_from_active_record?
|
@@ -45,6 +45,7 @@ module ThinkingSphinx
|
|
45
45
|
)
|
46
46
|
|
47
47
|
set_source_database_settings source
|
48
|
+
set_source_fields source
|
48
49
|
set_source_attributes source, offset
|
49
50
|
set_source_settings source
|
50
51
|
set_source_sql source, offset
|
@@ -59,6 +60,7 @@ module ThinkingSphinx
|
|
59
60
|
source.parent = "#{index.core_name}_#{position}"
|
60
61
|
|
61
62
|
set_source_database_settings source
|
63
|
+
set_source_fields source
|
62
64
|
set_source_attributes source, offset, true
|
63
65
|
set_source_settings source
|
64
66
|
set_source_sql source, offset, true
|
@@ -97,6 +99,14 @@ module ThinkingSphinx
|
|
97
99
|
source.sql_sock = config[:socket]
|
98
100
|
end
|
99
101
|
|
102
|
+
def set_source_fields(source)
|
103
|
+
fields.each do |field|
|
104
|
+
source.sql_file_field << field.unique_name if field.file?
|
105
|
+
source.sql_field_string << field.unique_name if field.with_attribute?
|
106
|
+
source.sql_field_str2wordcount << field.unique_name if field.with_wordcount?
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
100
110
|
def set_source_attributes(source, offset, delta = false)
|
101
111
|
available_attributes.each do |attrib|
|
102
112
|
source.send(attrib.type_to_config) << attrib.config_value(offset, delta)
|
@@ -159,5 +169,26 @@ module ThinkingSphinx
|
|
159
169
|
def utf8?
|
160
170
|
@index.options[:charset_type] =~ /utf-8|zh_cn.utf-8/
|
161
171
|
end
|
172
|
+
|
173
|
+
def join_dependency_class
|
174
|
+
if rails_3_1?
|
175
|
+
::ActiveRecord::Associations::JoinDependency
|
176
|
+
else
|
177
|
+
::ActiveRecord::Associations::ClassMethods::JoinDependency
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def initial_joins
|
182
|
+
if rails_3_1?
|
183
|
+
[]
|
184
|
+
else
|
185
|
+
nil
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def rails_3_1?
|
190
|
+
::ActiveRecord::Associations.constants.include?(:JoinDependency) ||
|
191
|
+
::ActiveRecord::Associations.constants.include?('JoinDependency')
|
192
|
+
end
|
162
193
|
end
|
163
194
|
end
|
@@ -4,10 +4,15 @@ module ThinkingSphinx
|
|
4
4
|
def add_internal_attributes_and_facets
|
5
5
|
add_internal_attribute :sphinx_internal_id, nil,
|
6
6
|
@model.primary_key_for_sphinx.to_sym
|
7
|
-
add_internal_attribute :class_crc, :integer, crc_column, true
|
8
7
|
add_internal_attribute :sphinx_deleted, :integer, "0"
|
9
|
-
|
10
|
-
|
8
|
+
add_internal_attribute :class_crc, :integer, crc_column, true
|
9
|
+
|
10
|
+
unless Riddle.loaded_version.to_i < 2
|
11
|
+
add_internal_attribute :sphinx_internal_class, :string, internal_class_column, true
|
12
|
+
add_internal_facet :sphinx_internal_class
|
13
|
+
else
|
14
|
+
add_internal_facet :class_crc
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
def add_internal_attribute(name, type, contents, facet = false)
|
@@ -61,7 +61,7 @@ module ThinkingSphinx
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def sql_select_clause(offset)
|
64
|
-
unique_id_expr = ThinkingSphinx.unique_id_expression(offset)
|
64
|
+
unique_id_expr = ThinkingSphinx.unique_id_expression(adapter, offset)
|
65
65
|
|
66
66
|
(
|
67
67
|
["#{@model.quoted_table_name}.#{quote_column(@model.primary_key_for_sphinx)} #{unique_id_expr} AS #{quote_column(@model.primary_key_for_sphinx)} "] +
|
@@ -130,6 +130,15 @@ module ThinkingSphinx
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
+
def internal_class_column
|
134
|
+
if @model.table_exists? &&
|
135
|
+
@model.column_names.include?(@model.inheritance_column)
|
136
|
+
adapter.quote_with_table(@model.inheritance_column)
|
137
|
+
else
|
138
|
+
"'#{@model.name}'"
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
133
142
|
def type_values
|
134
143
|
@model.connection.select_values <<-SQL
|
135
144
|
SELECT DISTINCT #{@model.inheritance_column}
|
@@ -298,184 +298,176 @@ describe ThinkingSphinx::Attribute do
|
|
298
298
|
end
|
299
299
|
|
300
300
|
describe "MVA with source query" do
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
end
|
301
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
302
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
303
|
+
:as => :tag_ids, :source => :query)
|
304
|
+
}
|
305
|
+
let(:adapter) { attribute.send(:adapter) }
|
307
306
|
|
308
307
|
it "should use a query" do
|
309
|
-
|
308
|
+
attribute.type_to_config.should == :sql_attr_multi
|
310
309
|
|
311
|
-
declaration, query =
|
310
|
+
declaration, query = attribute.config_value.split('; ')
|
312
311
|
declaration.should == "uint tag_ids from query"
|
313
|
-
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags`"
|
312
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags`"
|
314
313
|
end
|
315
314
|
end
|
316
315
|
|
317
316
|
describe "MVA with source query for a delta source" do
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
end
|
317
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
318
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
319
|
+
:as => :tag_ids, :source => :query)
|
320
|
+
}
|
321
|
+
let(:adapter) { attribute.send(:adapter) }
|
324
322
|
|
325
323
|
it "should use a query" do
|
326
|
-
|
324
|
+
attribute.type_to_config.should == :sql_attr_multi
|
327
325
|
|
328
|
-
declaration, query =
|
326
|
+
declaration, query = attribute.config_value(nil, true).split('; ')
|
329
327
|
declaration.should == "uint tag_ids from query"
|
330
|
-
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)"
|
328
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)"
|
331
329
|
end
|
332
330
|
end
|
333
331
|
|
334
332
|
describe "MVA via a HABTM association with a source query" do
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
end
|
333
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
334
|
+
[ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
|
335
|
+
:as => :link_ids, :source => :query)
|
336
|
+
}
|
337
|
+
let(:adapter) { attribute.send(:adapter) }
|
341
338
|
|
342
339
|
it "should use a ranged query" do
|
343
|
-
|
340
|
+
attribute.type_to_config.should == :sql_attr_multi
|
344
341
|
|
345
|
-
declaration, query =
|
342
|
+
declaration, query = attribute.config_value.split('; ')
|
346
343
|
declaration.should == "uint link_ids from query"
|
347
|
-
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people`"
|
344
|
+
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people`"
|
348
345
|
end
|
349
346
|
end
|
350
347
|
|
351
348
|
describe "MVA with ranged source query" do
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
end
|
349
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
350
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
351
|
+
:as => :tag_ids, :source => :ranged_query)
|
352
|
+
}
|
353
|
+
let(:adapter) { attribute.send(:adapter) }
|
358
354
|
|
359
355
|
it "should use a ranged query" do
|
360
|
-
|
356
|
+
attribute.type_to_config.should == :sql_attr_multi
|
361
357
|
|
362
|
-
declaration, query, range_query =
|
358
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
363
359
|
declaration.should == "uint tag_ids from ranged-query"
|
364
|
-
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"
|
360
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
|
365
361
|
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
366
362
|
end
|
367
363
|
end
|
368
364
|
|
369
365
|
describe "MVA with ranged source query for a delta source" do
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
end
|
366
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
367
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
368
|
+
:as => :tag_ids, :source => :ranged_query)
|
369
|
+
}
|
370
|
+
let(:adapter) { attribute.send(:adapter) }
|
376
371
|
|
377
372
|
it "should use a ranged query" do
|
378
|
-
|
373
|
+
attribute.type_to_config.should == :sql_attr_multi
|
379
374
|
|
380
|
-
declaration, query, range_query =
|
375
|
+
declaration, query, range_query = attribute.config_value(nil, true).split('; ')
|
381
376
|
declaration.should == "uint tag_ids from ranged-query"
|
382
|
-
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)"
|
377
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} 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)"
|
383
378
|
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
384
379
|
end
|
385
380
|
end
|
386
381
|
|
387
382
|
describe "MVA via a has-many :through with a ranged source query" do
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
end
|
383
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
384
|
+
[ThinkingSphinx::Index::FauxColumn.new(:football_teams, :id)],
|
385
|
+
:as => :football_team_ids, :source => :ranged_query)
|
386
|
+
}
|
387
|
+
let(:adapter) { attribute.send(:adapter) }
|
394
388
|
|
395
389
|
it "should use a ranged query" do
|
396
|
-
|
390
|
+
attribute.type_to_config.should == :sql_attr_multi
|
397
391
|
|
398
|
-
declaration, query, range_query =
|
392
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
399
393
|
declaration.should == "uint football_team_ids from ranged-query"
|
400
|
-
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"
|
394
|
+
query.should == "SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `tags`.`football_team_id` AS `football_team_ids` FROM `tags` WHERE `tags`.`person_id` >= $start AND `tags`.`person_id` <= $end"
|
401
395
|
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
402
396
|
end
|
403
397
|
end
|
404
398
|
|
405
399
|
describe "MVA via a has-many :through using a foreign key with a ranged source query" do
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
end
|
400
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
401
|
+
[ThinkingSphinx::Index::FauxColumn.new(:friends, :id)],
|
402
|
+
:as => :friend_ids, :source => :ranged_query)
|
403
|
+
}
|
404
|
+
let(:adapter) { attribute.send(:adapter) }
|
412
405
|
|
413
406
|
it "should use a ranged query" do
|
414
|
-
|
407
|
+
attribute.type_to_config.should == :sql_attr_multi
|
415
408
|
|
416
|
-
declaration, query, range_query =
|
409
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
417
410
|
declaration.should == "uint friend_ids from ranged-query"
|
418
|
-
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"
|
411
|
+
query.should == "SELECT `friendships`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `friendships`.`friend_id` AS `friend_ids` FROM `friendships` WHERE `friendships`.`person_id` >= $start AND `friendships`.`person_id` <= $end"
|
419
412
|
range_query.should == "SELECT MIN(`friendships`.`person_id`), MAX(`friendships`.`person_id`) FROM `friendships`"
|
420
413
|
end
|
421
414
|
end
|
422
415
|
|
423
416
|
describe "MVA via a HABTM with a ranged source query" do
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
end
|
417
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(@source,
|
418
|
+
[ThinkingSphinx::Index::FauxColumn.new(:links, :id)],
|
419
|
+
:as => :link_ids, :source => :ranged_query)
|
420
|
+
}
|
421
|
+
let(:adapter) { attribute.send(:adapter) }
|
430
422
|
|
431
423
|
it "should use a ranged query" do
|
432
|
-
|
424
|
+
attribute.type_to_config.should == :sql_attr_multi
|
433
425
|
|
434
|
-
declaration, query, range_query =
|
426
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
435
427
|
declaration.should == "uint link_ids from ranged-query"
|
436
|
-
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"
|
428
|
+
query.should == "SELECT `links_people`.`person_id` #{ThinkingSphinx.unique_id_expression adapter} AS `id`, `links_people`.`link_id` AS `link_ids` FROM `links_people` WHERE `links_people`.`person_id` >= $start AND `links_people`.`person_id` <= $end"
|
437
429
|
range_query.should == "SELECT MIN(`links_people`.`person_id`), MAX(`links_people`.`person_id`) FROM `links_people`"
|
438
430
|
end
|
439
431
|
end
|
440
432
|
|
441
433
|
describe "MVA via two has-many associations with a ranged source query" do
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
end
|
434
|
+
let(:index) { ThinkingSphinx::Index.new(Alpha) }
|
435
|
+
let(:source) { ThinkingSphinx::Source.new(index) }
|
436
|
+
let(:attribute) { ThinkingSphinx::Attribute.new(source,
|
437
|
+
[ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
|
438
|
+
:as => :gamma_values, :source => :ranged_query)
|
439
|
+
}
|
440
|
+
let(:adapter) { attribute.send(:adapter) }
|
450
441
|
|
451
442
|
it "should use a ranged query" do
|
452
|
-
|
443
|
+
attribute.type_to_config.should == :sql_attr_multi
|
453
444
|
|
454
|
-
declaration, query, range_query =
|
445
|
+
declaration, query, range_query = attribute.config_value.split('; ')
|
455
446
|
declaration.should == "uint gamma_values from ranged-query"
|
456
|
-
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"
|
447
|
+
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression adapter} 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"
|
457
448
|
range_query.should == "SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`"
|
458
449
|
end
|
459
450
|
end
|
460
451
|
|
461
452
|
describe "MVA via two has-many associations with a ranged source query for a delta source" do
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
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) }
|
469
460
|
|
470
|
-
|
461
|
+
before :each do
|
462
|
+
index.delta_object = ThinkingSphinx::Deltas::DefaultDelta.new index, index.local_options
|
471
463
|
end
|
472
464
|
|
473
465
|
it "should use a ranged query" do
|
474
|
-
|
466
|
+
attribute.type_to_config.should == :sql_attr_multi
|
475
467
|
|
476
|
-
declaration, query, range_query =
|
468
|
+
declaration, query, range_query = attribute.config_value(nil, true).split('; ')
|
477
469
|
declaration.should == "uint gamma_values from ranged-query"
|
478
|
-
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)"
|
470
|
+
query.should == "SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression adapter} 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)"
|
479
471
|
range_query.should == "SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`"
|
480
472
|
end
|
481
473
|
end
|