• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_discovery / 5af13607-7741-41ac-b110-c94c8a3ee0f0

pending completion
5af13607-7741-41ac-b110-c94c8a3ee0f0

Pull #441

circleci

hectorcorrea
Better error handling
Pull Request #441: Indexing to a new collection

99 of 99 new or added lines in 3 files covered. (100.0%)

1816 of 2220 relevant lines covered (81.8%)

95.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.71
/app/controllers/catalog_controller.rb
1
# frozen_string_literal: true
2

3
class CatalogController < ApplicationController
1✔
4
  include Blacklight::Catalog
1✔
5
  include BlacklightRangeLimit::ControllerOverride
1✔
6

7
  include Blacklight::Marc::Catalog
1✔
8

9
  rescue_from Blacklight::Exceptions::RecordNotFound do
1✔
10
    error_page = Rails.env.production? || Rails.env.staging? ? '/discovery/errors/not_found' : '/errors/not_found'
4✔
11
    redirect_to error_page
4✔
12
  end
13

14
  configure_blacklight do |config|
1✔
15
    ## Class for sending and receiving requests from a search index
16
    # config.repository_class = Blacklight::Solr::Repository
17
    #
18
    ## Class for converting Blacklight's url parameters to into request parameters for the search index
19
    # config.search_builder_class = ::SearchBuilder
20
    #
21
    ## Model that maps search index responses to the blacklight response model
22
    # config.response_model = Blacklight::Solr::Response
23
    #
24
    ## Should the raw solr document endpoint (e.g. /catalog/:id/raw) be enabled
25
    config.raw_endpoint.enabled = true
1✔
26

27
    ## Default parameters to send to solr for all search-like requests. See also SearchBuilder#processed_parameters
28
    config.default_solr_params = {
1✔
29
      rows: 10
30
    }
31

32
    # solr path which will be added to solr base url before the other solr params.
33
    # config.solr_path = 'select'
34
    # config.document_solr_path = 'get'
35

36
    # items to show per page, each number in the array represent another option to choose from.
37
    # config.per_page = [10,20,50,100]
38

39
    # solr field configuration for search results/index views
40
    config.index.title_field = 'title_tesim'
1✔
41
    # config.index.display_type_field = 'format'
42
    # config.index.thumbnail_field = 'thumbnail_path_ss'
43

44
    config.add_results_document_tool(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)
1✔
45

46
    config.add_results_collection_tool(:sort_widget)
1✔
47
    config.add_results_collection_tool(:per_page_widget)
1✔
48
    config.add_results_collection_tool(:view_type_group)
1✔
49

50
    config.add_show_tools_partial(:bookmark, partial: 'bookmark_control', if: :render_bookmarks_control?)
1✔
51
    config.add_show_tools_partial(:email, callback: :email_action, validator: :validate_email_params)
1✔
52
    config.add_show_tools_partial(:sms, if: :render_sms_action?, callback: :sms_action, validator: :validate_sms_params)
1✔
53
    config.add_show_tools_partial(:citation)
1✔
54

55
    config.add_nav_action(:bookmark, partial: 'blacklight/nav/bookmark', if: :render_bookmarks_control?)
1✔
56
    config.add_nav_action(:search_history, partial: 'blacklight/nav/search_history')
1✔
57

58
    # solr field configuration for document/show views
59
    # config.show.display_type_field = 'format'
60
    # config.show.thumbnail_field = 'thumbnail_path_ss'
61

62
    # solr fields that will be treated as facets by the blacklight application
63
    #   The ordering of the field names is the order of the display
64
    #
65
    # Setting a limit will trigger Blacklight's 'more' facet values link.
66
    # * If left unset, then all facet values returned by solr will be displayed.
67
    # * If set to an integer, then "f.somefield.facet.limit" will be added to
68
    # solr request, with actual solr request being +1 your configured limit --
69
    # you configure the number of items you actually want _displayed_ in a page.
70
    # * If set to 'true', then no additional parameters will be sent to solr,
71
    # but any 'sniffed' request limit parameters will be used for paging, with
72
    # paging at requested limit -1. Can sniff from facet.limit or
73
    # f.specific_field.facet.limit solr request params. This 'true' config
74
    # can be used if you set limits in :default_solr_params, or as defaults
75
    # on the solr side in the request handler itself. Request handler defaults
76
    # sniffing requires solr requests to be made with "echoParams=all", for
77
    # app code to actually have it echo'd back to see it.
78
    #
79
    # :show may be set to false if you don't want the facet to be drawn in the
80
    # facet bar
81
    #
82
    # set :index_range to true if you want the facet pagination view to have facet prefix-based navigation
83
    #  (useful when user clicks "more" on a large facet and wants to navigate alphabetically across a large set of results)
84
    # :index_range can be an array or range of prefixes that will be used to create the navigation (note: It is case sensitive when searching values)
85

86
    # config.add_facet_field 'example_pivot_field', label: 'Pivot Field', pivot: %w[format language_ssim], collapsing: true
87

88
    # config.add_facet_field 'example_query_facet_field', label: 'Publish Date', query: {
89
    #   years_5: { label: 'within 5 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 5} TO *]" },
90
    #   years_10: { label: 'within 10 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 10} TO *]" },
91
    #   years_25: { label: 'within 25 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 25} TO *]" }
92
    # }
93

94
    config.add_facet_field 'domain_ssi', label: 'Domain'                      # DSpace records only
1✔
95
    config.add_facet_field 'community_root_name_ssi', label: 'Community'
1✔
96
    config.add_facet_field 'subcommunity_name_ssi', label: 'Subcommunity'     # DSpace records only
1✔
97
    config.add_facet_field 'collection_name_ssi', label: 'Collection'
1✔
98
    config.add_facet_field 'collection_tag_ssim', label: 'Collection Tags'    # PDC Describe records only
1✔
99

100
    config.add_facet_field 'genre_ssim', label: 'Type'
1✔
101
    config.add_facet_field 'year_available_itsi', label: 'Year Published', range: true
1✔
102

103
    # Notice that is facet is not shown. Yet facet searches by this field do work
104
    # and we use them when users click on the "Keywords" links in the Show page.
105
    config.add_facet_field 'subject_all_ssim', label: 'Keywords', show: false
1✔
106

107
    # Have BL send all facet field names to Solr, which has been the default
108
    # previously. Simply remove these lines if you'd rather use Solr request
109
    # handler defaults, or have no facets.
110
    config.add_facet_fields_to_solr_request!
1✔
111

112
    # solr fields to be displayed in the index (search results) view
113
    #   The ordering of the field names is the order of the display
114

115
    # Notice that for the author field we key of the `author_tesim` field but in reality
116
    # we render a different value (see the helper). We use `author_tesim` in here because
117
    # that is a common field between all our records, the ones coming from DataSpace
118
    # and the ones coming from PDC Describe.
119
    config.add_index_field 'author_tesim', label: 'Author(s)', helper_method: :authors_search_results_helper
1✔
120

121
    config.add_index_field 'format', label: 'Format'
1✔
122
    config.add_index_field 'abstract_tsim', label: 'Abstract'
1✔
123
    config.add_index_field 'published_ssim', label: 'Published'
1✔
124
    config.add_index_field 'published_vern_ssim', label: 'Published'
1✔
125
    config.add_index_field 'genre_ssim', label: 'Type'
1✔
126
    config.add_index_field 'issue_date_ssim', label: 'Issue Date'
1✔
127

128
    # solr fields to be displayed in the show (single result) view
129
    #   The ordering of the field names is the order of the display
130
    config.add_show_field 'author_tesim', label: 'Author'
1✔
131
    config.add_show_field 'format', label: 'Format'
1✔
132
    config.add_show_field 'url_fulltext_ssim', label: 'URL'
1✔
133
    config.add_show_field 'url_suppl_ssim', label: 'More Information'
1✔
134
    config.add_show_field 'language_ssim', label: 'Language'
1✔
135
    config.add_show_field 'published_ssim', label: 'Published'
1✔
136
    config.add_show_field 'published_vern_ssim', label: 'Published'
1✔
137
    config.add_show_field 'lc_callnum_ssim', label: 'Call number'
1✔
138
    config.add_show_field 'isbn_ssim', label: 'ISBN'
1✔
139
    config.add_show_field 'handle_ssim', label: 'Handle'
1✔
140

141
    config.add_show_field 'abstract_tsim', label: 'Abstract'
1✔
142
    config.add_show_field 'contributor_tsim', label: 'Author'
1✔
143
    config.add_show_field 'description_tsim', label: 'Description'
1✔
144
    config.add_show_field 'issue_date_ssim', label: 'Issued Date'
1✔
145
    config.add_show_field 'methods_tsim', label: 'Methods'
1✔
146

147
    # "fielded" search configuration. Used by pulldown among other places.
148
    # For supported keys in hash, see rdoc for Blacklight::SearchFields
149
    #
150
    # Search fields will inherit the :qt solr request handler from
151
    # config[:default_solr_parameters], OR can specify a different one
152
    # with a :qt key/value. Below examples inherit, except for subject
153
    # that specifies the same :qt as default for our own internal
154
    # testing purposes.
155
    #
156
    # The :key is what will be used to identify this BL search field internally,
157
    # as well as in URLs -- so changing it after deployment may break bookmarked
158
    # urls.  A display label will be automatically calculated from the :key,
159
    # or can be specified manually to be different.
160

161
    # This one uses all the defaults set by the solr request handler. Which
162
    # solr request handler? The one set in config[:default_solr_parameters][:qt],
163
    # since we aren't specifying it otherwise.
164

165
    config.add_search_field 'all_fields', label: 'All Fields'
1✔
166

167
    # Now we see how to over-ride Solr request handler defaults, in this
168
    # case for a BL "search field", which is really a dismax aggregate
169
    # of Solr search fields.
170

171
    config.add_search_field('title') do |field|
1✔
172
      # solr_parameters hash are sent to Solr as ordinary url query params.
173
      field.solr_parameters = {
1✔
174
        'spellcheck.dictionary': 'title',
175
        qf: '${title_qf}',
176
        pf: '${title_pf}'
177
      }
178
    end
179

180
    config.add_search_field('author') do |field|
1✔
181
      field.solr_parameters = {
1✔
182
        'spellcheck.dictionary': 'author',
183
        qf: '${author_qf}',
184
        pf: '${author_pf}'
185
      }
186
    end
187

188
    # Specifying a :qt only to show it's possible, and so our internal automated
189
    # tests can test it. In this case it's the same as
190
    # config[:default_solr_parameters][:qt], so isn't actually neccesary.
191
    config.add_search_field('subject') do |field|
1✔
192
      field.qt = 'search'
1✔
193
      field.solr_parameters = {
1✔
194
        'spellcheck.dictionary': 'subject',
195
        qf: '${subject_qf}',
196
        pf: '${subject_pf}'
197
      }
198
    end
199

200
    # "sort results by" select (pulldown)
201
    # label in pulldown is followed by the name of the Solr field to sort by and
202
    # whether the sort is ascending or descending (it must be asc or desc
203
    # except in the relevancy case). Add the sort: option to configure a
204
    # custom Blacklight url parameter value separate from the Solr sort fields.
205
    config.add_sort_field 'relevance', sort: 'score desc, year_available_itsi desc, title_si asc', label: 'relevance'
1✔
206
    config.add_sort_field 'year', sort: 'year_available_itsi desc, title_si asc', label: 'year'
1✔
207
    config.add_sort_field 'author', sort: 'author_si asc, title_si asc', label: 'author'
1✔
208
    config.add_sort_field 'title', sort: 'title_si asc, year_available_itsi desc', label: 'title'
1✔
209

210
    # If there are more than this many search results, no spelling ("did you
211
    # mean") suggestion is offered.
212
    config.spell_max = 5
1✔
213

214
    # # Configuration for autocomplete suggester
215
    # config.autocomplete_enabled = true
216
    # config.autocomplete_path = 'suggest'
217
    # # if the name of the solr.SuggestComponent provided in your solrconfig.xml is not the
218
    # # default 'mySuggester', uncomment and provide it below
219
    # # config.autocomplete_suggester = 'mySuggester'
220
    config.search_state_fields = config.search_state_fields + [
1✔
221
      :doi, :ark, :id,
222
      :a # this is in the search parameters becuase the search bar is shown on the error page
223
    ]
224
  end
225

226
  # Returns the raw BibTex citation information
227
  def bibtex
1✔
228
    _unused, @document = search_service.fetch(params[:id])
×
229
    citation = @document.cite("BibTeX")
×
230
    send_data citation, filename: "#{@document.bibtex_id}.bibtex", type: 'text/plain', disposition: 'attachment'
×
231
  end
232

233
  def resolve_doi
1✔
234
    raise Blacklight::Exceptions::RecordNotFound unless params.key?(:doi)
×
235

236
    doi_query = params[:doi]
×
237
    query = { q: "uri_ssim:*\"#{doi_query}\"" }
×
238

239
    solr_response = search_service.repository.search(**query)
×
240
    documents = solr_response.documents
×
241

242
    raise Blacklight::Exceptions::RecordNotFound if documents.empty?
×
243
    document = documents.first
×
244

245
    redirect_to(solr_document_path(id: document.id))
×
246
  end
247

248
  def resolve_ark
1✔
249
    raise Blacklight::Exceptions::RecordNotFound unless params.key?(:ark)
×
250

251
    ark = params[:ark]
×
252
    ark_query = "uri_ssim:*\"#{ark}\""
×
253
    query = { q: ark_query }
×
254

255
    solr_response = search_service.repository.search(**query)
×
256
    documents = solr_response.documents
×
257

258
    raise Blacklight::Exceptions::RecordNotFound if documents.empty?
×
259
    document = documents.first
×
260

261
    redirect_to(solr_document_path(id: document.id))
×
262
  end
263

264
  # Create an endpoint for PPPL / OSTI harvesting that provides full datacite records
265
  def pppl_reporting_feed
1✔
266
    # Limit to items from PPPL
267
    pppl_query = 'data_source_ssi:pdc_describe community_root_name_ssi:"Princeton Plasma Physics Lab (PPPL)"'
×
268
    page = params["page"] || "1"
×
269
    per_page = params["per_page"] || "10"
×
270
    start = per_page.to_i * (page.to_i - 1)
×
271

272
    query = { q: pppl_query, fl: 'pdc_describe_json_ss', format: 'json', sort: 'timestamp desc', rows: per_page, start: start }
×
273

274
    solr_response = search_service.repository.search(**query)
×
275

276
    @documents = solr_response.documents
×
277
    respond_to do |format|
×
278
      format.json { render json: @documents }
×
279
    end
280
  end
281
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc