Skip to content

Commit

Permalink
Use v2 for all site search queries
Browse files Browse the repository at this point in the history
This switches the `/search/all` ("site search") finder over to use
`search-api-v2` exclusively now that our AB test has concluded with a
positive outcome.

- Instead of checking for AB test variant, check for site search finder
  base path to establish whether to use v2
- Add `use_v1` query parameter along the lines of the existing `use_v2`
  to force use of `search-api` in circumstances where `search-api-v2`
  would normally be used
  • Loading branch information
csutter committed Feb 27, 2024
1 parent 51e9ce0 commit 1457eb4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/lib/search/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# search results from rummager.
module Search
class Query
SITE_SEARCH_FINDER_BASE_PATH = "/search/all".freeze

include ActiveModel::Validations

attr_reader :filter_params
Expand Down Expand Up @@ -110,7 +112,10 @@ def fetch_search_response(content_item)
end

def use_v2_api?
ActiveModel::Type::Boolean.new.cast(filter_params["use_v2"]) || ab_params[:vertex] == "B"
return false if ActiveModel::Type::Boolean.new.cast(filter_params["use_v1"])
return true if ActiveModel::Type::Boolean.new.cast(filter_params["use_v2"])

content_item.base_path == SITE_SEARCH_FINDER_BASE_PATH
end
end
end
2 changes: 1 addition & 1 deletion spec/controllers/finders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@

describe "with legacy query parameters for publications" do
before do
search_api_request
search_api_request(search_api_app: "search-api-v2")
stub_content_store_has_item("/search/all", all_content_finder)

@default_params = { slug: "search/all" }
Expand Down
27 changes: 25 additions & 2 deletions spec/lib/search/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def stub_batch_search
"details" => {
"facets" => facets,
},
"base_path" => "/some/finder",
)
end

Expand Down Expand Up @@ -49,6 +50,26 @@ def result_item(id, title, score:, popularity:, updated:)
}
end

context "when manually overriding parameters to use the v1 API" do
subject { described_class.new(content_item, { "use_v1" => "true" }).search_results }

let(:content_item) { ContentItem.new({ "base_path" => "/search/all" }) }

before do
stub_search.to_return(body: {
"results" => [
result_item("/i-am-the-v1-api", "I am the v1 API", score: nil, updated: "14-12-19", popularity: 1),
],
}.to_json)
end

it "calls the v1 API" do
results = subject.fetch("results")
expect(results.length).to eq(1)
expect(results.first).to match(hash_including("_id" => "/i-am-the-v1-api"))
end
end

context "when manually overriding parameters to use the v2 API" do
subject { described_class.new(content_item, { "use_v2" => "true" }).search_results }

Expand All @@ -67,8 +88,10 @@ def result_item(id, title, score:, popularity:, updated:)
end
end

context "when in AB test variant B" do
subject { described_class.new(content_item, {}, ab_params: { vertex: "B" }).search_results }
context "when on the site search finder" do
subject { described_class.new(content_item, {}).search_results }

let(:content_item) { ContentItem.new({ "base_path" => "/search/all" }) }

before do
stub_search_v2.to_return(body: {
Expand Down

0 comments on commit 1457eb4

Please sign in to comment.