Skip to content

Commit

Permalink
Use alternate search algorithm provided by params
Browse files Browse the repository at this point in the history
Co-authored-by: Carolyn Cole <carolyncole@users.noreply.github.com>
Co-authored-by: James R. Griffin III <jrgriffiniii@users.noreply.github.com>
Co-authored-by: Eliot Jordan <eliotjordan@users.noreply.github.com>
  • Loading branch information
4 people committed Nov 7, 2023
1 parent 88396a9 commit 2b592cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b592cb

Please sign in to comment.