freelancing-god-thinking-sphinx 1.2.10 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
+ :patch: 11
2
3
  :major: 1
3
4
  :minor: 2
4
- :patch: 10
@@ -9,8 +9,7 @@ module ThinkingSphinx
9
9
  (@reflection.klass.sphinx_indexes || []).each do |index|
10
10
  attribute = index.attributes.detect { |attrib|
11
11
  attrib.columns.length == 1 &&
12
- attrib.columns.first.__name == foreign_key.to_sym &&
13
- attrib.columns.first.__stack == stack
12
+ attrib.columns.first.__name == foreign_key.to_sym
14
13
  }
15
14
  break if attribute
16
15
  end
@@ -162,11 +162,12 @@ module ThinkingSphinx
162
162
  end
163
163
 
164
164
  if base_type == :string && @crc
165
- :integer
165
+ base_type = :integer
166
166
  else
167
- @crc = false
168
- base_type
167
+ @crc = false unless base_type == :multi && is_many_strings? && @crc
169
168
  end
169
+
170
+ base_type
170
171
  end
171
172
  end
172
173
 
@@ -189,6 +190,10 @@ module ThinkingSphinx
189
190
  all_of_type?(:datetime, :date, :timestamp)
190
191
  end
191
192
 
193
+ def all_strings?
194
+ all_of_type?(:string, :text)
195
+ end
196
+
192
197
  private
193
198
 
194
199
  def source_value(offset, delta)
@@ -286,6 +291,10 @@ WHERE #{@source.index.delta_object.clause(model, true)})
286
291
  def is_many_datetimes?
287
292
  is_many? && all_datetimes?
288
293
  end
294
+
295
+ def is_many_strings?
296
+ is_many? && all_strings?
297
+ end
289
298
 
290
299
  def type_from_database
291
300
  klass = @associations.values.flatten.first ?
@@ -91,18 +91,29 @@ module ThinkingSphinx
91
91
  private
92
92
 
93
93
  def translate(object, attribute_value)
94
- column.__stack.each { |method|
95
- return nil unless object = object.send(method)
96
- }
97
- if object.is_a?(Array)
98
- object.collect { |item| item.send(column.__name) }.detect { |item|
94
+ objects = source_objects(object)
95
+ return nil if objects.nil? || objects.empty?
96
+
97
+ if objects.length > 1
98
+ objects.collect { |item| item.send(column.__name) }.detect { |item|
99
99
  item.to_crc32 == attribute_value
100
100
  }
101
101
  else
102
- object.send(column.__name)
102
+ objects.first.send(column.__name)
103
103
  end
104
104
  end
105
105
 
106
+ def source_objects(object)
107
+ column.__stack.each { |method|
108
+ object = Array(object).collect { |item|
109
+ item.send(method)
110
+ }.flatten.compact
111
+
112
+ return nil if object.empty?
113
+ }
114
+ Array(object)
115
+ end
116
+
106
117
  def column
107
118
  @property.columns.first
108
119
  end
@@ -265,6 +265,41 @@ describe ThinkingSphinx::Attribute do
265
265
  end
266
266
  end
267
267
 
268
+ describe '#all_strings?' do
269
+ it "should return true if all columns are strings or text" do
270
+ attribute = ThinkingSphinx::Attribute.new(@source,
271
+ [ ThinkingSphinx::Index::FauxColumn.new(:first_name),
272
+ ThinkingSphinx::Index::FauxColumn.new(:last_name) ]
273
+ )
274
+ attribute.model = Person
275
+ attribute.columns.each { |col| attribute.associations[col] = [] }
276
+
277
+ attribute.should be_all_strings
278
+ end
279
+
280
+ it "should return false if only some columns are strings" do
281
+ attribute = ThinkingSphinx::Attribute.new(@source,
282
+ [ ThinkingSphinx::Index::FauxColumn.new(:id),
283
+ ThinkingSphinx::Index::FauxColumn.new(:first_name) ]
284
+ )
285
+ attribute.model = Person
286
+ attribute.columns.each { |col| attribute.associations[col] = [] }
287
+
288
+ attribute.should_not be_all_strings
289
+ end
290
+
291
+ it "should return true if all columns are not strings" do
292
+ attribute = ThinkingSphinx::Attribute.new(@source,
293
+ [ ThinkingSphinx::Index::FauxColumn.new(:id),
294
+ ThinkingSphinx::Index::FauxColumn.new(:parent_id) ]
295
+ )
296
+ attribute.model = Person
297
+ attribute.columns.each { |col| attribute.associations[col] = [] }
298
+
299
+ attribute.should_not be_all_strings
300
+ end
301
+ end
302
+
268
303
  describe "MVA with source query" do
269
304
  before :each do
270
305
  @attribute = ThinkingSphinx::Attribute.new(@source,
@@ -299,6 +299,18 @@ describe ThinkingSphinx::Facet do
299
299
 
300
300
  @facet.value(friendship, 1).should be_nil
301
301
  end
302
+
303
+ it "should return multi-level association values" do
304
+ person = Person.find(:first)
305
+ tag = person.tags.build(:name => 'buried')
306
+ friendship = Friendship.new(:person => person)
307
+
308
+ field = ThinkingSphinx::Field.new(
309
+ @source, ThinkingSphinx::Index::FauxColumn.new(:person, :tags, :name)
310
+ )
311
+ ThinkingSphinx::Facet.new(field).value(friendship, 'buried'.to_crc32).
312
+ should == 'buried'
313
+ end
302
314
  end
303
315
 
304
316
  describe 'for float attributes' do
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.2.10
4
+ version: 1.2.11
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-09-12 00:00:00 -07:00
12
+ date: 2009-09-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -104,7 +104,7 @@ files:
104
104
  - vendor/riddle/lib/riddle/configuration/sql_source.rb
105
105
  - vendor/riddle/lib/riddle/configuration/xml_source.rb
106
106
  - vendor/riddle/lib/riddle/controller.rb
107
- has_rdoc: true
107
+ has_rdoc: false
108
108
  homepage: http://ts.freelancing-gods.com
109
109
  post_install_message: |+
110
110
  With the release of Thinking Sphinx 1.1.18, there is one important change to
@@ -144,7 +144,7 @@ requirements: []
144
144
  rubyforge_project:
145
145
  rubygems_version: 1.2.0
146
146
  signing_key:
147
- specification_version: 2
147
+ specification_version: 3
148
148
  summary: A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching.
149
149
  test_files:
150
150
  - spec/lib/thinking_sphinx/active_record/delta_spec.rb