From 2b592cbad63907f9dea48914af229c99969fdf9d Mon Sep 17 00:00:00 2001 From: Anna Headley <845363+hackartisan@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:01:06 -0500 Subject: [PATCH] Use alternate search algorithm provided by params Co-authored-by: Carolyn Cole Co-authored-by: James R. Griffin III Co-authored-by: Eliot Jordan --- app/controllers/catalog_controller.rb | 10 ++++++++-- spec/controllers/catalog_controller_spec.rb | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 4f1f82efe..f89109b2a 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -789,7 +789,13 @@ def basic_response def search_service_context return {} unless Flipflop.multi_algorithm? - return {} unless params[:search_algorithm] == "alternate" - { search_builder_class: AlternateSearchBuilder } + return {} unless alternate_search_builder_class # use default if none specified + { search_builder_class: alternate_search_builder_class } + end + + def alternate_search_builder_class + "#{params[:search_algorithm]}_search_builder".camelize.constantize + rescue NameError + nil end end diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb index aa7bcbf28..b07f1ec2f 100644 --- a/spec/controllers/catalog_controller_spec.rb +++ b/spec/controllers/catalog_controller_spec.rb @@ -146,6 +146,14 @@ expect(repository).to have_received(:search).with(instance_of(AlternateSearchBuilder)) end end + + context "when the search_algorithm parameter is set to 'not_a_real_class'" do + it "uses the default search builder" do + get :index, params: { q: "coffee", search_algorithm: "not_a_real_class" } + + expect(repository).to have_received(:search).with(instance_of(SearchBuilder)) + end + end end context "when the multi-algorithm feature is off" do