Module: SupplejackApi::FacetsHelper

Defined in:
app/helpers/supplejack_api/facets_helper.rb

Class Method Summary collapse

Class Method Details

.get_list_of_facet_values(facet_key) ⇒ Object

Given a facet key, returns list of facets under that key



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/supplejack_api/facets_helper.rb', line 8

def get_list_of_facet_values(facet_key)
  facets_list = []
  facets_page = 1

  loop do
    s = RecordSearch.new(facets: facet_key, facets_per_page: 150, facets_page: facets_page)
    # HACK: We override SearchSerializable#facets_list in the api_app to
    # replace :display_collection with :primary_collection, this transparently fixes it
    mappings = { primary_collection: :display_collection }
    facets = Hash[s.facets_hash.map { |k, v| [mappings[k] || k, v] }][facet_key.to_sym]

    # Gone past last page of facets
    break if facets.length.zero?

    facets_list << facets.keys
    facets_page += 1
  end

  facets_list.flatten
end