Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
13ab0f0
update to Blacklight 9.0.0.beta7 in Gemfile
jrochkind Oct 28, 2025
2a5bbd8
update blacklight-frontend to 9.0.0.beta7
jrochkind Oct 28, 2025
c34d323
remove deprecated SolrDocument modules that we haven't used anyway
jrochkind Oct 28, 2025
94f2551
render constraints new Blacklight 9 way in customized catalog/index p…
jrochkind Oct 28, 2025
440454d
render facets/sidebar new Blacklight 9 way on collection/featured top…
jrochkind Oct 28, 2025
1016517
Use search_header component directly, instead of partial removed from…
jrochkind Oct 28, 2025
f4f2a44
set page title new Blacklight 9 way and improve it on collection and …
jrochkind Oct 28, 2025
f8f228c
Fix custom facet CSS overrides for Blacklight 9 use of Bootstrap 5 ac…
jrochkind Oct 28, 2025
db6d2c6
fix 'you searched for' i18n label for new key used in BL9
jrochkind Oct 28, 2025
bb6bbb8
fix custom search-widgets alignment for Blacklight 9
jrochkind Oct 29, 2025
54ab2c6
fix blacklight_solr_repository spec for params arg temporarily required.
jrochkind Oct 29, 2025
7750ad0
update to newer blacklight 9.0.0-beta8
jrochkind Oct 30, 2025
00e138f
Avoid BL9 deprecation warning for repository.search positional argument
jrochkind Oct 30, 2025
16b6a5f
turn off new facet suggest feature until we are ready to turn it on
jrochkind Oct 30, 2025
0866ffa
Refactor SearchBuilder search logic customizations for Blacklight 9.0…
jrochkind Nov 3, 2025
e193036
Merge pull request #3182 from sciencehistory/refactor_for_facet_searc…
jrochkind Nov 10, 2025
16824d4
Merge branch 'master' into blacklight_9
jrochkind Nov 10, 2025
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ gem 'scout_apm'
# NOTE ALSO: We are using `blacklight-frontend` JS NPM package, updating blacklight
# version may require an update with yarn to `blacklight-frontend`, has to be
# checked manually.
gem "blacklight", "~> 8.12.2"
gem "blacklight", "~> 9.0.0.beta8"
gem "blacklight_range_limit", "~> 9.1.0" # version no longer sync'd with blacklight, not sure how we tell what version works with what version of BL

# for some code to deal with transcoding video, via AWS MediaConvert
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ GEM
benchmark (0.4.1)
bigdecimal (3.3.1)
bindex (0.8.1)
blacklight (8.12.2)
blacklight (9.0.0.beta8)
globalid
i18n (>= 1.7.0)
jbuilder (~> 2.7)
kaminari (>= 0.15)
ostruct (>= 0.3.2)
rails (>= 6.1, < 9)
view_component (>= 2.74, < 5)
rails (>= 7.0, < 9)
view_component (>= 3.0, < 5.0)
zeitwerk
blacklight_range_limit (9.1.0)
blacklight (>= 7.25.2, < 9)
Expand Down Expand Up @@ -825,7 +825,7 @@ DEPENDENCIES
aws-sdk-s3 (~> 1.0)
axe-core-rspec (~> 4.3)
barnes
blacklight (~> 8.12.2)
blacklight (~> 9.0.0.beta8)
blacklight_range_limit (~> 9.1.0)
bootsnap (>= 1.4.4)
bootstrap4-kaminari-views
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ def active_sort_fields
#config.show.display_type_field = 'format'
#config.show.thumbnail_field = 'thumbnail_path_ss'


# Turn off the new facet-suggest functionality, until we are ready to turn it on.
# https://github.com/sciencehistory/scihist_digicoll/issues/3062
config.default_facet_suggest = false

# solr fields that will be treated as facets by the blacklight application
# The ordering of the field names is the order of the display
#
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/collection_show_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def blacklight_config
configure_blacklight do |config|
# Our custom sub-class to limit just to docs in collection, with collection id
# taken from params[:collection_id]
#
# Blacklight 9 requires this logic to be duplicated in two parallel search builder
# classes, see https://github.com/projectblacklight/blacklight/pull/3762
config.search_builder_class = ::SearchBuilder::WithinCollectionBuilder
config.facet_search_builder_class = ::SearchBuilder::WithinCollectionFacetBuilder

# and we need to make sure collection_id is allowed by BL, don't totally
# understand this, as of BL 7.25
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/featured_topic_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ class FeaturedTopicController < CatalogController

configure_blacklight do |config|
# Limit just to items in the featured topic.
# For Blacklight 9, we need to do this in two classes.
config.search_builder_class = ::SearchBuilder::WithinFeaturedTopicBuilder
config.facet_search_builder_class = ::SearchBuilder::WithinFeaturedTopicFacetBuilder

# And we need to make sure the :slug param is allowed by blacklight,
# don't totally understand why, as of BL 7.25
Expand Down Expand Up @@ -37,11 +39,10 @@ def total_count

empty_search_state = search_state_class.new(params.slice(:controller, :action, :slug), blacklight_config, self)

# In future BL versions you may need to remove .to_h, just `search_service.search_builder.with(empty_search_state)`
builder = search_service.search_builder.with(empty_search_state.to_h)
builder = search_service.search_builder.with(empty_search_state)
builder.rows = 0 # we don't want any actual results back, just search metadata

response = search_service.repository.search(builder)
response = search_service.repository.search(params: builder)

response.total_count
end
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/entrypoints/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@import 'bootstrap/scss/bootstrap';

@import 'blacklight-frontend/app/assets/stylesheets/blacklight/blacklight';
@import 'blacklight-frontend/stylesheets/blacklight';

@import "@stylesheets/responsive-tabs/responsive-tabs";

Expand Down
87 changes: 46 additions & 41 deletions app/frontend/stylesheets/local/search_results.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@


// override sufia facet widget styles to be more brand-like, and generally neater
.facets {
.facets {
// disable border Blacklight default is trying to put in at small sizes,
// we have already taken care of it differently.
--bl-facets-smallish-border: none;

// no special styles for active facets
--bl-facet-active-bg: #{$shi-bg-gray};
--bl-facet-active-color: initial;
--bl-facet-active-item-color: initial;

// override various bootstrap and blacklight CSS properties for our facet
// accordion to look how it was designed before bootstrap acccordion existed,
// we still like it.
//
// Includes grey bg for button/header, white body, border, with NO
// special colors for active\/open/hover, just the same!
//
// Bit tricky to get it overridden everywhere with right specificity
.accordion, .facet-limit {
--bs-accordion-btn-bg: #{$shi-bg-gray};
--bs-accordion-active-bg: var(--bs-accordion-btn-bg);
--bs-accordion-btn-active-icon: var(--bs-accordion-btn-icon);

--bs-btn-hover-bg: var(--bs-accordion-btn-bg);
--bs-accordion-btn-padding-x: 0.5rem;
--bs-accordion-btn-padding-y: 0.5rem;
--bs-accordion-border-color: #{$card-border-color};

--bs-accordion-body-padding-x: 1rem;
--bs-accordion-body-padding-y: 1rem;

// need to override variable set on .btn
.btn {
--bs-btn-font-weight: 500;
}
}

// get rid of custom Blacklight-set active icon with different color, this was so hard to
// figure out! Having the exact right selector is important, to undo what they set.
.facet-limit-active {
--bs-accordion-btn-icon: inherit;
}

.facets-header {
// To try to make top line of search results all line up, we hackily try to make
// this have the exact same line-height in pixels as .page_links. hack to try to improve on BL.
Expand All @@ -26,56 +63,26 @@
@extend .d-md-none;
}

.card-header {
.accordion-header {
font-weight: normal;
line-height: 1.4;
color: inherit;

padding: .625rem .9375rem;
}

.card-body {
border-top: $card-border-width solid $card-border-color;
}

.facet-limit {
margin-top: 0;
margin-bottom: 0;
}

// keep double border from happening between "boxes" in our facet limit stack
.facet-limit:not(:first-child) {
border-top: 0;
}

.facet-values li {
line-height: 1.2;
// override blacklight spacing to be better
padding-top: 0;
padding-bottom: 0.5rem;
}



// eliminate any special styles on active facet by overrides
// Originally active facet gets green bg and white text, we don't want!
.facet-limit-active {
color: inherit;
border-color: $card-border-color !important;
& .card-header {
background-color: $card-cap-bg !important;
color: $body-color;
border-color: $card-border-color !important;
button {
color: inherit; // in BL 8 need to override at this level too
}
}
.facet-values li .selected {
color: inherit !important;
}
}


form.range_limit {
display: block;
// get 'limit' button all on one line by making inputs more compact
Expand All @@ -86,6 +93,12 @@
}
}

// override blacklight to make sure right-edge button in "sort/per page" area
// is right-justified. Annoying.
.search-widgets :last-child {
margin-right: 0 !important;
}

.sort-pagination {
// to try to make search results line up horizontally, we have to override
// some BL things, and match blacklight .facets-header so it lines up
Expand All @@ -99,15 +112,7 @@
flex-wrap: wrap;
justify-content: space-between;
border: none;
.search-widgets {
float: none !important;

// override blacklight's use of bootstrap -- in our layout we want
// this flush with right margin.
#sort-dropdown {
margin-right: 0 !important;
}
}
&:after {
display: none;
}
Expand Down
28 changes: 28 additions & 0 deletions app/models/concerns/search_builder_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Blacklight 9 requires all local custom SearchBuilder logic to be duplicated in two
# places, also into a corresponding FacetSearchBuilder class. So we do it here, so
# it can be done in two places DRY. Sorry for increase of complexity.
#
# See https://github.com/projectblacklight/blacklight/pull/3762
module SearchBuilderBehavior
extend ActiveSupport::Concern

# For blacklight_range_limit plugin
include BlacklightRangeLimit::RangeLimitBuilder

# Scihist SearchBuilder extensions
include SearchBuilder::AccessControlFilter
include SearchBuilder::AdminOnlySearchFields
include SearchBuilder::CustomSortLogic
include SearchBuilder::AllSearchResultIdsBuilder

##
# @example Adding a new step to the processor chain
#
# included do
# self.default_processor_chain += [:add_custom_data_to_query]
# end
#
# def add_custom_data_to_query(solr_parameters)
# solr_parameters[:custom] = blacklight_params[:user_value]
# end
end
53 changes: 53 additions & 0 deletions app/models/concerns/within_collection_builder_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Applies a limit to search just within a given collection, filtering on solr
# field where we've stored the containing collection ids.
#
# :collection_id needs to be provided in context, the actual UUID pk of collection,
# since that's what we index.
#
# Used on CollectionShowController search within a collection
#
# Blacklight 9 requires all custom search builder logic to be duplicated in a FacetSearchBuilder,
# so it lives here to keep it DRY.
# See https://github.com/projectblacklight/blacklight/pull/3762
module WithinCollectionBuilderBehavior
extend ActiveSupport::Concern

included do
class_attribute :collection_id_solr_field, default: "collection_id_ssim"
class_attribute :box_id_solr_field, default: "box_tsi"
class_attribute :folder_id_solr_field, default: "folder_tsi"

self.default_processor_chain += [:within_collection]
end

def within_collection(solr_parameters)
solr_parameters[:fq] ||= []
solr_parameters[:fq] << "{!term f=#{collection_id_solr_field}}#{collection_id}"
solr_parameters[:fq] << "#{box_id_solr_field}:(#{box_id})" if box_id.present?
solr_parameters[:fq] << "#{folder_id_solr_field}:(#{folder_id})" if folder_id.present?
end

private

# Overrides CustomSortLogic#default_sort_order
def default_sort_order
scope.context.dig(:collection_default_sort_order) || super
end

def collection_id
scope.context.fetch(:collection_id)
end

def box_id
safe_solr_escape scope.context.fetch :box_id
end

def folder_id
safe_solr_escape scope.context.fetch :folder_id
end

def safe_solr_escape str
RSolr.solr_escape str unless str.nil?
end

end
22 changes: 22 additions & 0 deletions app/models/concerns/within_featured_topic_builder_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Applies a limit to search just within a given featured topic.
#
# :slug needs to be provided in context.
#
# Used on FeaturedTopicController.
# Blacklight 9 requires all custom search builder logic to be duplicated in a FacetSearchBuilder,
# so it lives here to keep it DRY.
#
# See https://github.com/projectblacklight/blacklight/pull/3762
module WithinFeaturedTopicBuilderBehavior
extend ActiveSupport::Concern

included do
self.default_processor_chain += [:within_featured_topic]
end

def within_featured_topic(solr_parameters)
featured_topic = FeaturedTopic.from_slug(blacklight_params[:slug])
solr_parameters[:fq] ||= []
solr_parameters[:fq] << featured_topic.solr_fq
end
end
7 changes: 7 additions & 0 deletions app/models/facet_search_builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class FacetSearchBuilder < Blacklight::FacetSearchBuilder
include Blacklight::Solr::FacetSearchBuilderBehavior

# shared logic with SearchBuilder that MUST be duplciated to avoid
# subtle faulty behavior, see https://github.com/projectblacklight/blacklight/pull/3762
include SearchBuilderBehavior
end
23 changes: 4 additions & 19 deletions app/models/search_builder.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
# frozen_string_literal: true
#
# TODO: chf_sufia mixin's or equivalents for:
# * SearchBuilder::RestrictAdminSearchFields => Makes sure admin notes are only searchable if logged in
# * SearchBuilder::SyntheticCategoryLimit => something with making our 'topics'/synthetic categories
# work as limits, probably just for showing the main page for a 'topic'
# Blacklight 9 requires all custom search builder logic to be duplicated in a FacetSearchBuilder,
# so please do all customization in the `SearchBuilderBehavior` module so it can be kept DRY.
# See https://github.com/projectblacklight/blacklight/pull/3762
class SearchBuilder < Blacklight::SearchBuilder
include Blacklight::Solr::SearchBuilderBehavior
include BlacklightRangeLimit::RangeLimitBuilder


# Scihist SearchBuilder extensions
include SearchBuilder::AccessControlFilter
include SearchBuilder::AdminOnlySearchFields
include SearchBuilder::CustomSortLogic
include SearchBuilder::AllSearchResultIdsBuilder

##
# @example Adding a new step to the processor chain
# self.default_processor_chain += [:add_custom_data_to_query]
#
# def add_custom_data_to_query(solr_parameters)
# solr_parameters[:custom] = blacklight_params[:user_value]
# end
include SearchBuilderBehavior
end
Loading