Class: Solr::Query::Request::Facet

Inherits:
Object
  • Object
show all
Includes:
Support::SchemaHelper
Defined in:
lib/solr/query/request/facet.rb

Constant Summary collapse

TERMS_TYPE =
:terms
QUERY_TYPE =
:query
RANGE_TYPE =
:range

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::SchemaHelper

#solarize_field

Constructor Details

#initialize(field:, type:, name: nil, value: nil, filters: [], subfacets: [], options: {}) ⇒ Facet

Returns a new instance of Facet.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/solr/query/request/facet.rb', line 22

def initialize(field:, type:, name: nil, value: nil, filters: [], subfacets: [], options: {})
  if options[:limit].nil? && type == TERMS_TYPE
    raise ArgumentError, "Need to specify :limit option value for 'terms' facet type"
  end

  if options.values_at(:gap, :lower_bound, :upper_bound).any?(&:nil?) && type == RANGE_TYPE
    raise ArgumentError, "Need to specify :lower_bound, :upper_bound, :gap option values for 'range' facet type"
  end

  @field       = field
  @name        = name || field
  @type        = type
  @value       = value
  @filters     = filters
  @subfacets   = subfacets
  @limit       = options[:limit].to_i
  @gap         = options[:gap]
  @lower_bound = options[:lower_bound]
  @upper_bound = options[:upper_bound]
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def field
  @field
end

#filtersObject (readonly)

Returns the value of attribute filters.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def filters
  @filters
end

#gapObject (readonly)

Returns the value of attribute gap.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def gap
  @gap
end

#limitObject (readonly)

Returns the value of attribute limit.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def limit
  @limit
end

#lower_boundObject (readonly)

Returns the value of attribute lower_bound.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def lower_bound
  @lower_bound
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def name
  @name
end

#subfacetsObject (readonly)

Returns the value of attribute subfacets.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def subfacets
  @subfacets
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def type
  @type
end

#upper_boundObject (readonly)

Returns the value of attribute upper_bound.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def upper_bound
  @upper_bound
end

#valueObject (readonly)

Returns the value of attribute value.



11
12
13
# File 'lib/solr/query/request/facet.rb', line 11

def value
  @value
end

Instance Method Details

#to_solr_hObject



43
44
45
46
47
# File 'lib/solr/query/request/facet.rb', line 43

def to_solr_h
  return { name.to_s => value } if type == QUERY_TYPE && value

  default_solr_h
end