Skip to content

Commit

Permalink
Merge pull request #234 from alphagov/bb-case-insen
Browse files Browse the repository at this point in the history
Normalise user query for best bets
  • Loading branch information
csutter authored Mar 6, 2024
2 parents 5d01bcf + 969216f commit c3c444b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/services/discovery_engine/query/best_bets_boost.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module DiscoveryEngine::Query
class BestBetsBoost
def initialize(query_string)
@query_string = query_string
@query_string = query_string.strip.downcase.gsub(/\s+/, " ")
end

def boost_specs
Expand Down
20 changes: 19 additions & 1 deletion spec/services/discovery_engine/query/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
end
end

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

Expand All @@ -171,6 +171,24 @@
end
end

context "when searching for a query with a best bet in a different case and whitespace" do
# see test section in YAML config
let(:query_params) { { q: " I want to TEST a sInGlE best bET " } }

let(:expected_boost_specs) do
super() + [{
boost: 1,
condition: 'link: ANY("/here/you/go")',
}]
end

it "calls the client with the expected parameters" do
expect(client).to have_received(:search).with(
hash_including(boost_spec: { condition_boost_specs: expected_boost_specs }),
)
end
end

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

0 comments on commit c3c444b

Please sign in to comment.