Skip to content

Commit

Permalink
Merge pull request #143 from alphagov/reject-link
Browse files Browse the repository at this point in the history
Add ability to reject links
  • Loading branch information
csutter authored Dec 8, 2023
2 parents 65ed9e0 + 31b608e commit 49d13fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/services/discovery_engine/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def discovery_engine_params
page_size:,
offset:,
order_by:,
filter:,
boost_spec:,
}.compact
end
Expand Down Expand Up @@ -68,6 +69,17 @@ def order_by
end
end

def filter
reject_links_filter
end

def reject_links_filter
return nil if query_params[:reject_link].blank?

reject_links = Array(query_params[:reject_link]).map { "\"#{_1}\"" }.join(",")
"NOT link: ANY(#{reject_links})"
end

def serving_config
Rails.configuration.discovery_engine_serving_config
end
Expand Down
20 changes: 20 additions & 0 deletions spec/services/discovery_engine/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@
end
end

context "with a single reject_link parameter" do
let(:query_params) { { q: "garden centres", reject_link: "/foo" } }

it "calls the client with the expected parameters" do
expect(client).to have_received(:search).with(
hash_including(filter: 'NOT link: ANY("/foo")'),
)
end
end

context "with several reject_link parameter" do
let(:query_params) { { q: "garden centres", reject_link: ["/foo", "/bar"] } }

it "calls the client with the expected parameters" do
expect(client).to have_received(:search).with(
hash_including(filter: 'NOT link: ANY("/foo","/bar")'),
)
end
end

context "when searching for a query that has a single best bets defined" do
# see test section in YAML config
let(:query_params) { { q: "i want to test a single best bet" } }
Expand Down

0 comments on commit 49d13fc

Please sign in to comment.