Class: Sunspot::Query::RangeJsonFacet

Inherits:
AbstractJsonFieldFacet show all
Defined in:
lib/sunspot/query/range_json_facet.rb

Direct Known Subclasses

DateFieldJsonFacet

Constant Summary collapse

SECONDS_IN_DAY =
86400

Constants inherited from AbstractJsonFieldFacet

AbstractJsonFieldFacet::DISTINCT_STRATEGIES

Instance Attribute Summary

Attributes inherited from AbstractJsonFieldFacet

#field

Instance Method Summary collapse

Methods inherited from AbstractJsonFieldFacet

#get_params, #init_params, #to_params

Constructor Details

#initialize(field, options, setup) ⇒ RangeJsonFacet

Returns a new instance of RangeJsonFacet.

Raises:

  • (Exception)


7
8
9
10
11
12
13
14
15
# File 'lib/sunspot/query/range_json_facet.rb', line 7

def initialize(field, options, setup)
  options[:range] ||= options[:time_range]
  raise Exception.new("Need to specify a range") if options[:range].nil? && options[:time_range].nil?
  @start = options[:range].first
  @end = options[:range].last
  @gap = options[:gap] || SECONDS_IN_DAY
  @other = options[:other]
  super
end

Instance Method Details

#field_name_with_local_paramsObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sunspot/query/range_json_facet.rb', line 17

def field_name_with_local_params
  {
    @field.name => {
      type: 'range',
      field: @field.indexed_name,
      start: @field.to_indexed(@start),
      end: @field.to_indexed(@end),
      gap: @gap,
      other: @other
    }.merge!(init_params)
  }
end