Permalink
Browse files

Fixing MVA string facets sourced from attributes, not fields.

  • Loading branch information...
1 parent 8cffc1f commit 993af0bffdf556a5127f25398fecccf514b69850 @pat pat committed Sep 13, 2009
Showing with 47 additions and 3 deletions.
  1. +12 −3 lib/thinking_sphinx/attribute.rb
  2. +35 −0 spec/lib/thinking_sphinx/attribute_spec.rb
@@ -162,11 +162,12 @@ def type
end
if base_type == :string && @crc
- :integer
+ base_type = :integer
else
- @crc = false
- base_type
+ @crc = false unless base_type == :multi && is_many_strings? && @crc
end
+
+ base_type
end
end
@@ -189,6 +190,10 @@ def all_datetimes?
all_of_type?(:datetime, :date, :timestamp)
end
+ def all_strings?
+ all_of_type?(:string, :text)
+ end
+
private
def source_value(offset, delta)
@@ -286,6 +291,10 @@ def is_many_ints?
def is_many_datetimes?
is_many? && all_datetimes?
end
+
+ def is_many_strings?
+ is_many? && all_strings?
+ end
def type_from_database
klass = @associations.values.flatten.first ?
@@ -265,6 +265,41 @@
end
end
+ describe '#all_strings?' do
+ it "should return true if all columns are strings or text" do
+ attribute = ThinkingSphinx::Attribute.new(@source,
+ [ ThinkingSphinx::Index::FauxColumn.new(:first_name),
+ ThinkingSphinx::Index::FauxColumn.new(:last_name) ]
+ )
+ attribute.model = Person
+ attribute.columns.each { |col| attribute.associations[col] = [] }
+
+ attribute.should be_all_strings
+ end
+
+ it "should return false if only some columns are strings" do
+ attribute = ThinkingSphinx::Attribute.new(@source,
+ [ ThinkingSphinx::Index::FauxColumn.new(:id),
+ ThinkingSphinx::Index::FauxColumn.new(:first_name) ]
+ )
+ attribute.model = Person
+ attribute.columns.each { |col| attribute.associations[col] = [] }
+
+ attribute.should_not be_all_strings
+ end
+
+ it "should return true if all columns are not strings" do
+ attribute = ThinkingSphinx::Attribute.new(@source,
+ [ ThinkingSphinx::Index::FauxColumn.new(:id),
+ ThinkingSphinx::Index::FauxColumn.new(:parent_id) ]
+ )
+ attribute.model = Person
+ attribute.columns.each { |col| attribute.associations[col] = [] }
+
+ attribute.should_not be_all_strings
+ end
+ end
+
describe "MVA with source query" do
before :each do
@attribute = ThinkingSphinx::Attribute.new(@source,

0 comments on commit 993af0b

Please sign in to comment.