-
Notifications
You must be signed in to change notification settings - Fork 1
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 #24 from ukparliament/development
Development merge
- Loading branch information
Showing
49 changed files
with
48,483 additions
and
1,686 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,4 @@ def show | |
render template: @object.template, :locals => { :object => @object } | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,17 @@ | ||
# # The one and only search controller. | ||
class SearchController < ApplicationController | ||
|
||
# A method to render the search form. | ||
def form | ||
@page_title = 'Search' | ||
|
||
def index | ||
@page_title = "Search results" | ||
results = SolrSearch.new(search_params) | ||
|
||
@items = results.object_data | ||
@metadata = results.send(:evaluated_response)['response'] | ||
end | ||
|
||
# ## A method to render a results page. | ||
def results | ||
@page_title = 'Search results' | ||
|
||
# We get the document type from the URL parameter. | ||
document_type = params[:document_type] | ||
|
||
# We construct the URL string to grab the XML from. | ||
url = "#{BASE_API_URI}results/#{document_type}.rb" | ||
|
||
# We turn the URL string into a RUBY URI. | ||
uri = URI( url ) | ||
|
||
# We get the body of the response from deferencing the URI. | ||
response_body = Net::HTTP.get( uri ) | ||
|
||
# We evaluate the body and construct a Ruby hash. | ||
evaluated = eval( response_body ) | ||
|
||
# We render the search results template, passing the evaluated response body as results. | ||
render :template => 'search/results/results', :locals => { :results => evaluated } | ||
|
||
private | ||
|
||
def search_params | ||
params.permit(:query, :page, :type_ses) | ||
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
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,42 @@ | ||
class SolrSearch < ApiCall | ||
|
||
attr_reader :query, :page, :type | ||
|
||
def initialize(params) | ||
super | ||
@query = params[:query] | ||
@page = params[:page] | ||
@type = params[:type_ses] | ||
end | ||
|
||
def object_data | ||
return evaluated_response if evaluated_response['statusCode'] == 500 | ||
|
||
res = evaluated_response['response']['docs'] | ||
puts "response: #{res}" | ||
res | ||
end | ||
|
||
def result_uris | ||
object_data.map { |doc| doc["uri"] } | ||
end | ||
|
||
def start | ||
# offset number of rows | ||
return 0 if page.blank? | ||
|
||
page.to_i * rows | ||
end | ||
|
||
def rows | ||
# number of results per page; default is 10 in SOLR | ||
20 | ||
end | ||
|
||
def ruby_uri | ||
build_uri("#{BASE_API_URI}select?q=%22#{query}%22&rows=#{rows}&start=#{start}") | ||
end | ||
|
||
# TODO: we can search for a specific term / filter by adding to the query string | ||
# select?q=type_ses:#{type} | ||
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
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
<section id="text" class="content-section"> | ||
<div class="about-item"> | ||
<h3 class="content-heading" id="answer">Answer</h3> | ||
<%= raw(object.answer_text) %> | ||
</div> | ||
</section> | ||
<div class="about-item"> | ||
<h3 class="content-heading" id="answer">Answer</h3> | ||
<%= raw sanitize object.answer_text, tags: %w(strong em a br) %> | ||
</div> |
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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
<section id="text" class="content-section"> | ||
<div class="about-item"> | ||
<h3 class="content-heading" id="corrected-answer">Corrected answer</h3> | ||
<%= raw(object.corrected_answer) %> | ||
</div> | ||
<div class="about-item"> | ||
<%= link_to object.corrected_item_link %> | ||
</div> | ||
</section> | ||
<div class="about-item"> | ||
<h3 class="content-heading" id="corrected-answer">Corrected answer</h3> | ||
<%= raw(object.corrected_answer) %> | ||
</div> | ||
<div class="about-item"> | ||
<%= link_to object.corrected_item_link %> | ||
</div> |
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,7 @@ | ||
<div class="about-item"> | ||
<div class="callout"> | ||
When a parliamentary session comes to an end Parliament is prorogued until the next session begins. Prorogation | ||
is the formal end to the parliamentary year. A 'prorogation answer' to a written question may be issued by a | ||
Minister if it has not been possible to provide a substantive answer in the time available before Prorogation. | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
<section id="text" class="content-section"> | ||
<div class="about-item"> | ||
<h3 class="content-heading" id="question">Question</h3> | ||
<%= raw(object.question_text) %> | ||
</div> | ||
</section> | ||
<div class="about-item"> | ||
<h3 class="content-heading" id="question">Question</h3> | ||
<%= raw sanitize object.question_text, tags: %w(strong em a br) %> | ||
</div> |
2 changes: 1 addition & 1 deletion
2
app/views/search/fragments/_registered_interest_declared.html.erb
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div class="about-item"> | ||
<h3 class="content-heading" id="registered-interest-declared">Registered interest declared</h3> | ||
<%= registered_interest_declared %> | ||
<%= boolean_yes_no(registered_interest) %> | ||
</div> |
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 |
---|---|---|
@@ -1,18 +1,24 @@ | ||
<!--like content section, this needs to be properly vertically spaced--> | ||
|
||
<div class="about-item"> | ||
<h3 class="content-heading" id="related-items">Related items</h3> | ||
<% related_items.each do |related_item| %> | ||
<div> | ||
<%= link_to related_item.page_title, related_item.content_object_data['uri'] %><br/> | ||
<% if related_item.date %> | ||
<%= related_item.date&.strftime(ApplicationHelper::DATE_DISPLAY_FORMAT) %> | ||
<% end %> | ||
<% if related_item.type %> | ||
<%= ses_name(related_item.type) %><br/> | ||
<% end %> | ||
<% if related_item.legislature %> | ||
<%= ses_name(related_item.legislature) %><br/> | ||
<% end %> | ||
</div> | ||
<br/> | ||
<% end %> | ||
<div class="flex-list"> | ||
<% related_items[:items].each do |related_item| %> | ||
<div> | ||
<% unless related_item.content_object_data['uri'].blank? %> | ||
<%= link_to(related_item.page_title, object_show_url(:object => related_item.content_object_data['uri'])) %> | ||
<br/> | ||
<% end %> | ||
<% if related_item.date %> | ||
<%= related_item.date&.strftime(ApplicationHelper::DATE_DISPLAY_FORMAT) %><br/> | ||
<% end %> | ||
<% if related_item.type %> | ||
<%= related_items[:ses_lookup][related_item.type] %><br/> | ||
<% end %> | ||
<% unless related_item.legislature.blank? %> | ||
<%= related_items[:ses_lookup][related_item.legislature] %><br/> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> |
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,23 @@ | ||
<% content_for(:before_title) do %> | ||
<%= link_to('UK Parliament', root_path) %> / <%= link_to('Open data', root_path) %><br/> | ||
<div id="top"></div> | ||
<% end %> | ||
|
||
<section> | ||
<h3>Search results</h3> | ||
|
||
<h6>Found <%= @metadata['numFound'] %> results</h6> | ||
|
||
<ul> | ||
<% @items.each do |item| %> | ||
<li> | ||
<%= link_to(item["title_t"], object_show_url(:object => item["uri"])) %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
|
||
</section> | ||
|
||
<%= button_to "1", search_url(query: params[:query], page: 1), { method: :post } %> | ||
<%= button_to "2", search_url(query: params[:query], page: 2), { method: :post } %> | ||
<%= button_to "3", search_url(query: params[:query], page: 3), { method: :post } %> |
Oops, something went wrong.