Skip to content

Commit

Permalink
Merge pull request #3817 from pulibrary/highlight-3795
Browse files Browse the repository at this point in the history
Enable highlighting in catalog_controller behind a flipper feature
  • Loading branch information
christinach authored Nov 10, 2023
2 parents 5b952f2 + 96252b3 commit dedb0d0
Show file tree
Hide file tree
Showing 14 changed files with 2,524 additions and 488 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ Rails/OutputSafety:
- 'app/services/holding_requests_builder.rb'
- 'app/services/online_holdings_markup_builder.rb'
- 'app/services/physical_holdings_markup_builder.rb'
- 'app/processors/orangelight/highlight_processor.rb'

Rails/TimeZone:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem 'alma'
gem 'babel-transpiler'
gem 'bcrypt_pbkdf'
# Blacklight
gem 'blacklight', '~> 7.34'
gem 'blacklight', '~> 7.35'
# advanced search functionality
gem 'blacklight_advanced_search', '~> 7.0'
gem 'blacklight_dynamic_sitemap'
Expand Down
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ GEM
rubocop-performance
rubocop-rails
rubocop-rspec
blacklight (7.34.0)
blacklight (7.35.0)
deprecation
globalid
hashdiff
i18n (>= 1.7.0)
jbuilder (~> 2.7)
kaminari (>= 0.15)
ostruct (>= 0.3.2)
rails (>= 5.1, < 7.1)
rails (>= 5.1, < 7.2)
view_component (>= 2.66, < 4)
blacklight-marc (8.1.0)
blacklight (>= 7.11, < 9)
Expand Down Expand Up @@ -205,7 +205,7 @@ GEM
crack (0.4.5)
rexml
crass (1.0.6)
date (3.3.3)
date (3.3.4)
ddtrace (1.14.0)
debase-ruby_core_source (= 3.2.1)
libdatadog (~> 3.0.0.1.0)
Expand Down Expand Up @@ -367,13 +367,13 @@ GEM
modernizr-rails (2.7.1)
msgpack (1.7.2)
multi_xml (0.6.0)
net-imap (0.4.3)
net-imap (0.4.4)
date
net-protocol
net-ldap (0.18.0)
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
net-protocol (0.2.2)
timeout
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
Expand Down Expand Up @@ -402,7 +402,7 @@ GEM
marc
scrub_rb (~> 1.0)
orm_adapter (0.5.0)
ostruct (0.5.5)
ostruct (0.6.0)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
Expand All @@ -419,7 +419,7 @@ GEM
public_suffix (5.0.3)
puma (6.4.0)
nio4r (~> 2.0)
racc (1.7.2)
racc (1.7.3)
rack (2.2.8)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
Expand Down Expand Up @@ -603,7 +603,7 @@ GEM
thread_safe (0.3.6)
tilt (2.3.0)
timecop (0.9.8)
timeout (0.4.0)
timeout (0.4.1)
tins (1.32.1)
sync
traject (3.8.1)
Expand Down Expand Up @@ -674,7 +674,7 @@ DEPENDENCIES
babel-transpiler
bcrypt_pbkdf
bixby (~> 5.0)
blacklight (~> 7.34)
blacklight (~> 7.35)
blacklight-marc (~> 8.1)
blacklight_advanced_search (~> 7.0)
blacklight_dynamic_sitemap
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class CatalogController < ApplicationController
end

configure_blacklight do |config|
# config.add_field_configuration_to_solr_request!
config.raw_endpoint.enabled = true

config.json_solr_path = 'advanced'
Expand Down Expand Up @@ -228,16 +229,16 @@ class CatalogController < ApplicationController
# output for bento search. If you need to add a field to JSON display
# (catalog.json), add it here!
config.add_index_field 'series_display', label: 'Series', helper_method: :series_results
config.add_index_field 'author_display', label: 'Author/Artist', browse_link: :name
config.add_index_field 'author_display', label: 'Author/Artist', browse_link: :name, presenter: Orangelight::HighlightPresenter
config.add_index_field 'pub_created_display', label: 'Published/Created'
config.add_index_field 'format', label: 'Format', helper_method: :format_icon
config.add_index_field 'holdings_1display', show: false
config.add_index_field 'contained_in_s', show: false
config.add_index_field 'isbn_t', show: false
config.add_index_field 'score', show: false
config.add_index_field 'marc_relator_display', show: false
config.add_index_field 'title_display', show: false
config.add_index_field 'title_vern_display', show: false
config.add_index_field 'title_display', show: false, presenter: Orangelight::HighlightPresenter
config.add_index_field 'title_vern_display', show: false, presenter: Orangelight::HighlightPresenter
config.add_index_field 'isbn_s', show: false
config.add_index_field 'oclc_s', show: false
config.add_index_field 'lccn_s', show: false
Expand Down
9 changes: 9 additions & 0 deletions app/presenters/orangelight/highlight_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
module Orangelight
class HighlightPresenter < Blacklight::FieldPresenter
def initialize(view_context, document, field_config, options = {})
super
@field_config["highlight"] = Flipflop.highlighting?
end
end
end
9 changes: 9 additions & 0 deletions app/processors/orangelight/highlight_processor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Orangelight
class HighlightProcessor < Blacklight::Rendering::AbstractStep
def render
next_step(values.map { |value| value.gsub('<em>', '<em class="highlight-query">').gsub('</em>', '</em class="highlight-query">').html_safe })
end
end
end
1 change: 1 addition & 0 deletions config/initializers/blacklight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
Orangelight::ReferenceNoteUrlProcessor,
Orangelight::SeriesLinkProcessor,
Blacklight::Rendering::Microdata,
Orangelight::HighlightProcessor,
Orangelight::JoinProcessor]
end
Loading

0 comments on commit dedb0d0

Please sign in to comment.