From 0741b9201bf79c657e852ff1e882c7aafed943e4 Mon Sep 17 00:00:00 2001 From: jrgriffiniii <1443986+jrgriffiniii@users.noreply.github.com> Date: Tue, 7 Nov 2023 14:45:34 -0500 Subject: [PATCH] Ensuring that CatalogController utilizes the non-default SearchBuilder when configured for a custom SearchBuilder and the `search_algorith` parameter is empty Co-authored-by: Anna Headley Co-authored-by: Carolyn Cole Co-authored-by: Trey Pendragon Co-authored-by: Eliot Jordan --- app/controllers/catalog_controller.rb | 8 +++++++- spec/controllers/catalog_controller_spec.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 7fac9c6df..caeed4333 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -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 diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb index 66476b99b..7be40543e 100644 --- a/spec/controllers/catalog_controller_spec.rb +++ b/spec/controllers/catalog_controller_spec.rb @@ -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