Skip to content

Commit

Permalink
Merge pull request #4129 from pulibrary/i4105_language_dropdown
Browse files Browse the repository at this point in the history
Make it so new advanced search includes all facet dropdowns
  • Loading branch information
christinach authored Aug 23, 2024
2 parents 912308b + 049343c commit c135914
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</div>
<% end %>
<div class="form-group advanced-search-facet row">
<%= label_tag pub_date_field.parameterize, :class => "col-sm-4 control-label advanced-facet-label" do %>Publication Year<% end %>
<%= label_tag pub_date_field.parameterize, :class => "col-sm-4 control-label advanced-facet-label" do %>Publication year<% end %>
<div class="col-sm-8 range_limit">
<label for="range_pub_date_start_sort_begin" class="sr-only">Publication date range (starting year)</label>
<%= BlacklightRangeLimit::RangeFormComponent.new(facet_field: pub_date_presenter).render_range_input(:begin) %>
Expand Down
32 changes: 17 additions & 15 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CatalogController < ApplicationController
config.json_solr_path = 'advanced'

# default advanced config values
# TODO: remove for advanced search gem deprecation
config.advanced_search ||= Blacklight::OpenStructWithHashAccess.new
config.advanced_search[:url_key] ||= 'advanced'
config.advanced_search[:query_parser] ||= 'edismax'
Expand All @@ -46,6 +47,7 @@ class CatalogController < ApplicationController
config.advanced_search[:form_solr_parameters]['facet.pivot'] ||= ''
config.advanced_search[:form_solr_parameters]['f.language_facet.facet.limit'] ||= -1
config.advanced_search[:form_solr_parameters]['f.language_facet.facet.sort'] ||= 'index'
# end remove for advanced search gem deprecation

config.numismatics_search ||= Blacklight::OpenStructWithHashAccess.new
config.numismatics_search[:facet_fields] ||= %w[issue_metal_s issue_city_s issue_state_s issue_region_s issue_denomination_s
Expand Down Expand Up @@ -109,22 +111,22 @@ class CatalogController < ApplicationController
#
# :show may be set to false if you don't want the facet to be drawn in the
# facet bar
config.add_facet_field 'access_facet', label: 'Access', sort: 'index', collapse: false, home: true
config.add_facet_field 'access_facet', label: 'Access', sort: 'index', collapse: false, home: true, include_in_advanced_search: true
config.add_facet_field 'location', label: 'Library', limit: 20, sort: 'index',
home: true, solr_params: { 'facet.mincount' => Blacklight.blacklight_yml['mincount'] || 1 }
home: true, solr_params: { 'facet.mincount' => Blacklight.blacklight_yml['mincount'] || 1 }, include_in_advanced_search: false
config.add_facet_field 'format', label: 'Format', partial: 'facet_format', sort: 'index', limit: 15,
collapse: false, home: true, solr_params: { 'facet.mincount' => Blacklight.blacklight_yml['mincount'] || 1 }
collapse: false, home: true, solr_params: { 'facet.mincount' => Blacklight.blacklight_yml['mincount'] || 1 }, include_in_advanced_search: true

# num_segments and segments set to defaults here, included to show customizable features
config.add_facet_field 'pub_date_start_sort', label: 'Publication year', single: true, range: {
num_segments: 10,
assumed_boundaries: [1100, Time.now.year + 1],
segments: true
}
config.add_facet_field 'language_facet', label: 'Language', limit: true
config.add_facet_field 'subject_topic_facet', label: 'Subject: Topic', limit: true
config.add_facet_field 'genre_facet', label: 'Subject: Genre', limit: true
config.add_facet_field 'subject_era_facet', label: 'Subject: Era', limit: true
config.add_facet_field 'language_facet', label: 'Language', limit: true, include_in_advanced_search: true
config.add_facet_field 'subject_topic_facet', label: 'Subject: Topic', limit: true, include_in_advanced_search: false
config.add_facet_field 'genre_facet', label: 'Subject: Genre', limit: true, include_in_advanced_search: false
config.add_facet_field 'subject_era_facet', label: 'Subject: Era', limit: true, include_in_advanced_search: false
config.add_facet_field 'recently_added_facet', label: 'Recently added', home: true, query: {
weeks_1: { label: 'Within 1 week', fq: 'cataloged_tdt:[NOW/DAY-7DAYS TO NOW/DAY+1DAY]' },
weeks_2: { label: 'Within 2 weeks', fq: 'cataloged_tdt:[NOW/DAY-14DAYS TO NOW/DAY+1DAY]' },
Expand All @@ -133,15 +135,15 @@ class CatalogController < ApplicationController
months_2: { label: 'Within 2 months', fq: 'cataloged_tdt:[NOW/DAY-2MONTHS TO NOW/DAY+1DAY]' },
months_3: { label: 'Within 3 months', fq: 'cataloged_tdt:[NOW/DAY-3MONTHS TO NOW/DAY+1DAY]' },
months_6: { label: 'Within 6 months', fq: 'cataloged_tdt:[NOW/DAY-6MONTHS TO NOW/DAY+1DAY]' }
}
}, include_in_advanced_search: false

config.add_facet_field 'instrumentation_facet', label: 'Instrumentation', limit: true
config.add_facet_field 'publication_place_facet', label: 'Place of publication', limit: true
config.add_facet_field 'instrumentation_facet', label: 'Instrumentation', limit: true, include_in_advanced_search: false
config.add_facet_field 'publication_place_facet', label: 'Place of publication', limit: true, include_in_advanced_search: false
config.add_facet_field 'classification_pivot_field', label: 'Classification', pivot: %w[lc_1letter_facet lc_rest_facet], collapsing: true, icons: {
hide: '<i class="icon toggle"></i>'.html_safe,
show: '<i class="icon toggle collapsed"></i>'.html_safe
}
config.add_facet_field 'sudoc_facet', label: 'SuDocs', limit: true, sort: 'index'
}, include_in_advanced_search: false
config.add_facet_field 'sudoc_facet', label: 'SuDocs', limit: true, sort: 'index', include_in_advanced_search: false

# The following facet configurations are purely for display purposes. They
# will not show up in the facet bar, but without them the labels and other
Expand All @@ -156,10 +158,10 @@ class CatalogController < ApplicationController
config.add_facet_field 'call_number_scheme_facet', label: 'Call number scheme', limit: 25, include_in_request: false, sort: 'index'
config.add_facet_field 'call_number_group_facet', label: 'Call number group', limit: 25, include_in_request: false, sort: 'index'
config.add_facet_field 'call_number_full_facet', label: 'Full call number', limit: 25, include_in_request: false, sort: 'index'
config.add_facet_field 'advanced_location_s', label: 'Holding location', include_in_request: false,
helper_method: :render_location_code
config.add_facet_field 'advanced_location_s', label: 'Holding location', include_in_request: true, show: false,
helper_method: :render_location_code, include_in_advanced_search: true, sort: 'alpha'
config.add_facet_field 'name_title_browse_s', label: 'Author-title heading', include_in_request: false
config.add_facet_field 'subject_facet', show: false
config.add_facet_field 'subject_facet', show: false, include_in_advanced_search: false

# Numismatics facets
config.add_facet_field 'numismatic_collection_s', label: 'Numismatic Collection', include_in_request: false
Expand Down
14 changes: 10 additions & 4 deletions app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def facets_for_advanced_search_form(solr_p)
end

def only_home_facets(solr_parameters)
return if search_parameters?
return if search_parameters? || advanced_search?
solr_parameters['facet.field'] = blacklight_config.facet_fields.select { |_, v| v[:home] }.keys
solr_parameters['facet.pivot'] = []
end
Expand All @@ -93,16 +93,22 @@ def excessive_paging_error(_solr_parameters)
def excessive_paging?
page = blacklight_params[:page].to_i || 0
return false if page <= 1
return false if search_parameters? && page < 1000
return false if (search_parameters? || advanced_search?) && page < 1000
true
end

##
# Check if we are on an advanced search page
# @return [Boolean]
def advanced_search?
blacklight_params[:search_field] == 'advanced' || search_state.controller.try(:params).try(:[], :action) == 'advanced_search' || blacklight_params[:action] == 'numismatics'
end

##
# Check if any search parameters have been set
# @return [Boolean]
def search_parameters?
!blacklight_params[:q].nil? || blacklight_params[:f].present? ||
blacklight_params[:search_field] == 'advanced'
!blacklight_params[:q].nil? || blacklight_params[:f].present?
end

def conditionally_configure_json_query_dsl(_solr_parameters)
Expand Down
11 changes: 11 additions & 0 deletions spec/features/advanced_searching_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
expect(page).to have_selector '.icon-refresh[aria-hidden="true"]'
end

it 'has the expected facets' do
visit '/advanced'
expect(page.find_all('.advanced-facet-label').map(&:text)).to match_array(["Access", "Format", "Language", "Holding location", "Publication year"])
end

it 'provides labels to form elements' do
visit '/advanced'
expect(page).to have_selector('label', exact_text: 'Options for advanced search')
Expand Down Expand Up @@ -89,6 +94,12 @@
visit '/advanced'
end

it 'has the expected facets' do
visit '/advanced'
expect(page.find_all('.advanced-facet-label').map(&:text)).to include('Language')
expect(page.find_all('.advanced-facet-label').map(&:text)).to match_array(["Access", "Format", "Language", "Holding location", "Publication year"])
end

it 'renders an accessible button for starting over the search' do
expect(page).to have_selector '.icon-refresh[aria-hidden="true"]'
end
Expand Down
26 changes: 23 additions & 3 deletions spec/models/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,36 @@
end
end

describe '#facets_for_advanced_search_form' do
describe '#facets_for_advanced_search_form', advanced_search: true do
before do
blacklight_config.advanced_search.form_solr_parameters = { 'facet.field' => ["issue_denomination_s"] }
end
context 'when encountering a nil facet' do
it 'removes nil and facets that need to be displayed on the form' do

context 'with the built-in advanced search form', advanced_search: true do
before do
allow(Flipflop).to receive(:view_components_advanced_search?).and_return(true)
allow(Flipflop).to receive(:json_query_dsl?).and_return(true)
end

it 'includes the advanced search facets' do
solr_p = { fq: ["{!lucene}{!query v=$f_inclusive.issue_denomination_s.0} OR {!query v=$f_inclusive.issue_denomination_s.1}", nil, "format:Coin"] }
search_builder.facets_for_advanced_search_form(solr_p)
expect(solr_p[:fq]).to eq(['format:Coin'])
end
end
context 'with the gem advanced search form' do
before do
allow(Flipflop).to receive(:view_components_advanced_search?).and_return(false)
allow(Flipflop).to receive(:json_query_dsl?).and_return(false)
end

context 'when encountering a nil facet' do
it 'removes nil and facets that need to be displayed on the form' do
solr_p = { fq: ["{!lucene}{!query v=$f_inclusive.issue_denomination_s.0} OR {!query v=$f_inclusive.issue_denomination_s.1}", nil, "format:Coin"] }
search_builder.facets_for_advanced_search_form(solr_p)
expect(solr_p[:fq]).to eq(['format:Coin'])
end
end
end
end
end

0 comments on commit c135914

Please sign in to comment.