-
Notifications
You must be signed in to change notification settings - Fork 78
/
catalog_controller.rb
285 lines (253 loc) · 13.1 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
class CatalogController < ApplicationController
include Hydra::Catalog
include Hydra::Controller::ControllerBehavior
include Sufia::Catalog
include BlacklightAdvancedSearch::Controller
# These before_filters apply the hydra access controls
before_filter :enforce_show_permissions, only: :show
skip_before_filter :default_html_head
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
configure_blacklight do |config|
# 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 = Sufia::SearchBuilder
# Show gallery view
config.view.gallery.partials = [:index_header, :index]
config.view.slideshow.partials = [:index]
## 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: "title_tesim name_tesim"
}
# 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.add_facet_field solr_name("human_readable_type", :facetable), label: "Type", limit: 5
config.add_facet_field solr_name("resource_type", :facetable), label: "Resource Type", limit: 5
config.add_facet_field solr_name("creator", :facetable), label: "Creator", limit: 5
config.add_facet_field solr_name("keyword", :facetable), label: "Keyword", limit: 5
config.add_facet_field solr_name("subject", :facetable), label: "Subject", limit: 5
config.add_facet_field solr_name("language", :facetable), label: "Language", limit: 5
config.add_facet_field solr_name("based_near", :facetable), label: "Location", limit: 5
config.add_facet_field solr_name("publisher", :facetable), label: "Publisher", limit: 5
config.add_facet_field solr_name("file_format", :facetable), label: "File Format", 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("title", :stored_searchable), label: "Title", itemprop: 'name', if: false
config.add_index_field solr_name("description", :stored_searchable), label: "Description", itemprop: 'description', helper_method: :iconify_auto_link
config.add_index_field solr_name("keyword", :stored_searchable), label: "Keyword", itemprop: 'keywords', link_to_search: solr_name("keyword", :facetable)
config.add_index_field solr_name("subject", :stored_searchable), label: "Subject", itemprop: 'about', link_to_search: solr_name("subject", :facetable)
config.add_index_field solr_name("creator", :stored_searchable), label: "Creator", itemprop: 'creator', link_to_search: solr_name("creator", :facetable)
config.add_index_field solr_name("contributor", :stored_searchable), label: "Contributor", itemprop: 'contributor', link_to_search: solr_name("contributor", :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), label: "Publisher", itemprop: 'publisher', link_to_search: solr_name("publisher", :facetable)
config.add_index_field solr_name("based_near", :stored_searchable), label: "Location", itemprop: 'contentLocation', link_to_search: solr_name("based_near", :facetable)
config.add_index_field solr_name("language", :stored_searchable), label: "Language", itemprop: 'inLanguage', link_to_search: solr_name("language", :facetable)
config.add_index_field solr_name("date_uploaded", :stored_sortable, type: :date), label: "Date Uploaded", itemprop: 'datePublished', helper_method: :human_readable_date
config.add_index_field solr_name("date_modified", :stored_sortable, type: :date), label: "Date Modified", itemprop: 'dateModified', helper_method: :human_readable_date
config.add_index_field solr_name("date_created", :stored_searchable), label: "Date Created", itemprop: 'dateCreated'
config.add_index_field solr_name("rights", :stored_searchable), label: "Rights", helper_method: :rights_statement_links
config.add_index_field solr_name("resource_type", :stored_searchable), label: "Resource Type", link_to_search: solr_name("resource_type", :facetable)
config.add_index_field solr_name("format", :stored_searchable), label: "File Format", link_to_search: solr_name("format", :facetable)
config.add_index_field solr_name("identifier", :stored_searchable), label: "Identifier"
# 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), label: "Title"
config.add_show_field solr_name("description", :stored_searchable), label: "Description"
config.add_show_field solr_name("keyword", :stored_searchable), label: "Keyword"
config.add_show_field solr_name("subject", :stored_searchable), label: "Subject"
config.add_show_field solr_name("creator", :stored_searchable), label: "Creator"
config.add_show_field solr_name("contributor", :stored_searchable), label: "Contributor"
config.add_show_field solr_name("publisher", :stored_searchable), label: "Publisher"
config.add_show_field solr_name("based_near", :stored_searchable), label: "Location"
config.add_show_field solr_name("language", :stored_searchable), label: "Language"
config.add_show_field solr_name("date_uploaded", :stored_searchable), label: "Date Uploaded"
config.add_show_field solr_name("date_modified", :stored_searchable), label: "Date Modified"
config.add_show_field solr_name("date_created", :stored_searchable), label: "Date Created"
config.add_show_field solr_name("rights", :stored_searchable), label: "Rights"
config.add_show_field solr_name("resource_type", :stored_searchable), label: "Resource Type"
config.add_show_field solr_name("format", :stored_searchable), label: "File Format"
config.add_show_field solr_name("identifier", :stored_searchable), label: "Identifier"
# "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) 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 all_text_timv",
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.
# :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|
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|
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"
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|
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|
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|
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|
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|
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
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
solr_name = solr_name("id", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('based_near') do |field|
field.label = "Location"
solr_name = solr_name("based_near", :stored_searchable)
field.solr_local_parameters = {
qf: solr_name,
pf: solr_name
}
end
config.add_search_field('keyword') do |field|
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') do |field|
solr_name = solr_name("rights", :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 "#{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"
# If there are more than this many search results, no spelling ("did you
# mean") suggestion is offered.
config.spell_max = 5
end
# disable the bookmark control from displaying in gallery view
# Sufia doesn't show any of the default controls on the list view, so
# this method is not called in that context.
def render_bookmarks_control?
false
end
end