Skip to content

Commit

Permalink
Added dynamic facets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Terrell committed Mar 21, 2014
1 parent 928aa4e commit e39b8b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions config/locales/oregondigital.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ en:
catalog:
show:
title: Title
facet:
subject: Topic
location: Region
set: Collection
23 changes: 15 additions & 8 deletions lib/oregon_digital/catalog/facets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,24 @@ module Facets
#
# :show may be set to false if you don't want the facet to be drawn in the
# facet bar
config.add_facet_field solr_name('desc_metadata__hasFormat',:facetable), :label => 'Format'
config.add_facet_field solr_name('desc_metadata__date', :facetable), :label => 'Publication Year', :single => true
config.add_facet_field solr_name('desc_metadata__subject', :facetable), :label => 'Topic', :limit => 20, :helper_method => :controlled_view
config.add_facet_field solr_name('desc_metadata__subject_label', :facetable), :show => false
config.add_facet_field solr_name('desc_metadata__location', :facetable), :label => 'Region', :helper_method => :controlled_view
config.add_facet_field solr_name('desc_metadata__location_label', :facetable), :show => false
config.add_facet_field solr_name('desc_metadata__set', :facetable), :label => 'Collection', :helper_method => :controlled_view
config.add_facet_field solr_name('desc_metadata__set_label', :facetable), :show => false
controlled_vocabularies.each do |key|
config.add_facet_field solr_name("desc_metadata__#{key}", :facetable), :helper_method => :controlled_view, :label => I18n.t("oregondigital.catalog.facet.#{key}",key.humanize)
config.add_facet_field solr_name("desc_metadata__#{key}_label", :facetable), :show => false
end
config.add_facet_fields_to_solr_request!
end
end

module ClassMethods
def controlled_vocabularies
Datastream::OregonRDF.properties.map do |key, property|
instance = property[:class_name].new if property[:class_name]
if instance && (instance.class.ancestors.include?(OregonDigital::RDF::Controlled) || (instance.respond_to?(:resource) && instance.resource.class.ancestors.include?(OregonDigital::RDF::Controlled)))
key
end
end.compact
end
end
end
end
end

0 comments on commit e39b8b0

Please sign in to comment.