Skip to content

Commit

Permalink
Merge pull request #3314 from alphagov/use-v1-search-to-filter-world-…
Browse files Browse the repository at this point in the history
…locations

Use V1 search when filtering by world location
  • Loading branch information
csutter authored Mar 22, 2024
2 parents f66ced8 + 51cba63 commit a6cd24d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/lib/search/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def fetch_search_response(content_item)
def use_v2_api?
return false if ActiveModel::Type::Boolean.new.cast(filter_params["use_v1"])
return true if ActiveModel::Type::Boolean.new.cast(filter_params["use_v2"])
return false if filter_params["world_locations"].present?

content_item.base_path == SITE_SEARCH_FINDER_BASE_PATH
end
Expand Down
27 changes: 27 additions & 0 deletions spec/lib/search/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,33 @@ def result_item(id, title, score:, popularity:, updated:)
end
end

context "when filtering by world location on the site search finder" do
subject { described_class.new(content_item, { "world_locations" => "austria" }).search_results }

let(:content_item) do
ContentItem.new({
"base_path" => "/search/all",
"details" => {
"facets" => facets,
},
})
end

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 searching using a single query" do
subject { described_class.new(content_item, filter_params).search_results }

Expand Down

0 comments on commit a6cd24d

Please sign in to comment.