diff --git a/app/controllers/content_objects_controller.rb b/app/controllers/content_objects_controller.rb index 241d25e4..87381636 100644 --- a/app/controllers/content_objects_controller.rb +++ b/app/controllers/content_objects_controller.rb @@ -7,7 +7,7 @@ def index def show # We get the object URI passed as a parameter and pass to a new instance of ApiCall - object_data = ApiCall.new(object_uri: params[:object]).object_data + object_data = SolrQuery.new(object_uri: params[:object]).object_data # TODO: handle other error types if object_data['statusCode'] == 500 diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb index 2f80d389..de59efae 100644 --- a/app/helpers/link_helper.rb +++ b/app/helpers/link_helper.rb @@ -21,7 +21,13 @@ def ses_object_name(ses_id) # used where the object type is dynamic but we don't actually want a link # e.g. secondary information title - @ses_data[ses_id.to_i]&.singularize.downcase + @ses_data[ses_id.to_i]&.singularize&.downcase + end + + def ses_name(ses_id) + # used where we want an as-is SES name but without a link + # TODO: refactor into main helper method using optional parameter? + display_name(@ses_data[ses_id.to_i]) end def display_name(ses_name) diff --git a/app/models/api_call.rb b/app/models/api_call.rb index 34f066e0..c37be9d3 100644 --- a/app/models/api_call.rb +++ b/app/models/api_call.rb @@ -5,24 +5,11 @@ class ApiCall attr_reader :object_uri BASE_API_URI = "https://api.parliament.uk/new-solr/" - # BASE_API_URI = "https://api.parliament.uk/search-mock/" - # BASE_API_URI = "http://localhost:3000/search-mock/" def initialize(params) @object_uri = params[:object_uri] end - def object_data - return evaluated_response if evaluated_response['statusCode'] == 500 - - evaluated_response['response']['docs'].first - end - - def ruby_uri - # build_uri("#{BASE_API_URI}objects.json?object=#{object_uri}") - build_uri("#{BASE_API_URI}select?q=uri:%22#{object_uri}%22") - end - private def response_body diff --git a/app/models/command_paper.rb b/app/models/command_paper.rb new file mode 100644 index 00000000..10504e55 --- /dev/null +++ b/app/models/command_paper.rb @@ -0,0 +1,14 @@ +class CommandPaper < ContentObject + + def initialize(content_object_data) + super + end + + def template + 'search/objects/command_paper' + end + + def object_name + 'command paper' + end +end \ No newline at end of file diff --git a/app/models/committee_proceeding.rb b/app/models/committee_proceeding.rb new file mode 100644 index 00000000..c6c7aa8c --- /dev/null +++ b/app/models/committee_proceeding.rb @@ -0,0 +1,15 @@ +class CommitteeProceeding < ContentObject + + def initialize(content_object_data) + super + end + + def template + 'search/objects/committee_proceeding' + end + + def object_name + 'committee proceeding' + end + +end \ No newline at end of file diff --git a/app/models/content_object.rb b/app/models/content_object.rb index e257128a..78c126ee 100644 --- a/app/models/content_object.rb +++ b/app/models/content_object.rb @@ -198,16 +198,36 @@ def notes content_object_data['searcherNote_t'].first end - def related_items + def old_related_items # based on provided information, this will return one or more URIs of related item object pages - # if relation_t and relation_uri, gets a related item - # fields might be inconsistent - # link through to the item landing page + relation_uris = content_object_data['relation_t'] + + return if relation_uris.blank? + + relation_objects = [] - return if content_object_data['relation_t'].blank? + relation_uris.each do |relation_uri| + relation_data = SolrQuery.new(object_uri: relation_uri).object_data + relation_object = ContentObject.generate(relation_data) + relation_objects << relation_object + end + + relation_objects + end + + def related_items + relation_uris = content_object_data['relation_t'] + return if relation_uris.blank? + + related_objects = SolrMultiQuery.new(object_uris: relation_uris).object_data + + ret = [] + related_objects.each do |object| + ret << ContentObject.generate(object) + end - content_object_data['relation_t'] + ret end def parliamentary_session diff --git a/app/models/european_deposited_document.rb b/app/models/european_deposited_document.rb new file mode 100644 index 00000000..aee4194c --- /dev/null +++ b/app/models/european_deposited_document.rb @@ -0,0 +1,15 @@ +class EuropeanDepositedDocument < ContentObject + + def initialize(content_object_data) + super + end + + def template + 'search/objects/european_deposited_document' + end + + def object_name + 'european deposited document' + end + +end \ No newline at end of file diff --git a/app/models/european_material.rb b/app/models/european_material.rb new file mode 100644 index 00000000..1a596299 --- /dev/null +++ b/app/models/european_material.rb @@ -0,0 +1,15 @@ +class EuropeanMaterial < ContentObject + + def initialize(content_object_data) + super + end + + def template + 'search/objects/european_material' + end + + def object_name + 'european material' + end + +end \ No newline at end of file diff --git a/app/models/house_of_commons_paper.rb b/app/models/house_of_commons_paper.rb new file mode 100644 index 00000000..ca41a8f8 --- /dev/null +++ b/app/models/house_of_commons_paper.rb @@ -0,0 +1,14 @@ +class HouseOfCommonsPaper < ContentObject + + def initialize(content_object_data) + super + end + + def template + 'search/objects/house_of_commons_paper' + end + + def object_name + 'house of commons paper' + end +end \ No newline at end of file diff --git a/app/models/oral_answer_to_question.rb b/app/models/oral_answer_to_question.rb index cf40b5f5..71064313 100644 --- a/app/models/oral_answer_to_question.rb +++ b/app/models/oral_answer_to_question.rb @@ -27,7 +27,7 @@ def question_url def question_object return unless has_question? - question_data = ApiCall.new(object_uri: question_url).object_data + question_data = SolrQuery.new(object_uri: question_url).object_data ContentObject.generate(question_data) end end \ No newline at end of file diff --git a/app/models/question.rb b/app/models/question.rb index 9984566e..68cb7dc7 100644 --- a/app/models/question.rb +++ b/app/models/question.rb @@ -49,7 +49,7 @@ def correcting_object return if content_object_data['correctingItem_uri'].blank? - correcting_item_data = ApiCall.new(object_uri: content_object_data['correctingItem_uri']).object_data + correcting_item_data = SolrQuery.new(object_uri: content_object_data['correctingItem_uri']).object_data ContentObject.generate(correcting_item_data) end diff --git a/app/models/research_material.rb b/app/models/research_material.rb new file mode 100644 index 00000000..89bdf249 --- /dev/null +++ b/app/models/research_material.rb @@ -0,0 +1,15 @@ +class ResearchMaterial < ContentObject + + def initialize(content_object_data) + super + end + + def template + 'search/objects/research_material' + end + + def object_name + 'research material' + end + +end \ No newline at end of file diff --git a/app/models/solr_multi_query.rb b/app/models/solr_multi_query.rb new file mode 100644 index 00000000..b53e4d37 --- /dev/null +++ b/app/models/solr_multi_query.rb @@ -0,0 +1,33 @@ +class SolrMultiQuery < ApiCall + # for fetching related item data etc. + + require 'open-uri' + require 'net/http' + + attr_reader :object_uris + + BASE_API_URI = "https://api.parliament.uk/new-solr/" + + def initialize(params) + @object_uris = params[:object_uris] + end + + def object_data + return evaluated_response if evaluated_response['statusCode'] == 500 + + evaluated_response['response']['docs'] + end + + def ruby_uri + # this constructs q=uri: "www.google.com" OR uri: "www.apple.com" OR ... + + uri = build_uri("#{BASE_API_URI}select?q=#{search_string}&rows=50") + + # TODO: this currently returns the first 50 results; this should be set to a sensible number? + end + + def search_string + query = object_uris.join("%22 OR uri:%22") + "(uri:%22#{query}%22)" + end +end \ No newline at end of file diff --git a/app/models/solr_query.rb b/app/models/solr_query.rb index 0c90520b..d729fc5c 100644 --- a/app/models/solr_query.rb +++ b/app/models/solr_query.rb @@ -4,8 +4,6 @@ class SolrQuery < ApiCall attr_reader :object_uri - # BASE_API_URI = "https://api.parliament.uk/search-mock/" - # BASE_API_URI = "http://localhost:3000/search-mock/" BASE_API_URI = "https://api.parliament.uk/new-solr/" def initialize(params) @@ -19,8 +17,6 @@ def object_data end def ruby_uri - # build_uri("#{BASE_API_URI}objects.json?object=#{object_uri}") - build_uri("#{BASE_API_URI}select?q=uri:%22#{object_uri}%22") end end \ No newline at end of file diff --git a/app/views/search/fragments/_related_items.html.erb b/app/views/search/fragments/_related_items.html.erb index fc624e73..1821222a 100644 --- a/app/views/search/fragments/_related_items.html.erb +++ b/app/views/search/fragments/_related_items.html.erb @@ -1,8 +1,24 @@
+ + + + + + <% related_items.each do |related_item| %> -
- <%= link_to related_item, '/' %>
-
+
+ <%= link_to related_item.page_title, related_item.content_object_data['uri'] %>
+ <% if related_item.date %> + <%= related_item.date&.strftime(ApplicationHelper::DATE_DISPLAY_FORMAT) %> + <% end %> + <% if related_item.type %> + <%= ses_name(related_item.type) %>
+ <% end %> + <% if related_item.legislature %> + <%= ses_name(related_item.legislature) %>
+ <% end %> +
+
<% end %>
\ No newline at end of file