Skip to content

Commit

Permalink
Allow search_builder_class to be passed to SearchService
Browse files Browse the repository at this point in the history
So that this can be set without having to override SearchService
  • Loading branch information
jcoyne committed Nov 7, 2018
1 parent 5284e21 commit b3d5304
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/blacklight/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

##
Expand Down
8 changes: 3 additions & 5 deletions app/services/blacklight/search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 19 additions & 1 deletion spec/services/blacklight/search_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) { {} }

Expand All @@ -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 }
Expand Down

0 comments on commit b3d5304

Please sign in to comment.