Skip to content

Commit 5b7049b

Browse files
author
Alice Bartlett
committed
Add request for extra results
When users search within a manual (this is doing a "scoped" search) we want to show them some results from the rest of GOV.UK (ie some "un-scoped" results) so that they are aware that here are other results available that might be useful. This commit adds a third rummager request for scoped searches which returns three un-scoped results. This request is built by removing the scoping `filer_manual[]=this/manual` and adding an extra parameter `reject_manual[]=this/manual` which tells rummager we don't want any results that occur in this manual.
1 parent 318731b commit 5b7049b

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

‎lib/search_api.rb‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ def search_results
3131
defscope_info
3232
ifis_scoped? && scope_object.present?
3333
{
34-
scope:{
35-
title:scope_object.title,
34+
"scope"=>{
35+
"title"=>scope_object.title,
3636
},
37+
"unscoped_results"=>unscoped_results,
3738
}
3839
else
3940
{}
@@ -53,7 +54,15 @@ def is_scoped?
5354
end
5455

5556
defscope_object_link
56-
params.filter('manual').first
57+
@link ||= params.filter('manual').first
58+
end
59+
60+
defunscoped_results
61+
@unscoped_results ||= api.unified_search(unscoped_rummager_request).to_hash
62+
end
63+
64+
defunscoped_rummager_request
65+
rummager_params.except(:filter_manual).merge(count: "3",reject_manual: scope_object_link)
5766
end
5867
end
5968
end

‎test/unit/search_api_test.rb‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class SearchAPITest < ActiveSupport::TestCase
55

66
setupdo
77
@rummager_api=stub
8-
@rummager_params=stub
8+
@rummager_params=stub(except: {})
99
@search_params=stub(rummager_parameters: @rummager_params)
1010
@search_api=SearchAPI.new(@rummager_api)
1111
@search_results=stub
@@ -24,15 +24,19 @@ class SearchAPITest < ActiveSupport::TestCase
2424
end
2525
end
2626

27-
context"given an search scoped to a manual"do
27+
context"given a search scoped to a manual"do
2828
setupdo
2929
@manual_link='manual/manual-name'
3030
@manual_title='Manual Title'
3131

32+
@govuk_result_title="GOV.UK result"
33+
3234
@search_params.expects(:filtered_by?).with('manual').returns(true)
3335
@search_params.expects(:filter).with('manual').returns([@manual_link])
3436
@manual_search_response=stub(results: [stub(title: @manual_title)])
37+
@unscoped_search_response=stub(to_hash: {title: @govuk_result_title})
3538

39+
@rummager_api.expects(:unified_search).with(count: "3",reject_manual: @manual_link).returns(@unscoped_search_response)
3640
@rummager_api.expects(:unified_search).with(filter_link: @manual_link,count: "1",fields: %w{title}).returns(@manual_search_response)
3741
end
3842

@@ -43,7 +47,12 @@ class SearchAPITest < ActiveSupport::TestCase
4347

4448
should"return manual from rummager"do
4549
search_response=@search_api.search(@search_params)
46-
assert_equal({title: @manual_title},search_response.fetch(:scope))
50+
assert_equal({"title"=>@manual_title},search_response.fetch("scope"))
51+
end
52+
53+
should"return three results for the whole of gov.uk from rummager"do
54+
search_response=@search_api.search(@search_params)
55+
assert_equal({title: @govuk_result_title},search_response.fetch("unscoped_results"))
4756
end
4857
end
4958
end

0 commit comments

Comments
(0)