Class: Elasticsearch::FacetedSearch::FacetItem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, object) ⇒ FacetItem

Returns a new instance of FacetItem.



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

def initialize(group, object)
  self.group = group
  self.object = OpenStruct.new(object)
end

Instance Attribute Details

#groupObject

Returns the value of attribute group.



8
9
10
# File 'lib/elasticsearch/faceted_search/facet_item.rb', line 8

def group
  @group
end

#objectObject

Returns the value of attribute object.



8
9
10
# File 'lib/elasticsearch/faceted_search/facet_item.rb', line 8

def object
  @object
end

Instance Method Details

#idObject

delegate :operator_mappings, :operator, :key, :selected_values, :group_params, :type, to: :group delegate :term, :count, to: :object



15
16
17
# File 'lib/elasticsearch/faceted_search/facet_item.rb', line 15

def id
  object.id.to_s
end

#params_forObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/elasticsearch/faceted_search/facet_item.rb', line 28

def params_for
  prefix = selected? ? :remove : :add

  case type
    when 'multivalue'     then send(:"#{prefix}_multivalue")
    when 'multivalue_and' then send(:"#{prefix}_multivalue", :and)
    when 'multivalue_or'  then send(:"#{prefix}_multivalue", :or)
    when 'exclusive_or'   then send(:"#{prefix}_singlevalue")
    # else                  raise UnknownSelectableType.new "Unknown selectable type #{selectable_type} for #{@type}"
  end
end

#selected?Boolean

Returns:

  • (Boolean)


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

def selected?
  @selected ||= Array(group_params).include?(id)
end