-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #784 from alphagov/surface-other-results
Show other results from GOV.UK in a scoped search
- Loading branch information
Showing
11 changed files
with
348 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class ScopedSearchResultsPresenter < SearchResultsPresenter | ||
|
||
def to_hash | ||
super.merge({ | ||
is_scoped?: true, | ||
scope_title: scope_title, | ||
unscoped_results_any?: unscoped_results.any?, | ||
unscoped_result_count: result_count_string(unscoped_result_count), | ||
}) | ||
end | ||
|
||
private | ||
|
||
attr_reader :unscoped_results | ||
|
||
def filter_fields | ||
[] | ||
end | ||
|
||
def scope_title | ||
search_response["scope"]["title"] | ||
end | ||
|
||
def results | ||
result_list = search_response["results"].map { |result| build_scoped_result(result).to_hash } | ||
|
||
if unscoped_results.any? | ||
insertion_point = [result_list.count, 3].min | ||
unscoped_results_sublist = { results: unscoped_results, is_multiple_results: true } | ||
|
||
result_list.insert(insertion_point, unscoped_results_sublist) | ||
end | ||
result_list | ||
end | ||
|
||
def unscoped_result_count | ||
search_response["unscoped_results"]["total"] | ||
end | ||
|
||
def unscoped_results | ||
@unscoped_results ||= build_result_presenters | ||
|
||
end | ||
|
||
def build_result_presenters | ||
search_response["unscoped_results"]["results"].map { |result| build_result(result).to_hash } | ||
end | ||
|
||
def build_scoped_result(result) | ||
ScopedResult.new(search_parameters, result) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<li{{#external}} class="external"{{/external}}> | ||
<h3><a href="{{link}}" {{#external}}rel="external"{{/external}}>{{title}}</a></h3> | ||
|
||
{{#debug_score}} | ||
<p class="debug-link"> | ||
{{link}} | ||
</p> | ||
<p class="debug-info"> | ||
<span>Score: {{es_score}}</span> | ||
<span>Format: {{#government}}government{{/government}} {{format}}</span> | ||
</p> | ||
{{/debug_score}} | ||
|
||
{{#external}} | ||
<p class="meta"> | ||
<span class="visuallyhidden">Part of </span> | ||
<span class="url">{{ display_link }}</span> | ||
</p> | ||
{{/external}} | ||
|
||
{{#section}} | ||
<p class="meta crumbtrail"> | ||
<span class="visuallyhidden">Part of </span> | ||
<span class="section">{{formatted_section_name}}</span> | ||
{{#formatted_subsection_name}} | ||
<span class="visuallyhidden">, </span> | ||
<span class="subsection">{{ formatted_subsection_name }}</span> | ||
{{/formatted_subsection_name}} | ||
{{#formatted_subsubsection_name}} | ||
<span class="visuallyhidden">, </span> | ||
<span class="subsubsection">{{ formatted_subsubsection_name }}</span> | ||
{{/formatted_subsubsection_name}} | ||
</p> | ||
{{/section}} | ||
|
||
{{#metadata_any?}} | ||
<ul class="attributes"> | ||
{{#metadata}} | ||
<li> {{{.}}} </li> | ||
{{/metadata}} | ||
</ul> | ||
{{/metadata_any?}} | ||
|
||
{{#historic?}} | ||
{{#government_name}} | ||
<p class="historic"> | ||
First published during the {{government_name}} | ||
</p> | ||
{{/government_name}} | ||
{{/historic?}} | ||
|
||
<p>{{description}}</p> | ||
|
||
{{#sections_present?}} | ||
<ul class="sections"> | ||
{{#sections}} | ||
<li><a href="{{link}}#{{hash}}">{{title}}</a></li> | ||
{{/sections}} | ||
</ul> | ||
{{/sections_present?}} | ||
|
||
{{#examples_present?}} | ||
<ul class="examples"> | ||
{{#examples}} | ||
<li> | ||
<h4><a href="{{link}}">{{title}}</a></h4> | ||
<p>{{description}}</p> | ||
</li> | ||
{{/examples}} | ||
|
||
{{#suggested_filter_present?}} | ||
<li> | ||
<h4 class="see-all"><a href="{{suggested_filter_link}}">{{suggested_filter_title}}</a><h4> | ||
</li> | ||
{{/suggested_filter_present?}} | ||
</ul> | ||
{{/examples_present?}} | ||
|
||
{{^examples_present?}} | ||
{{#suggested_filter_present?}} | ||
<h4 class="see-all"><a href="{{suggested_filter_link}}">{{suggested_filter_title}}</a><h4> | ||
{{/suggested_filter_present?}} | ||
{{/examples_present?}} | ||
|
||
</li> |
Oops, something went wrong.