Skip to content

Commit

Permalink
Allow configured advanced search facets & home facets to be different…
Browse files Browse the repository at this point in the history
…, refine advanced config. Fixes TD-1394 & TD-1263..

- Remove Subject (About Topic) facet from Advanced (it was never present before due to # of unique values in a -1 limit being infeasable to request from Solr)
- Add Physical Media facet to advanced search
- Ensure the :only_home_facets filter is removed from the advanced search builder processor chain
  • Loading branch information
seanaery committed Dec 12, 2024
1 parent 019dd06 commit 6b41fc1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
19 changes: 12 additions & 7 deletions lib/trln_argon/controller_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,25 @@ module ControllerOverride

# default advanced config values
config.advanced_search ||= Blacklight::OpenStructWithHashAccess.new
# BL7
config.advanced_search.enabled = true
config.advanced_search[:url_key] ||= 'advanced'
config.advanced_search[:form_solr_parameters] ||= {
# NOTE: You will not get any facets back
# on the advanced search page
# unless defType is set to lucene.
'defType' => 'lucene',
'facet.field' => [TrlnArgon::Fields::AVAILABLE_FACET.to_s,
TrlnArgon::Fields::ACCESS_TYPE_FACET.to_s,
'facet.field' => [TrlnArgon::Fields::ACCESS_TYPE_FACET.to_s,
TrlnArgon::Fields::AVAILABLE_FACET.to_s,
TrlnArgon::Fields::LOCATION_HIERARCHY_FACET.to_s,
TrlnArgon::Fields::RESOURCE_TYPE_FACET.to_s,
TrlnArgon::Fields::PHYSICAL_MEDIA_FACET.to_s,
TrlnArgon::Fields::CALL_NUMBER_FACET.to_s,
TrlnArgon::Fields::LANGUAGE_FACET.to_s,
TrlnArgon::Fields::DATE_CATALOGED_FACET.to_s],
'f.resource_type_f.facet.limit' => -1, # return all resource type values
'f.language_f.facet.limit' => -1, # return all language facet values
'f.date_cataloged_dt.facet.limit' => -1, # return all date facet values
'f.resource_type_f.facet.limit' => -1,
'f.physical_media_f.facet.limit' => -1,
'f.language_f.facet.limit' => -1,
'f.date_cataloged_dt.facet.limit' => -1,
'facet.limit' => -1, # return all facet values
'facet.sort' => 'index' # sort by byte order of values
}
Expand Down Expand Up @@ -213,18 +216,20 @@ module ControllerOverride
config.add_facet_field TrlnArgon::Fields::RESOURCE_TYPE_FACET.to_s,
label: TrlnArgon::Fields::RESOURCE_TYPE_FACET.label,
limit: true,
sort: 'count',
collapse: false,
advanced_search_component: TrlnArgon::AdvancedSearchFacetFieldComponent
config.add_facet_field TrlnArgon::Fields::PHYSICAL_MEDIA_FACET.to_s,
label: TrlnArgon::Fields::PHYSICAL_MEDIA_FACET.label,
limit: true,
sort: 'count',
collapse: false,
advanced_search_component: TrlnArgon::AdvancedSearchFacetFieldComponent
config.add_facet_field TrlnArgon::Fields::SUBJECT_TOPICAL_FACET.to_s,
label: TrlnArgon::Fields::SUBJECT_TOPICAL_FACET.label,
limit: true,
collapse: false,
advanced_search_component: TrlnArgon::AdvancedSearchFacetFieldComponent
include_in_advanced_search: false
config.add_facet_field TrlnArgon::Fields::CALL_NUMBER_FACET.to_s,
label: TrlnArgon::Fields::CALL_NUMBER_FACET.label,
limit: 4500,
Expand Down
14 changes: 12 additions & 2 deletions lib/trln_argon/controller_override/solr_caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ def cached_advanced_index
cache_state = 'cacheable'
Rails.cache.fetch(adv_index_cache_key, expires_in: solr_cache_exp_time) do
cache_state = 'cache miss'
blacklight_advanced_search_form_search_service.search_results
advanced_search_form_data
end
else # not cacheable
blacklight_advanced_search_form_search_service.search_results
advanced_search_form_data
end

log_cache_state(cache_state, adv_index_cache_key)
Expand All @@ -72,6 +72,16 @@ def solr_cache_exp_time
num_string.to_i.send(time_unit)
end

# We need to ensure that the query that populates the advanced search
# form (which has no search params) facets isn't limited to just the homepage
# facets (TD-1263).
def advanced_search_form_data
@advanced_search_form_data ||=
blacklight_advanced_search_form_search_service.search_results do |builder|
builder.except(:only_home_facets)
end
end

def log_cache_state(cache_state, cache_key)
return unless cache_state && cache_key

Expand Down

0 comments on commit 6b41fc1

Please sign in to comment.