diff --git a/app/controllers/concerns/blacklight/catalog.rb b/app/controllers/concerns/blacklight/catalog.rb index 898a361d57..464ecb476c 100644 --- a/app/controllers/concerns/blacklight/catalog.rb +++ b/app/controllers/concerns/blacklight/catalog.rb @@ -163,7 +163,7 @@ def render_sms_action?(_config, _options) end def search_service - search_service_class.new(blacklight_config, search_state.to_h) + search_service_class.new(blacklight_config, user_params: search_state.to_h) end ## diff --git a/app/services/blacklight/search_service.rb b/app/services/blacklight/search_service.rb index 700859a83f..f5c88e182b 100644 --- a/app/services/blacklight/search_service.rb +++ b/app/services/blacklight/search_service.rb @@ -2,16 +2,14 @@ # SearchService returns search results from the repository module Blacklight class SearchService - def initialize(blacklight_config, user_params = {}) + def initialize(blacklight_config, user_params: {}, search_builder_class: blacklight_config.search_builder_class) @blacklight_config = blacklight_config @user_params = user_params + @search_builder_class = search_builder_class end # TODO: Can this be private? - attr_reader :blacklight_config - - # Override this method to use a search builder other than the one in the config - delegate :search_builder_class, to: :blacklight_config + attr_reader :blacklight_config, :search_builder_class def search_builder search_builder_class.new(self) diff --git a/spec/services/blacklight/search_service_spec.rb b/spec/services/blacklight/search_service_spec.rb index 1afac86e5f..ea9fe133fb 100644 --- a/spec/services/blacklight/search_service_spec.rb +++ b/spec/services/blacklight/search_service_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Blacklight::SearchService, api: true do subject { service } - let(:service) { described_class.new(blacklight_config, user_params) } + let(:service) { described_class.new(blacklight_config, user_params: user_params) } let(:repository) { Blacklight::Solr::Repository.new(blacklight_config) } let(:user_params) { {} } @@ -29,6 +29,24 @@ service.repository.connection = blacklight_solr end + describe '#search_builder_class' do + subject { service.search_builder_class } + + it 'defaults to the value in the config' do + expect(subject).to eq SearchBuilder + end + + context 'when the search_builder_class is passed in' do + let(:klass) { double("Search builder") } + + let(:service) { described_class.new(blacklight_config, user_params: user_params, search_builder_class: klass) } + + it 'uses the passed value' do + expect(subject).to eq klass + end + end + end + # SPECS FOR SEARCH RESULTS FOR QUERY describe 'Search Results', integration: true do let(:blacklight_config) { copy_of_catalog_config }