-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HYC-1766 - Date range advanced search (#1023)
* Configure date_issued field to have separate facet config for advanced search and regular search results. Add override of FacetsHelperBehavior to deduplicate list of facets during rendering, otherwise the date facet shows twice. Add advanced search range component (borrowed from stanford) for rendering the date field. * Prepopulate range fields in advanced search if there was an existing value * Add test for adv search date range, add date_issued to fixture records. Add placeholder value, fix font weight * Rubocop
- Loading branch information
Showing
7 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
app/components/advanced_search_range_limit_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%# [hyc-override] https://github.com/sul-dlss/SearchWorks/blob/01b8a0e8502220d4775ea868b097e9c723756455/app/components/advanced_search_range_limit_component.html.erb %> | ||
<%# This is not an override, but it is based on a file from another project %> | ||
<div class="form-group advanced-search-facet row facet_limit adv-date-year-range"> | ||
<%= label_tag "date_issued_isim", :class => "col-sm-3 col-form-label text-md-right" do %>Date<% end %> | ||
<div class="col-sm-9 form-inline row"> | ||
<%= label_tag("range[date_issued_isim][begin]", 'from year', class: 'sr-only visually-hidden') %> | ||
<%= number_field_tag("range[date_issued_isim][begin]", params.dig('range', 'date_issued_isim', 'begin'), maxlength: 6, class: "form-control text-center range_begin", placeholder: 'yyyy') %> | ||
<span class="control-label"> - </span> | ||
<%= label_tag("range[date_issued_isim][end]", 'to year', class: 'sr-only visually-hidden') %> | ||
<%= number_field_tag("range[date_issued_isim][end]", params.dig('range', 'date_issued_isim', 'end'), maxlength: 6, class: "form-control text-center range_end", placeholder: 'yyyy') %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
# [hyc-override] https://github.com/sul-dlss/SearchWorks/blob/01b8a0e8502220d4775ea868b097e9c723756455/app/components/advanced_search_range_limit_component.rb | ||
# The file is unchanged, but is imported from another project | ||
class AdvancedSearchRangeLimitComponent < ViewComponent::Base | ||
def initialize(facet_field:, **kwargs) | ||
@facet_field = facet_field | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/overrides/helpers/blacklight/facets_helper_behavior_override.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
# [hyc-override] https://github.com/projectblacklight/blacklight/blob/v7.33.1/app/helpers/blacklight/facets_helper_behavior.rb | ||
Blacklight::FacetsHelperBehavior.module_eval do | ||
# [hyc-override] make the list of facet fields unique to prevent duplicate Date facet | ||
alias_method :original_render_facet_partials, :render_facet_partials | ||
def render_facet_partials(fields = nil, options = {}) | ||
original_render_facet_partials(fields&.uniq, options) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
require Rails.root.join('spec/support/oai_sample_solr_documents.rb') | ||
include Warden::Test::Helpers | ||
|
||
RSpec.describe 'Advanced search', type: :feature, js: false do | ||
let(:solr) { Blacklight.default_index.connection } | ||
|
||
before do | ||
solr.delete_by_query('*:*') # delete everything in Solr | ||
solr.add([SLEEPY_HOLLOW, MYSTERIOUS_AFFAIR, BEOWULF, LEVIATHAN, GREAT_EXPECTATIONS, ILIAD, MISERABLES, MOBY_DICK]) | ||
solr.commit | ||
end | ||
|
||
after do | ||
solr.delete_by_query('*:*') | ||
solr.commit | ||
end | ||
|
||
it 'date range field returns expected results and retains values' do | ||
visit '/advanced' | ||
fill_in('range_date_issued_isim_begin', with: '1990') | ||
fill_in('range_date_issued_isim_end', with: '2020') | ||
click_button('Search') | ||
# Verify that only the titles with date issued within the given range are returned | ||
expect(page).not_to have_content(SLEEPY_HOLLOW[:title_tesim][0]) | ||
expect(page).not_to have_content(MYSTERIOUS_AFFAIR[:title_tesim][0]) | ||
expect(page).not_to have_content(BEOWULF[:title_tesim][0]) | ||
expect(page).not_to have_content(LEVIATHAN[:title_tesim][0]) | ||
expect(page).to have_content(GREAT_EXPECTATIONS[:title_tesim][0]) | ||
expect(page).not_to have_content(ILIAD[:title_tesim][0]) | ||
expect(page).to have_content(MISERABLES[:title_tesim][0]) | ||
expect(page).to have_content(MOBY_DICK[:title_tesim][0]) | ||
# Return to the advanced search and verify that the date range is still present | ||
click_link('Advanced search', match: :first) | ||
expect(page).to have_content('Date:1990 to 2020') | ||
expect(find('#range_date_issued_isim_begin').value).to eq('1990') | ||
expect(find('#range_date_issued_isim_end').value).to eq('2020') | ||
end | ||
end |
Oops, something went wrong.