Skip to content

Commit

Permalink
🎁 BONUS: Display QA term instead of id in search results and facets
Browse files Browse the repository at this point in the history
This commit adds helper methods to department so that the value will display the terms instead of the id, in the catalog search index and facets. For example, "history" instead of "hst". You could write a spec for these methods for reassurance, and know that this is not the only way to accomplish this. With customizations the dev will often have to come up with solutions of their own.

:gift: BONUS: Display QA term instead of id in search results and facets

This commit adds helper methods to department so that the value will display the terms instead of the id, in the catalog search index and facets. For example, "history" instead of "hst". You could write a spec for these methods for reassurance, and know that this is not the only way to accomplish this. With customizations the dev will often have to come up with solutions of their own.
  • Loading branch information
ShanaLMoore committed Sep 20, 2023
1 parent f4535db commit bdc46a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def self.modified_field
config.add_facet_field 'resource_type_sim', label: "Resource Type", limit: 5
config.add_facet_field 'creator_sim', limit: 5
config.add_facet_field 'contributor_sim', label: "Contributor", limit: 5
config.add_facet_field 'department_sim', label: "Department", limit: 5, helper_method: :department_facets
config.add_facet_field 'keyword_sim', limit: 5
config.add_facet_field 'subject_sim', limit: 5
config.add_facet_field 'language_sim', limit: 5
Expand Down Expand Up @@ -109,7 +110,7 @@ def self.modified_field
config.add_index_field 'identifier_tesim', helper_method: :index_field_link, field_name: 'identifier'
config.add_index_field 'embargo_release_date_dtsi', label: "Embargo release date", helper_method: :human_readable_date
config.add_index_field 'lease_expiration_date_dtsi', label: "Lease expiration date", helper_method: :human_readable_date
config.add_index_field 'department_tesim', label: "Department", link_to_search: 'department_sim'
config.add_index_field 'department_tesim', label: "Department", helper_method: :department_links

# solr fields to be displayed in the show (single result) view
# The ordering of the field names is the order of the display
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/hyrax/override_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,14 @@ def search_state_with_facets(params, facet = {})
state.add_facet_params("#{facet.keys.first}_sim",
facet.values.first)
end

def department_facets(options)
DepartmentsService.label(options)
end

def department_links(options)
service = DepartmentsService
options[:value].map { |department_id| service.label(department_id) }.join(', ')
end
end
end

0 comments on commit bdc46a5

Please sign in to comment.