Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
PrevPrevious commit
NextNext commit
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.
  • Loading branch information
Alice Bartlett committed Apr 10, 2015
commit 962a37c73cd66d9204c1f26250c5ffa4cc4fcadd
15 changes: 12 additions & 3 deletions lib/search_api.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,9 +31,10 @@ def search_results
def scope_info
if is_scoped? && scope_object.present?
{
scope:{
title: scope_object.title,
"scope" =>{
"title" => scope_object.title,
},
"unscoped_results" => unscoped_results,
}
else
{}
Expand All@@ -53,7 +54,15 @@ def is_scoped?
end

def scope_object_link
params.filter('manual').first
@scope_object_link ||= params.filter('manual').first
end

def unscoped_results
@unscoped_results ||= api.unified_search(unscoped_rummager_request).to_hash
end

def unscoped_rummager_request
rummager_params.except(:filter_manual).merge(count: "3", reject_manual: scope_object_link)
end
end
end
15 changes: 12 additions & 3 deletions test/unit/search_api_test.rb
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,7 @@ class SearchAPITest < ActiveSupport::TestCase

setup do
@rummager_api = stub
@rummager_params = stub
@rummager_params = stub(except:{})
@search_params = stub(rummager_parameters: @rummager_params)
@search_api = SearchAPI.new(@rummager_api)
@search_results = stub
Expand All@@ -24,15 +24,19 @@ class SearchAPITest < ActiveSupport::TestCase
end
end

context "given an search scoped to a manual" do
context "given a search scoped to a manual" do
setup do
@manual_link = 'manual/manual-name'
@manual_title = 'Manual Title'

@govuk_result_title = "GOV.UK result"

@search_params.expects(:filtered_by?).with('manual').returns(true)
@search_params.expects(:filter).with('manual').returns([@manual_link])
@manual_search_response = stub(results: [stub(title: @manual_title)])
@unscoped_search_response = stub(to_hash:{title: @govuk_result_title})

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

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

should "return manual from rummager" do
search_response = @search_api.search(@search_params)
assert_equal({title: @manual_title}, search_response.fetch(:scope))
assert_equal({"title" => @manual_title }, search_response.fetch("scope"))
end

should "return three results for the whole of gov.uk from rummager" do
search_response = @search_api.search(@search_params)
assert_equal({title: @govuk_result_title }, search_response.fetch("unscoped_results"))
end
end
end