Skip to content

Commit

Permalink
add Blacklight::Searchable-like behavior to Hyrax::Controller
Browse files Browse the repository at this point in the history
set the search service, and provide compatibility between Hyrax's use of
`search_results` and Blacklight 7's `Searchable` mixin.
  • Loading branch information
tamsin johnson authored and no-reply committed Jan 24, 2022
1 parent cb48cf6 commit 828cc4b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/controllers/concerns/hyrax/controller.rb
Expand Up @@ -17,6 +17,9 @@ module Hyrax::Controller
helper_method :create_work_presenter
before_action :set_locale
before_action :check_read_only, except: [:show, :index]

class_attribute :search_service_class
self.search_service_class = Hyrax::SearchService
end

# Provide a place for Devise to send the user to after signing in
Expand Down Expand Up @@ -51,6 +54,24 @@ def repository
blacklight_config.repository
end

# @note for Blacklight 6/7 compatibility
def search_results(*args)
return super if defined?(super) # use the upstream if present (e.g. in BL 6)

search_service(*args).search_results
end

##
# @note for Blacklight 6/7 compatibility
def search_service(**search_params)
return super if defined?(super) && search_params.empty?

search_service_class.new(config: blacklight_config,
scope: self,
user_params: search_params,
search_builder_class: search_builder_class)
end

private

##
Expand Down

0 comments on commit 828cc4b

Please sign in to comment.