-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalog_controller.rb
504 lines (455 loc) · 23.7 KB
/
catalog_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# frozen_string_literal: true
class CatalogController < ApplicationController
include BlacklightAdvancedSearch::Controller
include Hydra::Catalog
include Hydra::Controller::ControllerBehavior
include BlacklightOaiProvider::Controller
# These before_action filters apply the hydra access controls
before_action :enforce_show_permissions, only: :show
def self.uploaded_field
solr_name('system_create', :stored_sortable, type: :date)
end
def self.modified_field
solr_name('system_modified', :stored_sortable, type: :date)
end
def self.title_field
solr_name('title', :stored_sortable)
end
def self.identifier
solr_name('identifier', :stored_sortable)
end
# CatalogController-scope behavior and configuration for BlacklightIiifSearch
include BlacklightIiifSearch::Controller
configure_blacklight do |config|
# configuration for Blacklight IIIF Content Search
config.iiif_search = {
full_text_field: 'all_text_tsimv',
object_relation_field: 'is_page_of_ssim',
supported_params: %w[q page],
autocomplete_handler: 'iiif_suggest',
suggester_name: 'iiifSuggester'
}
config.view.gallery.partials = %i[index_header index]
config.view.masonry.partials = [:index]
config.view.slideshow.partials = [:index]
config.show.tile_source_field = :content_metadata_image_iiif_info_ssm
config.show.partials.insert(1, :openseadragon)
# default advanced config values
config.advanced_search ||= Blacklight::OpenStructWithHashAccess.new
# config.advanced_search[:qt] ||= 'advanced'
config.advanced_search[:url_key] ||= 'advanced'
config.advanced_search[:query_parser] ||= 'dismax'
config.advanced_search[:form_solr_parameters] ||= {}
config.search_builder_class = CustomSearchBuilder
# Show gallery view
config.view.gallery.partials = %i[index_header index]
config.view.slideshow.partials = [:index]
# rubocop:disable Style/HashSyntax
# rubocop:disable Style/SymbolLiteral
## Default parameters to send to solr for all search-like requests. See also SolrHelper#solr_search_params
config.default_solr_params = {
qt: "search",
rows: 10,
qf: HYKU_METADATA_RENDERING_ATTRIBUTES.keys.map { |attribute| "#{attribute}_tesim" }
.join(' ') << " title_tesim description_tesim all_text_tsimv",
:"hl" => true,
:"hl.simple.pre" => "<span class='highlight'>",
:"hl.simple.post" => "</span>",
:"hl.snippets" => 30,
:"hl.fragsize" => 100
}
# rubocop:enable Style/SymbolLiteral
# rubocop:enable Style/HashSyntax
# Specify which field to use in the tag cloud on the homepage.
# To disable the tag cloud, comment out this line.
config.tag_cloud_field_name = Solrizer.solr_name("tag", :facetable)
# solr field configuration for document/show views
config.index.title_field = solr_name("title", :stored_searchable)
config.index.display_type_field = solr_name("has_model", :symbol)
config.index.thumbnail_field = 'thumbnail_path_ss'
# solr fields that will be treated as facets by the blacklight application
# The ordering of the field names is the order of the display
# config.facet_fields = {}
# config.add_facet_field solr_name("human_readable_type", :facetable), label: "Type", limit: 5
# config.add_facet_field 'resource_type_tesim', label: "Object Type", limit: 5
config.add_facet_field solr_name("creator", :facetable), limit: 5
config.add_facet_field solr_name("contributor", :facetable), limit: 5
config.add_facet_field solr_name("street", :facetable), limit: 5
config.add_facet_field solr_name("neighborhood", :facetable), limit: 5
config.add_facet_field solr_name("city", :facetable), limit: 5
config.add_facet_field solr_name("county", :facetable), limit: 5
config.add_facet_field solr_name("subject", :facetable), limit: 5
config.add_facet_field solr_name("people_represented", :facetable), limit: 5
config.add_facet_field solr_name("decade", :facetable), limit: 5
config.add_facet_field solr_name("resource_type", :facetable), limit: 5
config.add_facet_field solr_name("publisher", :facetable), limit: 5
config.add_facet_field solr_name("file_format", :facetable), limit: 5
config.add_facet_field solr_name('member_of_collections', :symbol), limit: 5, label: 'Collections'
# config.add_facet_field solr_name("keyword", :facetable), limit: 5
# config.add_facet_field 'location_tesim', label: "Location", limit: 5
# config.add_facet_field solr_name("location", :facetable), limit: 5
# config.add_facet_field solr_name("language", :facetable), limit: 5
# config.add_facet_field solr_name("based_near_label", :facetable), limit: 5
# config.add_facet_field solr_name("media_type", :facetable), limit: 5
# config.add_facet_field solr_name("file_format", :facetable), limit: 5
# Have BL send all facet field names to Solr, which has been the default
# previously. Simply remove these lines if you'd rather use Solr request
# handler defaults, or have no facets.
config.add_facet_fields_to_solr_request!
# solr fields to be displayed in the index (search results) view
# The ordering of the field names is the order of the display
config.add_index_field solr_name("identifier", :stored_searchable), itemprop: 'identifier'
# config.add_index_field solr_name("identifier", :stored_searchable), helper_method: :index_field_link, field_name: 'identifier'
config.add_index_field solr_name("title", :stored_searchable), itemprop: 'name', if: false
config.add_index_field solr_name("description", :stored_searchable), itemprop: 'description', helper_method: :iconify_auto_link
config.add_index_field solr_name("searchable_text", :stored_searchable), itemprop: 'searchable_text', label: 'Searchable Text', helper_method: :iconify_auto_link
# config.add_index_field solr_name("keyword", :stored_searchable), itemprop: 'keywords', link_to_search: solr_name("keyword", :facetable)
config.add_index_field solr_name("date_created", :stored_searchable), itemprop: 'dateCreated'
config.add_index_field solr_name("subject", :stored_searchable), itemprop: 'subject', link_to_search: solr_name("subject", :facetable)
# config.add_index_field solr_name("decade", :stored_searchable), itemprop: 'decade', link_to_search: solr_name("decade", :facetable)
# config.add_index_field solr_name("creator", :stored_searchable), itemprop: 'creator', link_to_search: solr_name("creator", :facetable)
# config.add_index_field solr_name("contributor", :stored_searchable), itemprop: 'contributor', link_to_search: solr_name("contributor", :facetable)
# config.add_index_field solr_name("location", :stored_searchable), itemprop: 'location', link_to_search: solr_name("location", :facetable)
# config.add_index_field solr_name("proxy_depositor", :symbol), label: "Depositor", helper_method: :link_to_profile
# config.add_index_field solr_name("depositor"), label: "Owner", helper_method: :link_to_profile
# config.add_index_field solr_name("publisher", :stored_searchable), itemprop: 'publisher', link_to_search: solr_name("publisher", :facetable)
# config.add_index_field solr_name("publisher", :stored_searchable), itemprop: 'publisher', link_to_search: solr_name("publisher", :facetable)
# config.add_index_field solr_name("based_near_label", :stored_searchable), itemprop: 'contentLocation', link_to_search: solr_name("based_near_label", :facetable)
# config.add_index_field solr_name("date_uploaded", :stored_sortable, type: :date), itemprop: 'datePublished', helper_method: :human_readable_date
# config.add_index_field solr_name("date_modified", :stored_sortable, type: :date), itemprop: 'dateModified', helper_method: :human_readable_date
# config.add_index_field solr_name("rights_statement", :stored_searchable), helper_method: :rights_statement_links
# config.add_index_field solr_name("license", :stored_searchable), helper_method: :license_links
# config.add_index_field solr_name("resource_type", :stored_searchable), link_to_search: solr_name("resource_type", :facetable)
# config.add_index_field solr_name("file_format", :stored_searchable), link_to_search: solr_name("file_format", :facetable)
# config.add_index_field solr_name("media_type", :stored_searchable), itemprop: 'media_type', link_to_search: solr_name("media_type", :facetable)
# config.add_index_field solr_name("embargo_release_date", :stored_sortable, type: :date), label: "Embargo release date", helper_method: :human_readable_date
# config.add_index_field solr_name("lease_expiration_date", :stored_sortable, type: :date), label: "Lease expiration date", helper_method: :human_readable_date
# config.add_index_field solr_name("language", :stored_searchable), itemprop: 'inLanguage', link_to_search: solr_name("language", :facetable)
config.add_index_field 'all_text_tsimv', highlight: true, helper_method: :render_ocr_snippets
# solr fields to be displayed in the show (single result) view
# The ordering of the field names is the order of the display
config.add_show_field solr_name("title", :stored_searchable)
config.add_show_field solr_name("description", :stored_searchable)
config.add_show_field solr_name("keyword", :stored_searchable)
config.add_show_field solr_name("subject", :stored_searchable)
config.add_show_field solr_name("creator", :stored_searchable)
config.add_show_field solr_name("contributor", :stored_searchable)
config.add_show_field solr_name("publisher", :stored_searchable)
# config.add_show_field solr_name("based_near_label", :stored_searchable)
config.add_show_field solr_name("language", :stored_searchable)
config.add_show_field solr_name("date_uploaded", :stored_searchable)
config.add_show_field solr_name("date_modified", :stored_searchable)
config.add_show_field solr_name("date_created", :stored_searchable)
config.add_show_field solr_name("rights_statement", :stored_searchable)
config.add_show_field solr_name("license", :stored_searchable)
config.add_show_field solr_name("resource_type", :stored_searchable)
config.add_show_field solr_name("format", :stored_searchable)
config.add_show_field solr_name("identifier", :stored_searchable)
# Shared Custom Metadata
config.add_show_field solr_name('alternative_title', :stored_searchable)
config.add_show_field solr_name('contributor_role', :stored_searchable)
config.add_show_field solr_name('creator_role', :stored_searchable)
config.add_show_field solr_name('date_digital', :stored_searchable)
config.add_show_field solr_name('digitization_specification', :stored_searchable)
config.add_show_field solr_name('extent', :stored_searchable)
config.add_show_field solr_name('location', :stored_searchable)
config.add_show_field solr_name('media_type', :stored_searchable)
config.add_show_field solr_name('mesh', :stored_searchable)
config.add_show_field solr_name('ordering_information', :stored_searchable)
config.add_show_field solr_name('collection_information', :stored_searchable)
config.add_show_field solr_name('people_represented', :stored_searchable)
config.add_show_field solr_name('resource_query', :stored_searchable)
# Art Work type
config.add_show_field solr_name('honoree', :stored_searchable)
config.add_show_field solr_name('type_of_honoree', :stored_searchable)
config.add_show_field solr_name('location_of_honoree', :stored_searchable)
config.add_show_field solr_name('location_of_contributor', :stored_searchable)
config.add_show_field solr_name('biography_of_contributor', :stored_searchable)
config.add_show_field solr_name('contributor_history', :stored_searchable)
config.add_show_field solr_name('contributor_description', :stored_searchable)
config.add_show_field solr_name('transcription_translation', :stored_searchable)
config.add_show_field solr_name('style', :stored_searchable)
config.add_show_field solr_name('technique', :stored_searchable)
config.add_show_field solr_name('material', :stored_searchable)
config.add_show_field solr_name('measurement', :stored_searchable)
config.add_show_field solr_name('cultural_context', :stored_searchable)
config.add_show_field solr_name('language_script', :stored_searchable)
config.add_show_field solr_name('place_original', :stored_searchable)
config.add_show_field solr_name('ornamentation', :stored_searchable)
config.add_show_field solr_name('exhibit_history', :stored_searchable)
config.add_show_field solr_name('data_source', :stored_searchable)
config.add_show_field solr_name('cataloguing_note', :stored_searchable)
config.add_show_field solr_name('object_location', :stored_searchable)
config.add_show_field solr_name('condition', :stored_searchable)
# Image Work Type
config.add_show_field solr_name('city', :stored_searchable)
config.add_show_field solr_name('code', :stored_searchable)
config.add_show_field solr_name('county', :stored_searchable)
config.add_show_field solr_name('decade', :stored_searchable)
config.add_show_field solr_name('invoice_information', :stored_searchable)
config.add_show_field solr_name('neighborhood', :stored_searchable)
config.add_show_field solr_name('operating_area', :stored_searchable)
config.add_show_field solr_name('photo_comment', :stored_searchable)
config.add_show_field solr_name('region', :stored_searchable)
config.add_show_field solr_name('series', :stored_searchable)
config.add_show_field solr_name('story', :stored_searchable)
config.add_show_field solr_name('street', :stored_searchable)
config.add_show_field solr_name('tab_heading', :stored_searchable)
# Text Work type
config.add_show_field solr_name('issue', :stored_searchable)
config.add_show_field solr_name('stored_text', :stored_searchable)
config.add_show_field solr_name('table_of_contents', :stored_searchable)
config.add_show_field solr_name('volume', :stored_searchable)
config.add_show_field solr_name('searchable_text', :stored_searchable)
# "fielded" search configuration. Used by pulldown among other places.
# For supported keys in hash, see rdoc for Blacklight::SearchFields
#
# Search fields will inherit the :qt solr request handler from
# config[:default_solr_parameters], OR can specify a different one
# with a :qt key/value. Below examples inherit, except for subject
# that specifies the same :qt as default for our own internal
# testing purposes.
#
# The :key is what will be used to identify this BL search field internally,
# as well as in URLs -- so changing it after deployment may break bookmarked
# urls. A display label will be automatically calculated from the :key,
# or can be specified manually to be different.
#
# This one uses all the defaults set by the solr request handler. Which
# solr request handler? The one set in config[:default_solr_parameters][:qt],
# since we aren't specifying it otherwise.
config.add_search_field('all_fields', label: 'All Fields', include_in_advanced_search: false, advanced_parse: false) do |field|
all_names = config.show_fields.values.map(&:field).join(" ")
title_name = solr_name("title", :stored_searchable)
field.solr_parameters = {
qf: "#{all_names} file_format_tesim title_tesim all_text_tsimv",
pf: title_name.to_s
}
end
# Now we see how to over-ride Solr request handler defaults, in this
# case for a BL "search field", which is really a dismax aggregate
# of Solr search fields.
# creator, title, description, publisher, date_created,
# subject, language, resource_type, format, identifier, based_near,
config.add_search_field('contributor') do |field|
# solr_parameters hash are sent to Solr as ordinary url query params.
field.solr_parameters = { "spellcheck.dictionary": "contributor" }
# :solr_local_parameters will be sent using Solr LocalParams
# syntax, as eg {! qf=$title_qf }. This is neccesary to use
# Solr parameter de-referencing like $title_qf.
# See: http://wiki.apache.org/solr/LocalParams
solr_name = solr_name("contributor", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('creator') do |field|
field.solr_parameters = { "spellcheck.dictionary": "creator" }
solr_name = solr_name("creator", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('title') do |field|
field.solr_parameters = {
"spellcheck.dictionary": "title"
}
solr_name = solr_name("title", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('description') do |field|
field.label = "Abstract or Summary"
field.solr_parameters = {
"spellcheck.dictionary": "description"
}
solr_name = solr_name("description", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('publisher') do |field|
field.solr_parameters = {
"spellcheck.dictionary": "publisher"
}
solr_name = solr_name("publisher", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('date_created') do |field|
field.solr_parameters = {
"spellcheck.dictionary": "date_created"
}
solr_name = solr_name("created", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('subject') do |field|
field.solr_parameters = {
"spellcheck.dictionary": "subject"
}
solr_name = solr_name("subject", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('language') do |field|
field.solr_parameters = {
"spellcheck.dictionary": "language"
}
solr_name = solr_name("language", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('resource_type') do |field|
field.solr_parameters = {
"spellcheck.dictionary": "resource_type"
}
solr_name = solr_name("resource_type", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('format') do |field|
field.include_in_advanced_search = false
field.solr_parameters = {
"spellcheck.dictionary": "format"
}
solr_name = solr_name("format", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('identifier') do |field|
field.include_in_advanced_search = false
field.solr_parameters = {
"spellcheck.dictionary": "identifier"
}
solr_name = solr_name("id", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
# config.add_search_field('based_near_label') do |field|
# field.label = "Location"
# field.solr_parameters = {
# "spellcheck.dictionary": "based_near_label"
# }
# solr_name = solr_name("based_near_label", :stored_searchable)
# field.solr_local_parameters = {
# qf: solr_name,
# pf: solr_name
# }
# end
config.add_search_field('keyword') do |field|
field.solr_parameters = {
"spellcheck.dictionary": "keyword"
}
solr_name = solr_name("keyword", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('depositor') do |field|
solr_name = solr_name("depositor", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('rights_statement') do |field|
solr_name = solr_name("rights_statement", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('license') do |field|
solr_name = solr_name("license", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('extent') do |field|
solr_name = solr_name("extent", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
# "sort results by" select (pulldown)
# label in pulldown is followed by the name of the SOLR field to sort by and
# whether the sort is ascending or descending (it must be asc or desc
# except in the relevancy case).
# label is key, solr field is value
config.add_sort_field "score desc, #{uploaded_field} desc", label: "relevance"
config.add_sort_field "#{title_field} desc", label: "title \u25BC"
config.add_sort_field "#{title_field} asc", label: "title \u25B2"
config.add_sort_field "#{uploaded_field} desc", label: "date uploaded \u25BC"
config.add_sort_field "#{uploaded_field} asc", label: "date uploaded \u25B2"
config.add_sort_field "#{modified_field} desc", label: "date modified \u25BC"
config.add_sort_field "#{modified_field} asc", label: "date modified \u25B2"
config.add_sort_field "#{identifier} asc", label: "item number"
# OAI Config fields
config.oai = {
provider: {
repository_name: ->(controller) { controller.send(:current_account)&.name.presence },
# repository_url: ->(controller) { controller.oai_catalog_url },
record_prefix: ->(controller) { controller.send(:current_account).oai_prefix },
admin_email: ->(controller) { controller.send(:current_account).oai_admin_email },
sample_id: ->(controller) { controller.send(:current_account).oai_sample_identifier }
},
document: {
limit: 100, # number of records returned with each request, default: 15
set_fields: [ # ability to define ListSets, optional, default: nil
{ label: 'collection', solr_field: 'isPartOf_ssim' }
]
}
}
# If there are more than this many search results, no spelling ("did you
# mean") suggestion is offered.
config.spell_max = 5
config.add_field_configuration_to_solr_request!
end
# This is overridden just to give us a JSON response for debugging.
def show
_, @document = fetch params[:id]
render json: @document.to_h
end
def iiif_search
_parent_response, @parent_document = fetch(params[:solr_document_id])
iiif_search = BlacklightIiifSearch::IiifSearch.new(iiif_search_params, iiif_search_config,
@parent_document)
@response, _document_list = search_results(iiif_search.solr_params)
iiif_search_response = BlacklightIiifSearch::IiifSearchResponse.new(@response,
@parent_document,
self)
json_results = iiif_search_response.annotation_list
json_results&.[]('resources')&.each do |result_hit|
next if result_hit['resource'].present?
result_hit['resource'] = {
"@type": "cnt:ContentAsText",
"chars": "Metadata match, see sidebar for details"
}
end
render json: json_results,
content_type: 'application/json'
end
end