freelancing-god-thinking-sphinx 1.1.22 → 1.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/thinking_sphinx.rb
CHANGED
|
@@ -124,10 +124,10 @@ module ThinkingSphinx
|
|
|
124
124
|
# Special case is the multi-valued attribute that needs some
|
|
125
125
|
# extra configuration.
|
|
126
126
|
#
|
|
127
|
-
def config_value(offset = nil)
|
|
127
|
+
def config_value(offset = nil, delta = false)
|
|
128
128
|
if type == :multi
|
|
129
129
|
multi_config = include_as_association? ? "field" :
|
|
130
|
-
source_value(offset).gsub(/\s+/m, " ").strip
|
|
130
|
+
source_value(offset, delta).gsub(/\s+/m, " ").strip
|
|
131
131
|
"uint #{unique_name} from #{multi_config}"
|
|
132
132
|
else
|
|
133
133
|
unique_name
|
|
@@ -183,13 +183,20 @@ module ThinkingSphinx
|
|
|
183
183
|
|
|
184
184
|
private
|
|
185
185
|
|
|
186
|
-
def source_value(offset)
|
|
186
|
+
def source_value(offset, delta)
|
|
187
187
|
if is_string?
|
|
188
|
-
"#{query_source.to_s.dasherize}; #{columns.first.__name}"
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
return "#{query_source.to_s.dasherize}; #{columns.first.__name}"
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
query = query(offset)
|
|
192
|
+
|
|
193
|
+
if query_source == :ranged_query
|
|
194
|
+
query += query_clause
|
|
195
|
+
query += " AND #{query_delta.strip}" if delta
|
|
196
|
+
"ranged-query; #{query}; #{range_query}"
|
|
191
197
|
else
|
|
192
|
-
|
|
198
|
+
query += "WHERE #{query_delta.strip}" if delta
|
|
199
|
+
"query; #{query}"
|
|
193
200
|
end
|
|
194
201
|
end
|
|
195
202
|
|
|
@@ -211,6 +218,15 @@ FROM #{quote_table_name base_assoc.table} #{association_joins}
|
|
|
211
218
|
"WHERE #{foreign_key} >= $start AND #{foreign_key} <= $end"
|
|
212
219
|
end
|
|
213
220
|
|
|
221
|
+
def query_delta
|
|
222
|
+
foreign_key = foreign_key_for_mva base_association_for_mva
|
|
223
|
+
<<-SQL
|
|
224
|
+
#{foreign_key} IN (SELECT #{quote_column model.primary_key}
|
|
225
|
+
FROM #{model.quoted_table_name}
|
|
226
|
+
WHERE #{@source.index.delta_object.clause(model, true)})
|
|
227
|
+
SQL
|
|
228
|
+
end
|
|
229
|
+
|
|
214
230
|
def range_query
|
|
215
231
|
assoc = base_association_for_mva
|
|
216
232
|
foreign_key = foreign_key_for_mva assoc
|
|
@@ -8,7 +8,7 @@ module ThinkingSphinx
|
|
|
8
8
|
|
|
9
9
|
attr_accessor :model, :fields, :attributes, :conditions, :groupings,
|
|
10
10
|
:options
|
|
11
|
-
attr_reader :base
|
|
11
|
+
attr_reader :base, :index
|
|
12
12
|
|
|
13
13
|
def initialize(index, options = {})
|
|
14
14
|
@index = index
|
|
@@ -56,7 +56,7 @@ module ThinkingSphinx
|
|
|
56
56
|
source.parent = "#{name}_core_#{index}"
|
|
57
57
|
|
|
58
58
|
set_source_database_settings source
|
|
59
|
-
set_source_attributes source, offset
|
|
59
|
+
set_source_attributes source, offset, true
|
|
60
60
|
set_source_sql source, offset, true
|
|
61
61
|
|
|
62
62
|
source
|
|
@@ -89,9 +89,9 @@ module ThinkingSphinx
|
|
|
89
89
|
source.sql_sock = config[:socket]
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
def set_source_attributes(source, offset)
|
|
92
|
+
def set_source_attributes(source, offset, delta = false)
|
|
93
93
|
attributes.each do |attrib|
|
|
94
|
-
source.send(attrib.type_to_config) << attrib.config_value(offset)
|
|
94
|
+
source.send(attrib.type_to_config) << attrib.config_value(offset, delta)
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -4,6 +4,8 @@ describe ThinkingSphinx::Attribute do
|
|
|
4
4
|
before :each do
|
|
5
5
|
@index = ThinkingSphinx::Index.new(Person)
|
|
6
6
|
@source = ThinkingSphinx::Source.new(@index)
|
|
7
|
+
|
|
8
|
+
@index.delta_object = ThinkingSphinx::Deltas::DefaultDelta.new @index, @index.local_options
|
|
7
9
|
end
|
|
8
10
|
|
|
9
11
|
describe '#initialize' do
|
|
@@ -232,6 +234,23 @@ describe ThinkingSphinx::Attribute do
|
|
|
232
234
|
end
|
|
233
235
|
end
|
|
234
236
|
|
|
237
|
+
describe "MVA with source query for a delta source" do
|
|
238
|
+
before :each do
|
|
239
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
240
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
|
241
|
+
:as => :tag_ids, :source => :query
|
|
242
|
+
)
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it "should use a query" do
|
|
246
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
247
|
+
|
|
248
|
+
declaration, query = @attribute.config_value(nil, true).split('; ')
|
|
249
|
+
declaration.should == "uint tag_ids from query"
|
|
250
|
+
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)"
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
235
254
|
describe "MVA via a HABTM association with a source query" do
|
|
236
255
|
before :each do
|
|
237
256
|
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
@@ -267,6 +286,24 @@ describe ThinkingSphinx::Attribute do
|
|
|
267
286
|
end
|
|
268
287
|
end
|
|
269
288
|
|
|
289
|
+
describe "MVA with ranged source query for a delta source" do
|
|
290
|
+
before :each do
|
|
291
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
292
|
+
[ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
|
|
293
|
+
:as => :tag_ids, :source => :ranged_query
|
|
294
|
+
)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
it "should use a ranged query" do
|
|
298
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
299
|
+
|
|
300
|
+
declaration, query, range_query = @attribute.config_value(nil, true).split('; ')
|
|
301
|
+
declaration.should == "uint tag_ids from ranged-query"
|
|
302
|
+
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)"
|
|
303
|
+
range_query.should == "SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`"
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
|
|
270
307
|
describe "MVA via a has-many :through with a ranged source query" do
|
|
271
308
|
before :each do
|
|
272
309
|
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
@@ -341,6 +378,28 @@ describe ThinkingSphinx::Attribute do
|
|
|
341
378
|
end
|
|
342
379
|
end
|
|
343
380
|
|
|
381
|
+
describe "MVA via two has-many associations with a ranged source query for a delta source" do
|
|
382
|
+
before :each do
|
|
383
|
+
@index = ThinkingSphinx::Index.new(Alpha)
|
|
384
|
+
@source = ThinkingSphinx::Source.new(@index)
|
|
385
|
+
@attribute = ThinkingSphinx::Attribute.new(@source,
|
|
386
|
+
[ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
|
|
387
|
+
:as => :gamma_values, :source => :ranged_query
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
@index.delta_object = ThinkingSphinx::Deltas::DefaultDelta.new @index, @index.local_options
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
it "should use a ranged query" do
|
|
394
|
+
@attribute.type_to_config.should == :sql_attr_multi
|
|
395
|
+
|
|
396
|
+
declaration, query, range_query = @attribute.config_value(nil, true).split('; ')
|
|
397
|
+
declaration.should == "uint gamma_values from ranged-query"
|
|
398
|
+
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)"
|
|
399
|
+
range_query.should == "SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`"
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
|
|
344
403
|
describe "with custom queries" do
|
|
345
404
|
before :each do
|
|
346
405
|
index = CricketTeam.sphinx_indexes.first
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: freelancing-god-thinking-sphinx
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.23
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pat Allan
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-06-
|
|
12
|
+
date: 2009-06-28 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|