Module: HandleFaceting

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController, FacetFilter
Defined in:
public/app/controllers/concerns/handle_faceting.rb

Instance Method Summary collapse

Instance Method Details

#fetch_only_facets(query, facets_array, include_zero) ⇒ Object

does the fetches when you only want facet information



6
7
8
9
10
11
12
13
14
15
16
17
# File 'public/app/controllers/concerns/handle_faceting.rb', line 6

def fetch_only_facets(query, facets_array, include_zero)
#    Rails.logger.debug("Finding facets for query '#{query}'")
  criteria = {}
  criteria[:page_size] = 1
  criteria['facet[]'] = facets_array
  criteria['facet.mincount'] = 1 if !include_zero
  data = archivesspace.search(query, 1, criteria) || {}
  faceting = {}
  if !data['facets'].blank? && !data['facets']['facet_fields'].blank?
    faceting = data['facets']['facet_fields']
  end
end

#get_pretty_facet_value(k, v) ⇒ Object

bury the mess!



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'public/app/controllers/concerns/handle_faceting.rb', line 34

def get_pretty_facet_value(k, v)
  pv = strip_mixed_content(v)
  if k == 'primary_type'
    pv = I18n.t("#{v}._singular")
  elsif k == 'langcode'
    # Lookup three-letter language codes
    pv = I18n.t("enumerations.language_iso639_2.#{v}", :default => v)
  elsif k == 'type_enum_s'
    # Lookup container type
    pv = I18n.t("enumerations.container_type.#{v}", :default => v)
  elsif %w(repository used_within_published_repository).include?(k)
    repos = Repository.get_repos
    if repos[v].nil?
      pv = v
    else
      pv = repos[v]['name'] || v
    end
  end
  pv
end

#strip_facets(facets_array, min, total_hits = nil) ⇒ Object

strip out: facets with counts less than input minimum or equal to the total hits, facets of form “ead/ arch*” returns a hash with the text of the facet as the key, count as the value



22
23
24
25
26
27
28
29
30
31
# File 'public/app/controllers/concerns/handle_faceting.rb', line 22

def strip_facets(facets_array, min, total_hits = nil)
  facets = {}
  facets_array.each_slice(2) do |t, ct|
    next if ct < min
    next if total_hits && ct == total_hits
    next if t.start_with?("ead/ archdesc/ ")
    facets[t] = ct
  end
  facets
end