Skip to content

Commit

Permalink
Ensuring that CatalogController utilizes the non-default SearchBuilder
Browse files Browse the repository at this point in the history
when configured for a custom SearchBuilder and the `search_algorith`
parameter is empty

Co-authored-by: Anna Headley <hackartisan@users.noreply.github.com>
Co-authored-by: Carolyn Cole <carolyncole@users.noreply.github.com>
Co-authored-by: Trey Pendragon <tpendragon@users.noreply.github.com>
Co-authored-by: Eliot Jordan <eliotjordan@users.noreply.github.com>
  • Loading branch information
5 people committed Nov 7, 2023
1 parent 47b7ea8 commit 0741b92
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,14 @@ def search_service_context
{ search_builder_class: alternate_search_builder_class }
end

def search_algorithm_param
params[:search_algorithm]
end

def alternate_search_builder_class
"#{params[:search_algorithm]}_search_builder".camelize.constantize
return unless search_algorithm_param

"#{search_algorithm_param}_search_builder".camelize.constantize
rescue NameError
nil
end
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@
expect(repository).to have_received(:search).with(instance_of(SearchBuilder))
end
end

context "when the default is not search builder and the search_algorithm parameter is empty" do
it "uses the configured search builder" do
allow(controller.blacklight_config).to receive(:search_builder_class).and_return(EngineeringSearchBuilder)

get :index, params: { q: "coffee" }

expect(repository).to have_received(:search).with(instance_of(EngineeringSearchBuilder))
end
end
end

context "when the multi-algorithm feature is off" do
Expand Down

0 comments on commit 0741b92

Please sign in to comment.