Method: Sunspot::Util.parse_json_facet

Defined in:
lib/sunspot/util.rb

.parse_json_facet(field_name, options, setup) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/sunspot/util.rb', line 191

def parse_json_facet(field_name, options, setup)
  field = setup.field(field_name)
  if options[:range] || options[:time_range]
    unless [Sunspot::Type::TimeType, Sunspot::Type::FloatType, Sunspot::Type::IntegerType ].find{|type| field.type.is_a?(type)}
      raise(
        ArgumentError,
        ':range can only be specified for date, time, or numeric fields'
      )
    end
    facet_klass = field.type.is_a?(Sunspot::Type::TimeType) ? Sunspot::Query::DateFieldJsonFacet : Sunspot::Query::RangeJsonFacet
    facet_klass.new(field, options, setup)
  else
    Sunspot::Query::FieldJsonFacet.new(field, options, setup)
  end
end