# File lib/thinking_sphinx/facet.rb, line 24 def self.attribute_name_for(name) name.to_s == 'class' ? 'class_crc' : "#{name}_facet" end
# File lib/thinking_sphinx/facet.rb, line 28 def self.attribute_name_from_value(name, value) case value when String attribute_name_for(name) when Array if value.all? { |val| val.is_a?(Integer) } name else attribute_name_for(name) end else name end end
# File lib/thinking_sphinx/facet.rb, line 14 def self.name_for(facet) case facet when Facet facet.name when String, Symbol return :class if facet.to_s == 'sphinx_internal_class' facet.to_s.gsub(%r(_facet|_crc)$/,'').to_sym end end
# File lib/thinking_sphinx/facet.rb, line 5 def initialize(property, value_source = nil) @property = property @value_source = value_source if property.columns.length != 1 raise "Can't translate Facets on multiple-column field or attribute" end end
# File lib/thinking_sphinx/facet.rb, line 43 def self.translate?(property) return true if property.is_a?(Field) case property.type when :string true when :integer, :boolean, :datetime, :float false when :multi !property.all_ints? end end
# File lib/thinking_sphinx/facet.rb, line 60 def attribute_name if translate? Facet.attribute_name_for(@property.unique_name) else @property.unique_name.to_s end end
# File lib/thinking_sphinx/facet.rb, line 76 def float? @property.type == :float end
# File lib/thinking_sphinx/facet.rb, line 56 def name property.unique_name end
# File lib/thinking_sphinx/facet.rb, line 94 def to_s name end
# File lib/thinking_sphinx/facet.rb, line 68 def translate? Facet.translate?(@property) end
# File lib/thinking_sphinx/facet.rb, line 72 def type @property.is_a?(Field) ? :string : @property.type end
# File lib/thinking_sphinx/facet.rb, line 80 def value(object, attribute_hash) attribute_value = attribute_hash['@groupby'] return translate(object, attribute_value) if translate? || float? case @property.type when :datetime Time.at(attribute_value) when :boolean attribute_value > 0 else attribute_value end end