blacklight 5.9.4 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_facets.scss +11 -10
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +14 -14
- data/app/helpers/blacklight/configuration_helper_behavior.rb +16 -10
- data/app/helpers/blacklight/facets_helper_behavior.rb +15 -14
- data/app/helpers/blacklight/url_helper_behavior.rb +1 -1
- data/app/models/bookmark.rb +1 -4
- data/app/models/search.rb +3 -6
- data/app/views/catalog/_facet_layout.html.erb +2 -2
- data/app/views/catalog/_facet_limit.html.erb +5 -3
- data/app/views/catalog/_facet_pivot.html.erb +4 -4
- data/app/views/catalog/_home_text.html.erb +8 -48
- data/app/views/catalog/_index_default.html.erb +3 -3
- data/app/views/catalog/_show_default.html.erb +3 -3
- data/app/views/catalog/_sms_form.html.erb +1 -1
- data/app/views/catalog/facet.html.erb +1 -1
- data/blacklight.gemspec +1 -1
- data/config/jetty.yml +0 -3
- data/config/locales/blacklight.de.yml +2 -0
- data/config/locales/blacklight.en.yml +2 -0
- data/config/locales/blacklight.es.yml +2 -0
- data/config/locales/blacklight.fr.yml +2 -0
- data/config/locales/blacklight.pt-BR.yml +2 -0
- data/lib/blacklight.rb +70 -26
- data/lib/blacklight/abstract_repository.rb +29 -0
- data/lib/blacklight/base.rb +7 -7
- data/lib/blacklight/bookmarks.rb +5 -5
- data/lib/blacklight/catalog.rb +34 -19
- data/lib/blacklight/catalog/search_context.rb +1 -1
- data/lib/blacklight/configuration.rb +112 -46
- data/lib/blacklight/configuration/facet_field.rb +9 -7
- data/lib/blacklight/configuration/field.rb +27 -0
- data/lib/blacklight/configuration/fields.rb +25 -20
- data/lib/blacklight/configuration/search_field.rb +6 -8
- data/lib/blacklight/configuration/solr_field.rb +3 -18
- data/lib/blacklight/configuration/sort_field.rb +6 -7
- data/lib/blacklight/document.rb +156 -0
- data/lib/blacklight/document/dublin_core.rb +41 -0
- data/lib/blacklight/document/email.rb +16 -0
- data/lib/blacklight/document/export.rb +107 -0
- data/lib/blacklight/document/extensions.rb +56 -0
- data/lib/blacklight/document/schema_org.rb +7 -0
- data/lib/blacklight/document/semantic_fields.rb +51 -0
- data/lib/blacklight/document/sms.rb +14 -0
- data/lib/blacklight/document_presenter.rb +3 -3
- data/lib/blacklight/exceptions.rb +9 -2
- data/lib/blacklight/facet.rb +21 -16
- data/lib/blacklight/request_builders.rb +60 -284
- data/lib/blacklight/routes.rb +1 -1
- data/lib/blacklight/search_builder.rb +130 -0
- data/lib/blacklight/search_helper.rb +316 -0
- data/lib/blacklight/solr.rb +1 -0
- data/lib/blacklight/solr/document.rb +4 -187
- data/lib/blacklight/solr/document/dublin_core.rb +3 -37
- data/lib/blacklight/solr/document/email.rb +4 -13
- data/lib/blacklight/solr/document/export.rb +3 -103
- data/lib/blacklight/solr/document/extensions.rb +4 -52
- data/lib/blacklight/solr/document/more_like_this.rb +1 -1
- data/lib/blacklight/solr/document/schema_org.rb +4 -4
- data/lib/blacklight/solr/document/sms.rb +4 -11
- data/lib/blacklight/solr/facet_paginator.rb +2 -2
- data/lib/blacklight/solr/search_builder.rb +264 -0
- data/lib/blacklight/solr_helper.rb +6 -261
- data/lib/blacklight/solr_repository.rb +30 -24
- data/lib/blacklight/solr_response.rb +3 -3
- data/lib/blacklight/user.rb +1 -2
- data/lib/blacklight/utils.rb +0 -23
- data/lib/generators/blacklight/controller_generator.rb +38 -0
- data/lib/generators/blacklight/document_generator.rb +20 -0
- data/lib/generators/blacklight/install_generator.rb +38 -39
- data/lib/generators/blacklight/models_generator.rb +2 -62
- data/lib/generators/blacklight/templates/catalog_controller.rb +3 -4
- data/lib/generators/blacklight/templates/config/{solr.yml → blacklight.yml} +3 -0
- data/lib/generators/blacklight/templates/config/jetty.yml +0 -3
- data/lib/generators/blacklight/templates/solr_document.rb +6 -6
- data/lib/generators/blacklight/test_support_generator.rb +1 -6
- data/lib/generators/blacklight/user_generator.rb +59 -0
- data/lib/railties/blacklight.rake +16 -7
- data/spec/controllers/catalog_controller_spec.rb +9 -15
- data/spec/features/facets_spec.rb +8 -0
- data/spec/helpers/configuration_helper_spec.rb +6 -13
- data/spec/helpers/facets_helper_spec.rb +3 -2
- data/spec/lib/blacklight/configuration_spec.rb +11 -38
- data/spec/lib/blacklight/{solr/document → document}/dublin_core_spec.rb +4 -4
- data/spec/lib/blacklight/{solr/document → document}/email_spec.rb +2 -2
- data/spec/lib/blacklight/{solr/document → document}/sms_spec.rb +2 -2
- data/spec/lib/blacklight/search_builder_spec.rb +145 -0
- data/spec/lib/blacklight/search_helper_spec.rb +775 -0
- data/spec/lib/blacklight/solr/document/more_like_this_spec.rb +1 -1
- data/spec/lib/blacklight/solr/search_builder_spec.rb +561 -0
- data/spec/lib/blacklight/solr_helper_spec.rb +5 -1291
- data/spec/lib/blacklight/solr_repository_spec.rb +13 -13
- data/spec/models/record_mailer_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- data/spec/views/catalog/_constraints.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +2 -2
- data/spec/views/catalog/index.atom.builder_spec.rb +1 -1
- data/tasks/blacklight.rake +1 -1
- data/template.demo.rb +1 -1
- metadata +33 -45
- data/doc/Adding-new-document-actions.md +0 -94
- data/doc/Atom-Responses.md +0 -90
- data/doc/Blacklight-Add-ons.md +0 -23
- data/doc/Blacklight-configuration.md +0 -411
- data/doc/Blacklight-on-Heroku.md +0 -100
- data/doc/Blacklight-out-of-the-box.md +0 -47
- data/doc/Bookmarks.md +0 -1
- data/doc/Code4Lib-2014.md +0 -94
- data/doc/Configuration---Facet-Fields.md +0 -130
- data/doc/Configuration---Results-View.md +0 -224
- data/doc/Configuration---Solr-fields.md +0 -106
- data/doc/Configuring-and-Customizing-Blacklight.md +0 -257
- data/doc/Configuring-rails-routes.md +0 -13
- data/doc/Contributing-to-Blacklight.md +0 -43
- data/doc/Examples.md +0 -120
- data/doc/Extending-or-Modifying-Blacklight-Search-Behavior.md +0 -141
- data/doc/Home.md +0 -100
- data/doc/How-to-release-a-version.md +0 -45
- data/doc/Indexing-your-data-into-solr.md +0 -36
- data/doc/Internationalization.md +0 -32
- data/doc/JSON-API.md +0 -83
- data/doc/Pagination.md +0 -52
- data/doc/Providing-your-own-view-templates.md +0 -69
- data/doc/Quickstart.md +0 -153
- data/doc/README_SOLR.md +0 -245
- data/doc/Saved-Searches.md +0 -5
- data/doc/Solr-Configuration.md +0 -154
- data/doc/Sunspot-for-indexing.md +0 -46
- data/doc/Support.md +0 -33
- data/doc/Theming.md +0 -62
- data/doc/Understanding-Rails-and-Blacklight.md +0 -75
- data/doc/User-Authentication.md +0 -60
- data/doc/_Sidebar.md +0 -9
- data/doc/testing.md +0 -58
|
@@ -102,7 +102,7 @@ module Blacklight::Catalog::SearchContext
|
|
|
102
102
|
@next_document = documents.last
|
|
103
103
|
end
|
|
104
104
|
rescue Blacklight::Exceptions::InvalidRequest => e
|
|
105
|
-
logger.warn "Unable to setup next and previous documents: #{e}"
|
|
105
|
+
Rails.logger.warn "Unable to setup next and previous documents: #{e}"
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
end
|
|
@@ -8,11 +8,14 @@ module Blacklight
|
|
|
8
8
|
require 'blacklight/configuration/tool_config'
|
|
9
9
|
# XXX this isn't very pretty, but it works.
|
|
10
10
|
require 'blacklight/configuration/fields'
|
|
11
|
+
require 'blacklight/configuration/field'
|
|
11
12
|
require 'blacklight/configuration/solr_field'
|
|
12
13
|
require 'blacklight/configuration/search_field'
|
|
13
14
|
require 'blacklight/configuration/facet_field'
|
|
14
15
|
require 'blacklight/configuration/sort_field'
|
|
15
16
|
include Fields
|
|
17
|
+
extend Deprecation
|
|
18
|
+
self.deprecation_horizon = 'blacklight 6.0'
|
|
16
19
|
|
|
17
20
|
# Set up Blacklight::Configuration.default_values to contain
|
|
18
21
|
# the basic, required Blacklight fields
|
|
@@ -21,52 +24,79 @@ module Blacklight
|
|
|
21
24
|
|
|
22
25
|
@default_values ||= begin
|
|
23
26
|
{
|
|
27
|
+
##
|
|
28
|
+
# === Search request configuration
|
|
29
|
+
##
|
|
24
30
|
# HTTP method to use when making requests to solr; valid
|
|
25
31
|
# values are :get and :post.
|
|
26
|
-
:
|
|
32
|
+
http_method: :get,
|
|
27
33
|
# The solr request handler ('qt') to use for search requests
|
|
28
|
-
:
|
|
34
|
+
qt: 'search',
|
|
29
35
|
# The path to send requests to solr.
|
|
30
|
-
:
|
|
36
|
+
solr_path: 'select',
|
|
31
37
|
# Default values of parameters to send with every search request
|
|
32
|
-
:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
default_solr_params: {},
|
|
39
|
+
## deprecated; use add_facet_field :include_in_request instead;
|
|
40
|
+
# if this is configured true, all facets will be included in the solr request
|
|
41
|
+
# unless explicitly disabled.
|
|
42
|
+
add_facet_fields_to_solr_request: false,
|
|
43
|
+
## deprecated; use add_index_field :include_in_request instead;
|
|
44
|
+
# if this is configured true, all show and index will be included in the solr request
|
|
45
|
+
# unless explicitly disabled.
|
|
46
|
+
add_field_configuration_to_solr_request: false,
|
|
47
|
+
##
|
|
48
|
+
# === Single document request configuration
|
|
49
|
+
##
|
|
36
50
|
# The solr rqeuest handler to use when requesting only a single document
|
|
37
|
-
:
|
|
51
|
+
document_solr_request_handler: 'document',
|
|
38
52
|
# THe path to send single document requests to solr
|
|
39
|
-
:
|
|
40
|
-
:
|
|
53
|
+
document_solr_path: nil,
|
|
54
|
+
document_unique_id_param: :id,
|
|
41
55
|
# Default values of parameters to send when requesting a single document
|
|
42
|
-
:
|
|
56
|
+
default_document_solr_params: {
|
|
43
57
|
## Blacklight provides these settings in the /document request handler
|
|
44
58
|
## by default, we just ask for all fields.
|
|
45
|
-
|
|
59
|
+
#fl: '*',
|
|
46
60
|
## this is a fancy way to say "find the document by id using
|
|
47
61
|
## the value in the id query parameter"
|
|
48
|
-
|
|
62
|
+
#q: "{!raw f=#{unique_key} v=$id}",
|
|
49
63
|
## disable features we don't need
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
#facet: false,
|
|
65
|
+
#rows: 1
|
|
52
66
|
},
|
|
67
|
+
##
|
|
68
|
+
# == Response models
|
|
69
|
+
## Class for sending and receiving requests from a search index
|
|
70
|
+
repository_class: nil,
|
|
71
|
+
## Class for converting Blacklight parameters to request parameters for the repository_class
|
|
72
|
+
search_builder_class: nil,
|
|
73
|
+
# model that maps index responses to the blacklight response model
|
|
74
|
+
response_model: nil,
|
|
75
|
+
# the model to use for each response document
|
|
76
|
+
document_model: nil,
|
|
77
|
+
# document presenter class used by helpers and views
|
|
78
|
+
document_presenter_class: nil,
|
|
79
|
+
##
|
|
80
|
+
# == Blacklight view configuration
|
|
81
|
+
##
|
|
82
|
+
navbar: OpenStructWithHashAccess.new(partials: { }),
|
|
53
83
|
# General configuration for all views
|
|
54
|
-
:
|
|
84
|
+
index: ViewConfig::Index.new(
|
|
55
85
|
# solr field to use to render a document title
|
|
56
|
-
:
|
|
86
|
+
title_field: nil,
|
|
57
87
|
# solr field to use to render format-specific partials
|
|
58
|
-
:
|
|
88
|
+
display_type_field: 'format',
|
|
59
89
|
# partials to render for each document(see #render_document_partials)
|
|
60
|
-
:
|
|
61
|
-
:
|
|
62
|
-
:
|
|
90
|
+
partials: [:index_header, :thumbnail, :index],
|
|
91
|
+
document_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
|
|
92
|
+
collection_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
|
|
63
93
|
# what field, if any, to use to render grouped results
|
|
64
|
-
:
|
|
94
|
+
group: false,
|
|
65
95
|
# additional response formats for search results
|
|
66
|
-
:
|
|
96
|
+
respond_to: OpenStructWithHashAccess.new()
|
|
67
97
|
),
|
|
68
98
|
# Additional configuration when displaying a single document
|
|
69
|
-
:
|
|
99
|
+
show: ViewConfig::Show.new(
|
|
70
100
|
# default route parameters for 'show' requests
|
|
71
101
|
# set this to a hash with additional arguments to merge into
|
|
72
102
|
# the route, or set `controller: :current` to route to the
|
|
@@ -76,9 +106,8 @@ module Blacklight
|
|
|
76
106
|
partials: [:show_header, :show],
|
|
77
107
|
document_actions: NestedOpenStructWithHashAccess.new(ToolConfig)
|
|
78
108
|
),
|
|
79
|
-
:navbar => OpenStructWithHashAccess.new(partials: { }),
|
|
80
109
|
# Configurations for specific types of index views
|
|
81
|
-
:
|
|
110
|
+
view: NestedOpenStructWithHashAccess.new(ViewConfig,
|
|
82
111
|
'list',
|
|
83
112
|
atom: {
|
|
84
113
|
if: false, # by default, atom should not show up as an alternative view
|
|
@@ -88,24 +117,27 @@ module Blacklight
|
|
|
88
117
|
if: false, # by default, rss should not show up as an alternative view
|
|
89
118
|
partials: [:document]
|
|
90
119
|
}),
|
|
120
|
+
#
|
|
121
|
+
# These fields are created and managed below by `defined_field_access`
|
|
122
|
+
# facet_fields
|
|
123
|
+
# index_fields
|
|
124
|
+
# show_fields
|
|
125
|
+
# sort_fields
|
|
126
|
+
# search_fields
|
|
127
|
+
##
|
|
128
|
+
# === Blacklight behavior configuration
|
|
129
|
+
##
|
|
91
130
|
# Maxiumum number of spelling suggestions to offer
|
|
92
|
-
:
|
|
131
|
+
spell_max: 5,
|
|
93
132
|
# Maximum number of results to show per page
|
|
94
|
-
:
|
|
133
|
+
max_per_page: 100,
|
|
95
134
|
# Options for the user for number of results to show per page
|
|
96
|
-
:
|
|
97
|
-
:
|
|
135
|
+
per_page: [10,20,50,100],
|
|
136
|
+
default_per_page: nil,
|
|
98
137
|
# how many searches to save in session history
|
|
99
138
|
# (TODO: move the value into the configuration?)
|
|
100
|
-
:
|
|
101
|
-
|
|
102
|
-
# if this is configured true, all facets will be included in the solr request
|
|
103
|
-
# unless explicitly disabled.
|
|
104
|
-
:add_facet_fields_to_solr_request => false,
|
|
105
|
-
## deprecated; use add_index_field :include_in_request instead;
|
|
106
|
-
# if this is configured true, all show and index will be included in the solr request
|
|
107
|
-
# unless explicitly disabled.
|
|
108
|
-
:add_field_configuration_to_solr_request => false
|
|
139
|
+
search_history_window: Blacklight::Catalog::SearchHistoryWindow,
|
|
140
|
+
default_facet_limit: 10
|
|
109
141
|
}
|
|
110
142
|
end
|
|
111
143
|
end
|
|
@@ -148,13 +180,43 @@ module Blacklight
|
|
|
148
180
|
end
|
|
149
181
|
end
|
|
150
182
|
|
|
151
|
-
def
|
|
183
|
+
def document_model
|
|
152
184
|
super || SolrDocument
|
|
153
185
|
end
|
|
186
|
+
alias_method :solr_document_model, :document_model
|
|
187
|
+
# only here to support alias_method
|
|
188
|
+
def document_model= *args
|
|
189
|
+
super
|
|
190
|
+
end
|
|
191
|
+
alias_method :solr_document_model=, :document_model=
|
|
192
|
+
deprecation_deprecate solr_document_model: :document_model, :solr_document_model= => :document_model=
|
|
193
|
+
|
|
194
|
+
def document_presenter_class
|
|
195
|
+
super || Blacklight::DocumentPresenter
|
|
196
|
+
end
|
|
154
197
|
|
|
155
|
-
def
|
|
198
|
+
def response_model
|
|
156
199
|
super || Blacklight::SolrResponse
|
|
157
200
|
end
|
|
201
|
+
alias_method :solr_response_model, :response_model
|
|
202
|
+
# only here to support alias_method
|
|
203
|
+
def response_model= *args
|
|
204
|
+
super
|
|
205
|
+
end
|
|
206
|
+
alias_method :solr_response_model=, :response_model=
|
|
207
|
+
deprecation_deprecate solr_response_model: :response_model, :solr_response_model= => :response_model=
|
|
208
|
+
|
|
209
|
+
def repository_class
|
|
210
|
+
super || Blacklight::SolrRepository
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def search_builder_class
|
|
214
|
+
super || Blacklight::Solr::SearchBuilder
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def default_per_page
|
|
218
|
+
super || per_page.first
|
|
219
|
+
end
|
|
158
220
|
|
|
159
221
|
##
|
|
160
222
|
# DSL helper
|
|
@@ -167,7 +229,7 @@ module Blacklight
|
|
|
167
229
|
# Returns default search field, used for simpler display in history, etc.
|
|
168
230
|
# if not set, defaults to first defined search field
|
|
169
231
|
def default_search_field
|
|
170
|
-
field =
|
|
232
|
+
field = super
|
|
171
233
|
field ||= search_fields.values.select { |field| field.default == true }.first
|
|
172
234
|
field ||= search_fields.values.first
|
|
173
235
|
|
|
@@ -178,7 +240,7 @@ module Blacklight
|
|
|
178
240
|
# Returns default sort field, used for simpler display in history, etc.
|
|
179
241
|
# if not set, defaults to first defined sort field
|
|
180
242
|
def default_sort_field
|
|
181
|
-
field =
|
|
243
|
+
field = super
|
|
182
244
|
field ||= sort_fields.values.select { |field| field.default == true }.first
|
|
183
245
|
field ||= sort_fields.values.first
|
|
184
246
|
|
|
@@ -186,7 +248,7 @@ module Blacklight
|
|
|
186
248
|
end
|
|
187
249
|
|
|
188
250
|
def default_title_field
|
|
189
|
-
|
|
251
|
+
document_model.unique_key || 'id'
|
|
190
252
|
end
|
|
191
253
|
|
|
192
254
|
##
|
|
@@ -240,6 +302,7 @@ module Blacklight
|
|
|
240
302
|
.reject { |k,v| v[:query] || v[:pivot] }
|
|
241
303
|
.map { |k,v| v.field }
|
|
242
304
|
end
|
|
305
|
+
deprecation_deprecate :facet_fields_to_add_to_solr
|
|
243
306
|
|
|
244
307
|
##
|
|
245
308
|
# Provide a 'deep copy' of Blacklight::Configuration that can be modifyed without affecting
|
|
@@ -257,8 +320,11 @@ module Blacklight
|
|
|
257
320
|
# too. These model names should not be `#dup`'ed or we might break ActiveModel::Naming.
|
|
258
321
|
def deep_copy
|
|
259
322
|
deep_dup.tap do |copy|
|
|
260
|
-
copy.
|
|
261
|
-
copy.
|
|
323
|
+
copy.repository_class = self.repository_class
|
|
324
|
+
copy.response_model = self.response_model
|
|
325
|
+
copy.document_model = self.document_model
|
|
326
|
+
copy.document_presenter_class = self.document_presenter_class
|
|
327
|
+
copy.search_builder_class = self.search_builder_class
|
|
262
328
|
end
|
|
263
329
|
end
|
|
264
330
|
alias_method :inheritable_copy, :deep_copy
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
module Blacklight
|
|
2
|
-
class Configuration::FacetField < Blacklight::Configuration::
|
|
2
|
+
class Configuration::FacetField < Blacklight::Configuration::Field
|
|
3
3
|
def normalize! blacklight_config = nil
|
|
4
4
|
self.query.stringify_keys! if self.query
|
|
5
5
|
|
|
6
|
-
if self.single and self.tag.blank? and self.ex.blank?
|
|
7
|
-
self.tag = "#{self.field}_single"
|
|
8
|
-
self.ex = "#{self.field}_single"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
6
|
self.collapse = true if self.collapse.nil?
|
|
12
7
|
self.show = true if self.show.nil?
|
|
13
|
-
self.if
|
|
8
|
+
self.if ||= self.show
|
|
14
9
|
|
|
15
10
|
super
|
|
11
|
+
|
|
12
|
+
if self.single and self.tag.blank? and self.ex.blank?
|
|
13
|
+
self.tag = "#{self.key}_single"
|
|
14
|
+
self.ex = "#{self.key}_single"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
self
|
|
16
18
|
end
|
|
17
19
|
end
|
|
18
20
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Blacklight
|
|
2
|
+
class Configuration::Field < OpenStructWithHashAccess
|
|
3
|
+
def normalize! blacklight_config = nil
|
|
4
|
+
self.field ||= self.key
|
|
5
|
+
self.key ||= self.field
|
|
6
|
+
|
|
7
|
+
self.label ||= default_label
|
|
8
|
+
|
|
9
|
+
self.if = true if self.if.nil?
|
|
10
|
+
self.unless = false if self.unless.nil?
|
|
11
|
+
|
|
12
|
+
self
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def validate!
|
|
16
|
+
raise ArgumentError.new("Must supply a field name") if self.field.nil?
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def default_label
|
|
20
|
+
if self.key.respond_to?(:titleize)
|
|
21
|
+
self.key.try(:titleize)
|
|
22
|
+
else
|
|
23
|
+
self.key.to_s.titleize
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -4,6 +4,8 @@ module Blacklight
|
|
|
4
4
|
# solr fields configuration
|
|
5
5
|
module Fields
|
|
6
6
|
extend ActiveSupport::Concern
|
|
7
|
+
extend Deprecation
|
|
8
|
+
self.deprecation_horizon = "blacklight 6.0"
|
|
7
9
|
|
|
8
10
|
module ClassMethods
|
|
9
11
|
|
|
@@ -13,7 +15,7 @@ module Blacklight
|
|
|
13
15
|
|
|
14
16
|
self.default_values[key.pluralize.to_sym] = ActiveSupport::OrderedHash.new
|
|
15
17
|
|
|
16
|
-
base_class_name = options.fetch(:class,
|
|
18
|
+
base_class_name = options.fetch(:class, Field)
|
|
17
19
|
|
|
18
20
|
unless self.const_defined? key.camelcase
|
|
19
21
|
class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
|
@@ -23,7 +25,7 @@ module Blacklight
|
|
|
23
25
|
|
|
24
26
|
class_eval <<-END_EVAL, __FILE__, __LINE__ + 1
|
|
25
27
|
def add_#{key}(*args, &block)
|
|
26
|
-
|
|
28
|
+
add_blacklight_field("#{key}", *args, &block)
|
|
27
29
|
end
|
|
28
30
|
END_EVAL
|
|
29
31
|
end
|
|
@@ -32,41 +34,41 @@ module Blacklight
|
|
|
32
34
|
# Add a solr field configuration to the given configuration key
|
|
33
35
|
#
|
|
34
36
|
# The recommended and strongly encouraged format is a field name, configuration pair, e.g.:
|
|
35
|
-
#
|
|
37
|
+
# add_blacklight_field :index_field, 'format', :label => 'Format'
|
|
36
38
|
#
|
|
37
39
|
# Alternative formats include:
|
|
38
40
|
#
|
|
39
41
|
# * a field name and block format:
|
|
40
42
|
#
|
|
41
|
-
#
|
|
43
|
+
# add_blacklight_field :index_field, 'format' do |field|
|
|
42
44
|
# field.label = 'Format'
|
|
43
45
|
# end
|
|
44
46
|
#
|
|
45
47
|
# * a plain block:
|
|
46
48
|
#
|
|
47
|
-
#
|
|
49
|
+
# add_blacklight_field :index_field do |field|
|
|
48
50
|
# field.field = 'format'
|
|
49
51
|
# field.label = 'Format'
|
|
50
52
|
# end
|
|
51
53
|
#
|
|
52
54
|
# * a configuration hash:
|
|
53
55
|
#
|
|
54
|
-
#
|
|
56
|
+
# add_blacklight_field :index_field, :field => 'format', :label => 'Format'
|
|
55
57
|
#
|
|
56
58
|
# * a Field instance:
|
|
57
59
|
#
|
|
58
|
-
#
|
|
60
|
+
# add_blacklight_field :index_field, IndexField.new(:field => 'format', :label => 'Format')
|
|
59
61
|
#
|
|
60
62
|
# * an array of hashes:
|
|
61
63
|
#
|
|
62
|
-
#
|
|
64
|
+
# add_blacklight_field :index_field, [{:field => 'format', :label => 'Format'}, IndexField.new(:field => 'date', :label => 'Date')]
|
|
63
65
|
#
|
|
64
66
|
#
|
|
65
67
|
# @param String config_key
|
|
66
68
|
# @param Array *args
|
|
67
69
|
# @para
|
|
68
70
|
#
|
|
69
|
-
def
|
|
71
|
+
def add_blacklight_field config_key, *args, &block
|
|
70
72
|
field_config = case args.first
|
|
71
73
|
when String
|
|
72
74
|
field_config_from_key_and_hash(config_key, *args)
|
|
@@ -81,18 +83,20 @@ module Blacklight
|
|
|
81
83
|
end
|
|
82
84
|
|
|
83
85
|
# look up any dynamic fields
|
|
84
|
-
if field_config.field.to_s =~ /\*/ and luke_fields
|
|
86
|
+
if (field_config.field || field_config.key).to_s =~ /\*/ and luke_fields
|
|
87
|
+
wildcard_field = (field_config.field || field_config.key).to_s
|
|
85
88
|
salient_fields = luke_fields.select do |k,v|
|
|
86
|
-
k =~ Regexp.new("^" +
|
|
89
|
+
k =~ Regexp.new("^" + wildcard_field.gsub('*', '.+') + "$")
|
|
87
90
|
end
|
|
88
91
|
|
|
89
92
|
salient_fields.each do |field, luke_config|
|
|
90
93
|
config = field_config.dup
|
|
91
94
|
config.field = field
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
config.key = field
|
|
96
|
+
if self[config_key.pluralize][ config.key ]
|
|
97
|
+
self[config_key.pluralize][ config.key ] = config.merge(self[config_key.pluralize][ config.key ])
|
|
94
98
|
else
|
|
95
|
-
|
|
99
|
+
add_blacklight_field(config_key, config, &block)
|
|
96
100
|
end
|
|
97
101
|
end
|
|
98
102
|
|
|
@@ -106,10 +110,12 @@ module Blacklight
|
|
|
106
110
|
field_config.normalize!(self)
|
|
107
111
|
field_config.validate!
|
|
108
112
|
|
|
109
|
-
raise "A #{config_key} with the key #{field_config.
|
|
113
|
+
raise "A #{config_key} with the key #{field_config.key} already exists." if self[config_key.pluralize][field_config.key].present?
|
|
110
114
|
|
|
111
|
-
self[config_key.pluralize][ field_config.
|
|
115
|
+
self[config_key.pluralize][ field_config.key ] = field_config
|
|
112
116
|
end
|
|
117
|
+
alias_method :add_solr_field, :add_blacklight_field
|
|
118
|
+
deprecation_deprecate add_solr_field: :add_blacklight_field
|
|
113
119
|
|
|
114
120
|
protected
|
|
115
121
|
def luke_fields
|
|
@@ -129,17 +135,16 @@ module Blacklight
|
|
|
129
135
|
end
|
|
130
136
|
|
|
131
137
|
# Add a solr field by a solr field name and hash
|
|
132
|
-
def field_config_from_key_and_hash config_key,
|
|
138
|
+
def field_config_from_key_and_hash config_key, field_name, field_or_hash = {}
|
|
133
139
|
field_config = field_config_from_field_or_hash(config_key, field_or_hash)
|
|
134
|
-
field_config.
|
|
135
|
-
|
|
140
|
+
field_config.key = field_name
|
|
136
141
|
field_config
|
|
137
142
|
end
|
|
138
143
|
|
|
139
144
|
# Add multiple solr fields using a hash or Field instance
|
|
140
145
|
def field_config_from_array config_key, array_of_fields_or_hashes, &block
|
|
141
146
|
array_of_fields_or_hashes.map do |field_or_hash|
|
|
142
|
-
|
|
147
|
+
add_blacklight_field(config_key, field_or_hash, &block)
|
|
143
148
|
end
|
|
144
149
|
end
|
|
145
150
|
|