Skip to content

Commit

Permalink
Add advanced search included parent oid and call number
Browse files Browse the repository at this point in the history
Co-authored-by: Eric DeJesus <eric.dejesus@yale.com>
  • Loading branch information
2 people authored and bess committed Sep 8, 2020
1 parent eab2374 commit 9997dbd
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ inherit_gem:

Layout/LineLength:
Exclude:
- spec/support/solr_documents/metadata_cloud_with_visibility.rb
- spec/support/solr_documents/*

# Views do not have classes or modules
RSpec/DescribeClass:
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem 'awesome_print'
gem 'blacklight', '>= 7.0'
gem 'blacklight-gallery'
gem 'blacklight-marc', '>= 7.0.0.rc1', '< 8'
gem "blacklight_advanced_search"
gem 'blacklight_range_limit'
gem 'bootsnap', '>= 1.4.2', require: false
gem 'bootstrap', '~> 4.0'
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ GEM
marc-fastxmlwriter
rails
traject (~> 3.0)
blacklight_advanced_search (7.0.0)
blacklight (~> 7.0)
parslet
blacklight_range_limit (7.8.1)
blacklight (>= 7.0)
bootsnap (1.4.8)
Expand Down Expand Up @@ -254,6 +257,7 @@ GEM
parallel (1.19.1)
parser (2.7.1.3)
ast (~> 2.4.0)
parslet (2.0.0)
pg (1.2.3)
popper_js (1.16.0)
public_suffix (4.0.5)
Expand Down Expand Up @@ -465,6 +469,7 @@ DEPENDENCIES
blacklight (>= 7.0)
blacklight-gallery
blacklight-marc (>= 7.0.0.rc1, < 8)
blacklight_advanced_search
blacklight_range_limit
bootsnap (>= 1.4.2)
bootstrap (~> 4.0)
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
//= require jquery
//= require 'blacklight_advanced_search'


//= require jquery3
//= require rails-ujs
//= require turbolinks
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Used by blacklight_range_limit
*= require 'blacklight_range_limit'
*
*/
*/

@import 'bootstrap';
@import 'blacklight/blacklight', 'blacklight_marc';
Expand Down
41 changes: 39 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
# frozen_string_literal: true
class CatalogController < ApplicationController
include BlacklightAdvancedSearch::Controller
include BlacklightRangeLimit::ControllerOverride
include Blacklight::Catalog
include Blacklight::Marc::Catalog

configure_blacklight do |config|
# default advanced config values
config.advanced_search ||= Blacklight::OpenStructWithHashAccess.new
# config.advanced_search[:qt] ||= 'advanced'
config.advanced_search[:url_key] ||= 'advanced'
config.advanced_search[:query_parser] ||= 'edismax'
config.advanced_search[:form_solr_parameters] ||= {}

## Gallery View
config.view.gallery.partials = [:index_header]
config.show.tile_source_field = :content_metadata_image_iiif_info_ssm
config.show.partials.insert(1, :openseadragon)
Expand Down Expand Up @@ -102,7 +111,7 @@ class CatalogController < ApplicationController
assumed_boundaries: [1100, Time.current.year + 2],
segments: true,
maxlength: 4
}
}, include_in_advanced_search: false

# the facets below are set to false because we aren't filtering on them from the main search page
# but we need to be able to provide a label when they are filtered upon from an individual show page
Expand Down Expand Up @@ -232,18 +241,28 @@ class CatalogController < ApplicationController

# Array allows for only listed Solr fields to be searched in the 'All Fields'
search_fields = ['abstract_tesim', 'author_tesim', 'alternativeTitle_tesim', 'description_tesim', 'subjectGeographic_tesim',
'identifierShelfMark_tesim', 'orbisBidId_ssi', 'publicatonPlace_tesim', 'publisher_tesim',
'identifierShelfMark_tesim', 'orbisBibId_ssi', 'publicatonPlace_tesim', 'publisher_tesim',
'resourceType_tesim', 'sourceCreated_tesim', 'subjectName_tesim', 'subject_topic_tesim',
'title_tesim']

config.add_search_field('all_fields', label: 'All Fields') do |field|
field.qt = 'search'
field.include_in_advanced_search = false
field.solr_parameters = {
qf: search_fields,
pf: ''
}
end

config.add_search_field('all_fields_advanced', label: 'All Fields') do |field|
field.qt = 'search'
field.include_in_simple_select = false
field.solr_parameters = {
qf: search_fields.join(' '),
pf: ''
}
end

# Now we see how to over-ride Solr request handler defaults, in this
# case for a BL "search field", which is really a dismax aggregate
# of Solr search fields.
Expand All @@ -268,6 +287,7 @@ class CatalogController < ApplicationController
# config[:default_solr_parameters][:qt], so isn't actually neccesary.
config.add_search_field('subjectName_ssim', label: 'Subject') do |field|
field.qt = 'search'
field.include_in_advanced_search = false
field.solr_parameters = {
qf: '',
pf: 'subjectName_ssim'
Expand All @@ -282,6 +302,23 @@ class CatalogController < ApplicationController
}
end

config.add_search_field('oid_ssi', label: 'OID') do |field|
field.qt = 'search'
field.include_in_simple_select = false
field.solr_parameters = {
qf: 'oid_ssi',
pf: ''
}
end

config.add_search_field('identifierShelfMark_tesim', label: 'Identifier Shelf Mark') do |field|
field.qt = 'search'
field.include_in_simple_select = false
field.solr_parameters = {
qf: 'identifierShelfMark_tesim',
pf: ''
}
end
# "sort results by" select (pulldown)
# label in pulldown is followed by the name of the SOLR field to sort by and
# whether the sort is ascending or descending (it must be asc or desc
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/saved_searches_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true
class SavedSearchesController < ApplicationController
include Blacklight::SavedSearches

helper BlacklightAdvancedSearch::RenderConstraintsOverride
end
2 changes: 2 additions & 0 deletions app/controllers/search_history_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ class SearchHistoryController < ApplicationController
include Blacklight::SearchHistory

helper BlacklightRangeLimit::ViewHelperOverride
# helper BlacklightAdvancedSearch::RenderConstraintsOverride
helper RangeLimitHelper
helper BlacklightAdvancedSearch::RenderConstraintsOverride
end
4 changes: 4 additions & 0 deletions app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
# end
class SearchBuilder < Blacklight::SearchBuilder
include Blacklight::Solr::SearchBuilderBehavior
include BlacklightAdvancedSearch::AdvancedSearchBuilder
include BlacklightRangeLimit::RangeLimitBuilder

self.default_processor_chain += [:add_advanced_parse_q_to_solr, :add_advanced_search_to_solr]
# include BlacklightRangeLimit::RangeLimitBuilder

# Add the `show_only_public_records` method to the processor chain
self.default_processor_chain += [:show_only_public_records]
self.default_processor_chain += [:highlight_fields]
Expand Down
42 changes: 42 additions & 0 deletions app/views/advanced/_advanced_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<% unless (search_context_str = render_search_to_s( advanced_search_context)).blank? %>
<div class="constraints well search_history">
<h4><%= t 'blacklight_advanced_search.form.search_context' %></h4>
<%= search_context_str %>
</div>
<% end %>
<%= form_tag search_catalog_path, :class => 'advanced form-horizontal', :method => :get do %>
<%= render_hash_as_hidden_fields(advanced_search_context) %>

<div class="input-criteria">

<div class="query-criteria">
<h3 class="query-criteria-heading">
<%= t('blacklight_advanced_search.form.query_criteria_heading_html', :select_menu => select_menu_for_field_operator ) %>
</h3>

<div id="advanced_search">
<%= render 'advanced/advanced_search_fields' %>
</div>
</div>

</div>

<div class="form-group advanced-search-facet">
<%= label_tag "publication_date", :class => "col-sm-3 control-label" do %>
Publication Year
<% end %>

<div class="col-sm-9">
<%= render_range_input("pub_date_sort", :begin) %> - <%= render_range_input("pub_date_sort", :end) %>
</div>
</div>

<hr>

<div class="sort-submit-buttons clearfix">
<%= render 'advanced_search_submit_btns' %>
</div>

<% end %>
7 changes: 7 additions & 0 deletions app/views/catalog/_search_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<% end %>

<label for="q" class="sr-only"><%= t('blacklight.search.form.search.label') %></label>
<%#= text_field_tag :q, params[:q], placeholder: t('blacklight.search.form.search.placeholder'), class: "search-q q form-control rounded-#{search_fields.length > 1 ? '0' : 'left'}", id: "q", autocomplete: presenter.autocomplete_enabled? ? "off" : "", autofocus: presenter.autofocus?, data: { autocomplete_enabled: presenter.autocomplete_enabled?, autocomplete_path: search_action_path(action: :suggest) } %>
<%= text_field_tag :q, params[:q], placeholder: t('blacklight.search.form.search.placeholder'), class: "search-q q form-control rounded-#{search_fields.length > 1 ? '0' : 'left'}", id: "q", aria: { label: 'search' }, autocomplete: presenter.autocomplete_enabled? ? "off" : "", autofocus: presenter.autofocus?, data: { autocomplete_enabled: presenter.autocomplete_enabled?, autocomplete_path: search_action_path(action: :suggest) } %>

<span class="input-group-append">
Expand All @@ -25,3 +26,9 @@
</span>
</div>
<% end %>



<div>
<%= link_to 'More Options', blacklight_advanced_search_engine.advanced_search_path(search_state.to_h), class: 'advanced_search btn btn-secondary'%>
</div>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
end

mount Blacklight::Engine => '/'
mount BlacklightAdvancedSearch::Engine => '/'

root to: "catalog#index"
concern :searchable, Blacklight::Routes::Searchable.new

Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let(:search_fields) { controller.blacklight_config.search_fields.keys }

let(:expected_search_fields) do
['all_fields', 'author_tesim', 'orbisBibId_ssi', 'subjectName_ssim', 'title_tesim']
['all_fields', 'all_fields_advanced', 'author_tesim', 'identifierShelfMark_tesim', 'oid_ssi', 'orbisBibId_ssi', 'subjectName_ssim', 'title_tesim']
end

it { expect(search_fields).to contain_exactly(*expected_search_fields) }
Expand Down
Loading

0 comments on commit 9997dbd

Please sign in to comment.