Class: Elasticsearch::FacetedSearch::FacetGroup

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/elasticsearch/faceted_search/facet_group.rb

Constant Summary collapse

OPERATOR_MAPPING =
{
  :and => ',',
  :or => '|'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search, key, objects) ⇒ FacetGroup

delegate :class_facets, :execution_type, :search_params, to: :search



18
19
20
21
22
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 18

def initialize(search, key, objects)
  self.search = search
  self.key = key.to_sym
  self.objects = hit_count_mapping(objects['terms'])
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



13
14
15
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 13

def key
  @key
end

#objectsObject

Returns the value of attribute objects.



13
14
15
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 13

def objects
  @objects
end

#searchObject

Returns the value of attribute search.



13
14
15
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 13

def search
  @search
end

Instance Method Details

#group_paramsObject



39
40
41
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 39

def group_params
  group_params_string.split(operator).dup
end

#group_params_stringObject



43
44
45
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 43

def group_params_string
  search_params.fetch(key, '')
end

#itemsObject



24
25
26
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 24

def items
  @items ||= build_items
end

#operatorObject

Returns the string value ‘,’ or ‘|’



55
56
57
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 55

def operator
  @operator ||= operator_mappings(operator_for)
end

#operator_mappings(i = nil) ⇒ Object



59
60
61
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 59

def operator_mappings(i=nil)
  OPERATOR_MAPPING.fetch(i, nil)
end

#selected_valuesObject



34
35
36
37
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 34

def selected_values
  v = search_params.fetch(key, '')
  operator ? v.split(operator).map(&:downcase) : v.downcase
end

#titleObject



28
29
30
31
32
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 28

def title
  class_facets[key][:title]
rescue
  key.to_s.humanize
end

#typeObject



47
48
49
50
51
# File 'lib/elasticsearch/faceted_search/facet_group.rb', line 47

def type
  class_facets[key][:type]
rescue
  nil
end