Module: HandleFaceting

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController, Facet, 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!



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

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, type, 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
# File 'public/app/controllers/concerns/handle_faceting.rb', line 22

def strip_facets(facets_array, min, type, total_hits = nil)
  facets = []
  facets_array.each_slice(2) do |facet_key, facet_count|
    facets << Facet.new(type, facet_key, facet_count)
  end
  facets.reject! { |f| f.count < min || f.count == total_hits }
  facets.sort_by! { |f| f.label } if AppConfig[:pui_display_facets_alpha]
  facets
end