Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to reject links #143

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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