Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/components/um_blacklight_search_bar_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class UmBlacklightSearchBarComponent < Blacklight::SearchBarComponent
def advanced_search_enabled?
false
end
end
27 changes: 27 additions & 0 deletions app/components/um_search_bar_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%= render(UmBlacklightSearchBarComponent.new(
**@kwargs,
params: @params.merge(f: (@params[:f] || {}).except(:collection)),
q: @q,
search_field: @search_field)) do |c| %>

<% c.with_before_input_group do %>
<div class="input-group within-collection-dropdown">
<label class="input-group-text" for="within_collection">
<%= t('arclight.within_collection_dropdown.label_html') %>
</label>
<%= select_tag ('f[collection][]' if collection_name.present?), within_collection_options, id: 'within_collection', class: 'form-select search-field rounded-end' %>
</div>
<% end %>

<% c.with_prepend do %>
<%= prepend %>
<% end %>

<% c.with_append do %>
<%= append %>
<% end if append? %>

<% c.with_search_button do %>
<%= search_button %>
<% end if respond_to?(:search_button?) && search_button? # only BL8 has this option %>
<% end %>
4 changes: 4 additions & 0 deletions app/components/um_search_bar_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class UmSearchBarComponent < Arclight::SearchBarComponent
end
17 changes: 15 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative "../components/um_access_component"
require_relative "../components/um_constraints_component"
require_relative "../components/um_document_component"
require_relative "../components/um_search_bar_component"
require_relative "../components/um_search_result_component"

# Blacklight controller that handles searches and document requests
Expand Down Expand Up @@ -75,7 +76,7 @@ class CatalogController < ApplicationController
config.index.group_component = Arclight::GroupComponent
config.index.constraints_component = UmConstraintsComponent
config.index.document_presenter_class = Arclight::IndexPresenter
config.index.search_bar_component = Arclight::SearchBarComponent
config.index.search_bar_component = UmSearchBarComponent
# config.index.thumbnail_field = 'thumbnail_path_ss'

# solr field configuration for document/show views
Expand Down Expand Up @@ -209,61 +210,70 @@ class CatalogController < ApplicationController
# since we aren't specifying it otherwise.
config.add_search_field "all_fields", label: "All Fields" do |field|
field.include_in_simple_select = true
field.clause_params = { edismax: {} }
end

config.add_search_field "within_collection" do |field|
field.include_in_simple_select = false
field.solr_parameters = {
fq: "-level_ssim:Collection"
}
field.include_in_advanced_search = false
end

# Field-based searches. We have registered handlers in the Solr configuration
# so we have Blacklight use the `qt` parameter to invoke them
config.add_search_field "keyword", label: "Keyword" do |field|
field.qt = "search" # default
field.qt = "search"
field.clause_params = { edismax: {} }
end
config.add_search_field "name", label: "Name" do |field|
field.qt = "search"
field.solr_parameters = {
qf: "${qf_name}",
pf: "${pf_name}"
}
field.clause_params = { edismax: field.solr_parameters.dup }
end
config.add_search_field "place", label: "Place" do |field|
field.qt = "search"
field.solr_parameters = {
qf: "${qf_place}",
pf: "${pf_place}"
}
field.clause_params = { edismax: field.solr_parameters.dup }
end
config.add_search_field "subject", label: "Subject" do |field|
field.qt = "search"
field.solr_parameters = {
qf: "${qf_subject}",
pf: "${pf_subject}"
}
field.clause_params = { edismax: field.solr_parameters.dup }
end
config.add_search_field "title", label: "Title" do |field|
field.qt = "search"
field.solr_parameters = {
qf: "${qf_title}",
pf: "${pf_title}"
}
field.clause_params = { edismax: field.solr_parameters.dup }
end
config.add_search_field "container", label: "Container" do |field|
field.qt = "search"
field.solr_parameters = {
qf: "${qf_container}",
pf: "${pf_container}"
}
field.clause_params = { edismax: field.solr_parameters.dup }
end
config.add_search_field "identifier", label: "Identifier" do |field|
field.qt = "search"
field.solr_parameters = {
qf: "${qf_identifier}",
pf: "${pf_identifier}"
}
field.clause_params = { edismax: field.solr_parameters.dup }
end

# These are the parameters passed through in search_state.params_for_search
Expand Down Expand Up @@ -449,5 +459,8 @@ class CatalogController < ApplicationController

# Group header values
config.add_group_header_field "abstract_or_scope", accessor: true, truncate: true, helper_method: :render_html_tags

# Advanced search
config.advanced_search.enabled = true
end
end
16 changes: 15 additions & 1 deletion app/helpers/catalog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@ module CatalogHelper
include Blacklight::CatalogHelperBehavior

def has_no_query
request.path == "/" && params[:q].blank? && params[:f].blank?
request.path == "/" &&
params[:q].blank? &&
params[:f].blank? &&
!advanced_search_clauses?
end

private

# Advanced search sends `clause[...][query]` params instead of `q`.
def advanced_search_clauses?
clauses = params[:clause]
return false if clauses.blank?

values = clauses.respond_to?(:values) ? clauses.values : clauses
values.any? { |clause| clause[:query].present? }
end
end
8 changes: 7 additions & 1 deletion app/views/catalog/_home.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

<%= render(blacklight_config.view_config(document_index_view_type).search_bar_component.new(
url: search_action_url,
advanced_search_url: search_action_url(action: 'advanced_search'),
params: search_state.params_for_search.except(:qt),
autocomplete_path: search_action_path(action: :suggest))) %>

Expand All @@ -25,6 +24,13 @@
<%= link_to t('um_arclight.home.browse_all'), arclight_engine.collections_path %>
</div>

<div class="search-extra-controls flex-fill">
<div class="input-group">
<%= link_to "Advanced Search",
search_action_path(action: :advanced_search),
class: "advanced_search" %>
</div>
</div>
</div>

<a class="d-flex align-items-center mt-4 mb-3" href="/repositories">
Expand Down
103 changes: 103 additions & 0 deletions solr/conf/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,109 @@
</arr>
</requestHandler>

<!-- Advanced search handler for Blacklight's JSON Query DSL (json_solr_path
defaults to 'advanced'). Mirrors the query-parsing defaults of the
"search" handler so empty edismax clauses and ${qf_*}/${pf_*} macros
resolve identically to a normal search. -->
<requestHandler name="/advanced" class="solr.SearchHandler">
<lst name="defaults">
<str name="defType">edismax</str>
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="q.alt">*:*</str>

<str name="mm">4&lt;90%</str>

<str name="qf">
collection_title_tesim^150
title_tesim^100
normalized_title_teim^100
unitid_identifier_match^40
name_teim^10
place_teim^10
subject_teim^2
id
ead_ssi
ref_ssm
unitid_ssm
container_teim
parent_unittitles_tesim
text
</str>
<str name="pf">
collection_title_tesim^300
title_tesim^200
normalized_title_teim^200
unitid_identifier_match^80
name_teim^20
place_teim^20
subject_teim^5
id^2
ead_ssi^2
ref_ssm^2
unitid_ssm^2
container_teim^2
parent_unittitles_tesim^2
text^2
</str>

<str name="qf_container">
container_teim
</str>
<str name="pf_container">
container_teim^2
</str>
<str name="qf_identifier">
id
ead_ssi
ref_ssm
unitid_ssm
unitid_identifier_match
</str>
<str name="pf_identifier">
id^2
ead_ssi^2
ref_ssm^2
unitid_ssm^2
unitid_identifier_match^2
</str>
<str name="qf_name">
name_teim
</str>
<str name="pf_name">
name_teim^2
</str>
<str name="qf_place">
place_teim
</str>
<str name="pf_place">
place_teim^2
</str>
<str name="qf_subject">
subject_teim
</str>
<str name="pf_subject">
subject_teim^2
</str>
<str name="qf_title">
title_tesim
normalized_title_teim
</str>
<str name="pf_title">
title_tesim^2
normalized_title_teim^2
</str>

<int name="ps">3</int>
<float name="tie">0.01</float>

<str name="fl">*</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>

<!-- for requests to get a single document; use id=666 instead of q=id:666 -->
<requestHandler name="document" class="solr.SearchHandler" >
<lst name="defaults">
Expand Down