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

pulibrary / pdc_discovery / 3823446b-c57e-4abf-8330-d3cff9d77076

pending completion
3823446b-c57e-4abf-8330-d3cff9d77076

Pull #382

circleci

Hector Correa
When importing dataspace records, skip those that have matching records already imported from PDC Describe
Pull Request #382: Give priority to PDC Describe records when indexing records

5 of 5 new or added lines in 1 file covered. (100.0%)

1714 of 1932 relevant lines covered (88.72%)

102.07 hits per line

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

77.27
/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'
1✔
11
    redirect_to error_page
1✔
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
    config.add_index_field 'author_tesim', label: 'Author(s)', helper_method: :authors_search_results_helper
1✔
115
    config.add_index_field 'format', label: 'Format'
1✔
116
    config.add_index_field 'abstract_tsim', label: 'Abstract'
1✔
117
    config.add_index_field 'published_ssim', label: 'Published'
1✔
118
    config.add_index_field 'published_vern_ssim', label: 'Published'
1✔
119
    config.add_index_field 'genre_ssim', label: 'Type'
1✔
120
    config.add_index_field 'issue_date_ssim', label: 'Issue Date'
1✔
121

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

135
    config.add_show_field 'abstract_tsim', label: 'Abstract'
1✔
136
    config.add_show_field 'contributor_tsim', label: 'Author'
1✔
137
    config.add_show_field 'description_tsim', label: 'Description'
1✔
138
    config.add_show_field 'issue_date_ssim', label: 'Issued Date'
1✔
139
    config.add_show_field 'methods_tsim', label: 'Methods'
1✔
140

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

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

159
    config.add_search_field 'all_fields', label: 'All Fields'
1✔
160

161
    # Now we see how to over-ride Solr request handler defaults, in this
162
    # case for a BL "search field", which is really a dismax aggregate
163
    # of Solr search fields.
164

165
    config.add_search_field('title') do |field|
1✔
166
      # solr_parameters hash are sent to Solr as ordinary url query params.
167
      field.solr_parameters = {
1✔
168
        'spellcheck.dictionary': 'title',
169
        qf: '${title_qf}',
170
        pf: '${title_pf}'
171
      }
172
    end
173

174
    config.add_search_field('author') do |field|
1✔
175
      field.solr_parameters = {
1✔
176
        'spellcheck.dictionary': 'author',
177
        qf: '${author_qf}',
178
        pf: '${author_pf}'
179
      }
180
    end
181

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

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

204
    # If there are more than this many search results, no spelling ("did you
205
    # mean") suggestion is offered.
206
    config.spell_max = 5
1✔
207

208
    # # Configuration for autocomplete suggester
209
    # config.autocomplete_enabled = true
210
    # config.autocomplete_path = 'suggest'
211
    # # if the name of the solr.SuggestComponent provided in your solrconfig.xml is not the
212
    # # default 'mySuggester', uncomment and provide it below
213
    # # config.autocomplete_suggester = 'mySuggester'
214
  end
215

216
  # Returns the raw BibTex citation information
217
  def bibtex
1✔
218
    _unused, @document = search_service.fetch(params[:id])
×
219
    citation = @document.cite("BibTeX")
×
220
    send_data citation, filename: "#{@document.bibtex_id}.bibtex", type: 'text/plain', disposition: 'attachment'
×
221
  end
222

223
  def resolve_doi
1✔
224
    raise Blacklight::Exceptions::RecordNotFound unless params.key?(:doi)
×
225

226
    doi_query = params[:doi]
×
227
    query = { q: "uri_ssim:*\"#{doi_query}\"" }
×
228

229
    solr_response = search_service.repository.search(**query)
×
230
    documents = solr_response.documents
×
231

232
    raise Blacklight::Exceptions::RecordNotFound if documents.empty?
×
233
    document = documents.first
×
234

235
    redirect_to(solr_document_path(id: document.id))
×
236
  end
237

238
  def resolve_ark
1✔
239
    raise Blacklight::Exceptions::RecordNotFound unless params.key?(:ark)
×
240

241
    ark = params[:ark]
×
242
    ark_query = "uri_ssim:*\"#{ark}\""
×
243
    query = { q: ark_query }
×
244

245
    solr_response = search_service.repository.search(**query)
×
246
    documents = solr_response.documents
×
247

248
    raise Blacklight::Exceptions::RecordNotFound if documents.empty?
×
249
    document = documents.first
×
250

251
    redirect_to(solr_document_path(id: document.id))
×
252
  end
253
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