blacklight 6.5.0 → 6.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +5 -0
  4. data/.rubocop_todo.yml +114 -213
  5. data/{.solr_wrapper → .solr_wrapper.yml} +0 -0
  6. data/.yardopts +3 -1
  7. data/Gemfile +0 -3
  8. data/Rakefile +1 -1
  9. data/VERSION +1 -1
  10. data/Vagrantfile +0 -2
  11. data/app/controllers/bookmarks_controller.rb +0 -2
  12. data/app/controllers/catalog_controller.rb +0 -2
  13. data/app/controllers/concerns/blacklight/base.rb +0 -1
  14. data/app/controllers/concerns/blacklight/bookmarks.rb +1 -1
  15. data/app/controllers/concerns/blacklight/catalog.rb +7 -11
  16. data/app/controllers/concerns/blacklight/controller.rb +11 -7
  17. data/app/controllers/concerns/blacklight/default_component_configuration.rb +24 -37
  18. data/app/controllers/concerns/blacklight/facet.rb +2 -11
  19. data/app/controllers/concerns/blacklight/request_builders.rb +1 -3
  20. data/app/controllers/concerns/blacklight/search_context.rb +0 -1
  21. data/app/controllers/concerns/blacklight/search_fields.rb +2 -2
  22. data/app/controllers/concerns/blacklight/search_helper.rb +14 -24
  23. data/app/controllers/concerns/blacklight/token_based_user.rb +0 -2
  24. data/app/helpers/blacklight/blacklight_helper_behavior.rb +27 -28
  25. data/app/helpers/blacklight/catalog_helper_behavior.rb +15 -15
  26. data/app/helpers/blacklight/component_helper_behavior.rb +2 -5
  27. data/app/helpers/blacklight/configuration_helper_behavior.rb +2 -3
  28. data/app/helpers/blacklight/deprecated_url_helper_behavior.rb +1 -3
  29. data/app/helpers/blacklight/facets_helper_behavior.rb +21 -25
  30. data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +1 -2
  31. data/app/helpers/blacklight/render_constraints_helper_behavior.rb +8 -9
  32. data/app/helpers/blacklight/render_partials_helper.rb +14 -13
  33. data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +1 -4
  34. data/app/helpers/blacklight/url_helper_behavior.rb +1 -1
  35. data/app/models/blacklight/facet_paginator.rb +2 -2
  36. data/app/models/concerns/blacklight/document.rb +1 -6
  37. data/app/models/concerns/blacklight/document/active_model_shim.rb +0 -1
  38. data/app/models/concerns/blacklight/document/cache_key.rb +3 -3
  39. data/app/models/concerns/blacklight/document/dublin_core.rb +0 -1
  40. data/app/models/concerns/blacklight/document/email.rb +0 -2
  41. data/app/models/concerns/blacklight/document/export.rb +1 -2
  42. data/app/models/concerns/blacklight/document/schema_org.rb +0 -2
  43. data/app/models/concerns/blacklight/document/sms.rb +0 -2
  44. data/app/models/concerns/blacklight/solr/document.rb +0 -1
  45. data/app/models/record_mailer.rb +0 -1
  46. data/app/models/solr_document.rb +0 -2
  47. data/app/presenters/blacklight/document_presenter.rb +14 -11
  48. data/app/presenters/blacklight/index_presenter.rb +5 -5
  49. data/app/presenters/blacklight/json_presenter.rb +0 -1
  50. data/app/presenters/blacklight/rendering/abstract_step.rb +0 -1
  51. data/app/presenters/blacklight/rendering/helper_method.rb +5 -5
  52. data/app/presenters/blacklight/rendering/link_to_facet.rb +1 -1
  53. data/app/presenters/blacklight/show_presenter.rb +4 -5
  54. data/app/services/blacklight/field_retriever.rb +8 -9
  55. data/app/views/catalog/_facet_limit.html.erb +1 -1
  56. data/blacklight.gemspec +4 -0
  57. data/lib/blacklight.rb +2 -2
  58. data/lib/blacklight/abstract_repository.rb +4 -3
  59. data/lib/blacklight/configuration.rb +57 -92
  60. data/lib/blacklight/configuration/context.rb +3 -3
  61. data/lib/blacklight/configuration/fields.rb +24 -7
  62. data/lib/blacklight/exceptions.rb +0 -2
  63. data/lib/blacklight/parameters.rb +1 -1
  64. data/lib/blacklight/search_builder.rb +92 -96
  65. data/lib/blacklight/search_state.rb +2 -1
  66. data/lib/blacklight/solr/repository.rb +3 -4
  67. data/lib/blacklight/solr/request.rb +0 -2
  68. data/lib/blacklight/solr/response/facets.rb +23 -28
  69. data/lib/blacklight/solr/response/group.rb +0 -1
  70. data/lib/blacklight/solr/response/group_response.rb +1 -5
  71. data/lib/blacklight/solr/response/pagination_methods.rb +0 -1
  72. data/lib/blacklight/solr/response/response.rb +1 -1
  73. data/lib/blacklight/solr/response/spelling.rb +0 -4
  74. data/lib/blacklight/solr/search_builder_behavior.rb +29 -41
  75. data/lib/blacklight/utils.rb +10 -7
  76. data/lib/generators/blacklight/assets_generator.rb +0 -1
  77. data/lib/generators/blacklight/document_generator.rb +0 -1
  78. data/lib/generators/blacklight/install_generator.rb +2 -6
  79. data/lib/generators/blacklight/models_generator.rb +0 -3
  80. data/lib/generators/blacklight/search_builder_generator.rb +0 -1
  81. data/lib/generators/blacklight/solr4_generator.rb +0 -2
  82. data/lib/generators/blacklight/solr5_generator.rb +15 -1
  83. data/lib/generators/blacklight/test_support_generator.rb +0 -1
  84. data/lib/railties/blacklight.rake +3 -3
  85. data/spec/controllers/blacklight/catalog/component_configuration_spec.rb +1 -4
  86. data/spec/controllers/blacklight/search_helper_spec.rb +5 -7
  87. data/spec/controllers/blacklight/suggest_search_spec.rb +2 -2
  88. data/spec/controllers/bookmarks_controller_spec.rb +2 -2
  89. data/spec/controllers/catalog_controller_spec.rb +6 -6
  90. data/spec/features/search_context_spec.rb +4 -5
  91. data/spec/features/search_formats_spec.rb +0 -6
  92. data/spec/helpers/blacklight_helper_spec.rb +7 -7
  93. data/spec/helpers/catalog_helper_spec.rb +10 -10
  94. data/spec/helpers/configuration_helper_spec.rb +3 -3
  95. data/spec/helpers/facets_helper_spec.rb +1 -2
  96. data/spec/helpers/render_constraints_helper_spec.rb +8 -0
  97. data/spec/integration/generators/blacklight/solr5_generator_spec.rb +60 -0
  98. data/spec/models/blacklight/document_spec.rb +1 -1
  99. data/spec/models/blacklight/search_builder_spec.rb +5 -4
  100. data/spec/models/blacklight/solr/search_builder_spec.rb +12 -18
  101. data/spec/presenters/pipeline_spec.rb +1 -1
  102. data/spec/spec_helper.rb +43 -0
  103. data/spec/views/catalog/_index_header_default.html.erb_spec.rb +1 -1
  104. data/spec/views/catalog/_show_tools.html.erb_spec.rb +1 -1
  105. data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +2 -2
  106. data/spec/views/catalog/_thumbnail_default.erb_spec.rb +1 -1
  107. data/spec/views/catalog/_view_type_group.html.erb_spec.rb +3 -3
  108. data/spec/views/catalog/index.html.erb_spec.rb +1 -1
  109. data/spec/views/catalog/index.json.jbuilder_spec.rb +2 -2
  110. data/tasks/blacklight.rake +3 -0
  111. metadata +61 -3
@@ -11,10 +11,10 @@ module Blacklight
11
11
  ##
12
12
  # Evaluate conditionals for a configuration with if/unless attributes
13
13
  #
14
- # @param displayable_config [#if,#unless] an object that responds to if/unless
14
+ # @param [#if,#unless] config an object that responds to if/unless
15
15
  # @return [Boolean]
16
16
  def evaluate_if_unless_configuration(config, *args)
17
- return config if config === true or config === false
17
+ return config if config == true or config == false
18
18
 
19
19
  if_value = !config.respond_to?(:if) ||
20
20
  config.if.nil? ||
@@ -32,7 +32,7 @@ module Blacklight
32
32
  when Symbol
33
33
  arity = context.method(proc_helper_or_boolean).arity
34
34
 
35
- if arity == 0
35
+ if arity.zero?
36
36
  context.send(proc_helper_or_boolean)
37
37
  else
38
38
  context.send(proc_helper_or_boolean, *args_for_procs_and_methods)
@@ -7,7 +7,6 @@ module Blacklight
7
7
  extend ActiveSupport::Concern
8
8
 
9
9
  module ClassMethods
10
-
11
10
  # Add a configuration block for a collection of solr fields
12
11
  def define_field_access(key, options = {})
13
12
  key = key.to_s if respond_to? :to_s
@@ -39,12 +38,20 @@ module Blacklight
39
38
  #
40
39
  # * a field name and block format:
41
40
  #
41
+ # @overload add_blacklight_field(config_key, field_key)
42
+ # @param [Symbol] config_key
43
+ # @param [Symbol,String] field_key
44
+ #
45
+ #
42
46
  # add_blacklight_field :index_field, 'format' do |field|
43
47
  # field.label = 'Format'
44
48
  # end
45
49
  #
46
50
  # * a plain block:
47
51
  #
52
+ # @overload add_blacklight_field(config_key)
53
+ # @param [Symbol] config_key
54
+ #
48
55
  # add_blacklight_field :index_field do |field|
49
56
  # field.field = 'format'
50
57
  # field.label = 'Format'
@@ -52,20 +59,28 @@ module Blacklight
52
59
  #
53
60
  # * a configuration hash:
54
61
  #
62
+ # @overload add_blacklight_field(config_key, options)
63
+ # @param [Symbol] config_key
64
+ # @param [Hash] options
65
+ #
55
66
  # add_blacklight_field :index_field, :field => 'format', :label => 'Format'
56
67
  #
57
68
  # * a Field instance:
58
69
  #
70
+ # @overload add_blacklight_field(config_key, field)
71
+ # @param [Symbol] config_key
72
+ # @param [Blacklight::Configuration::Field] field
73
+ #
74
+ #
59
75
  # add_blacklight_field :index_field, IndexField.new(:field => 'format', :label => 'Format')
60
76
  #
61
77
  # * an array of hashes:
62
78
  #
63
- # add_blacklight_field :index_field, [{:field => 'format', :label => 'Format'}, IndexField.new(:field => 'date', :label => 'Date')]
64
- #
79
+ # @overload add_blacklight_field(config_key, fields)
80
+ # @param [Symbol] config_key
81
+ # @param [Array<Blacklight::Configuration::Field, Hash>] fields
65
82
  #
66
- # @param String config_key
67
- # @param Array *args
68
- # @para
83
+ # add_blacklight_field :index_field, [{ :field => 'format', :label => 'Format' }, IndexField.new(:field => 'date', :label => 'Date')]
69
84
  #
70
85
  def add_blacklight_field config_key, *args, &block
71
86
  field_config = case args.first
@@ -121,8 +136,9 @@ module Blacklight
121
136
  end
122
137
 
123
138
  protected
139
+
124
140
  def luke_fields
125
- if @table[:luke_fields] === false
141
+ if @table[:luke_fields] == false
126
142
  return nil
127
143
  end
128
144
 
@@ -179,6 +195,7 @@ module Blacklight
179
195
  end
180
196
 
181
197
  private
198
+
182
199
  # convert a config key to the appropriate Field class
183
200
  def field_class_from_key key
184
201
  "Blacklight::Configuration::#{key.camelcase}".constantize
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Blacklight
3
3
  module Exceptions
4
-
5
4
  class AccessDenied < StandardError
6
5
  end
7
6
 
@@ -21,6 +20,5 @@ module Blacklight
21
20
  end
22
21
 
23
22
  class ECONNREFUSED < ::Errno::ECONNREFUSED; end
24
-
25
23
  end
26
24
  end
@@ -4,7 +4,7 @@ module Blacklight
4
4
  ##
5
5
  # Sanitize the search parameters by removing unnecessary parameters
6
6
  # from the provided parameters.
7
- # @param [Hash] source_params parameters
7
+ # @param [Hash] params parameters
8
8
  def self.sanitize params
9
9
  params.reject { |k,v| v.nil? }
10
10
  .except(:action, :controller, :id, :commit, :utf8)
@@ -11,14 +11,18 @@ module Blacklight
11
11
 
12
12
  attr_reader :processor_chain, :blacklight_params
13
13
 
14
- # @param [List<Symbol>,TrueClass] options a list of filter methods to run or true, to use the default methods
15
- # @param [Object] scope the scope where the filter methods reside in.
14
+
15
+ # @overload initialize(scope)
16
+ # @param [Object] scope scope the scope where the filter methods reside in.
17
+ # @overload initialize(processor_chain, scope)
18
+ # @param [List<Symbol>,TrueClass] processor_chain options a list of filter methods to run or true, to use the default methods
19
+ # @param [Object] scope scope the scope where the filter methods reside in.
16
20
  def initialize(*options)
17
21
  @scope = case options.size
18
22
  when 1
19
23
  options.first
20
24
  when 2
21
- if options.first === true
25
+ if options.first == true
22
26
  Deprecation.warn Blacklight::SearchBuilder, "SearchBuilder#initialize now takes only one parameter, the scope. Passing `true' will be removed in Blacklight 7"
23
27
  else
24
28
  @processor_chain = options.first
@@ -36,7 +40,7 @@ module Blacklight
36
40
 
37
41
  ##
38
42
  # Set the parameters to pass through the processor chain
39
- def with blacklight_params = {}
43
+ def with(blacklight_params = {})
40
44
  params_will_change!
41
45
  @blacklight_params = blacklight_params.dup
42
46
  self
@@ -44,7 +48,7 @@ module Blacklight
44
48
 
45
49
  ##
46
50
  # Update the :q (query) parameter
47
- def where conditions
51
+ def where(conditions)
48
52
  params_will_change!
49
53
  @blacklight_params[:q] = conditions
50
54
  self
@@ -52,55 +56,53 @@ module Blacklight
52
56
 
53
57
  ##
54
58
  # Append additional processor chain directives
55
- def append *addl_processor_chain
59
+ def append(*addl_processor_chain)
56
60
  params_will_change!
57
61
  builder = self.class.new(processor_chain + addl_processor_chain, scope)
58
62
  .with(blacklight_params)
59
63
  .merge(@merged_params)
60
64
  .reverse_merge(@reverse_merged_params)
61
65
 
62
- builder.start(@start) if @start
63
- builder.rows(@rows) if @rows
64
- builder.page(@page) if @page
65
- builder.facet(@facet) if @facet
66
-
66
+ builder.start = @start if @start
67
+ builder.rows = @rows if @rows
68
+ builder.page = @page if @page
69
+ builder.facet = @facet if @facet
67
70
  builder
68
71
  end
69
72
 
70
73
  ##
71
74
  # Converse to append, remove processor chain directives,
72
75
  # returning a new builder that's a copy of receiver with
73
- # specified change.
76
+ # specified change.
74
77
  #
75
78
  # Methods in argument that aren't currently in processor
76
- # chain are ignored as no-ops, rather than raising.
77
- def except *except_processor_chain
79
+ # chain are ignored as no-ops, rather than raising.
80
+ def except(*except_processor_chain)
78
81
  builder = self.class.new(processor_chain - except_processor_chain, scope)
79
82
  .with(blacklight_params)
80
83
  .merge(@merged_params)
81
84
  .reverse_merge(@reverse_merged_params)
82
85
 
83
- builder.start(@start) if @start
84
- builder.rows(@rows) if @rows
85
- builder.page(@page) if @page
86
- builder.facet(@facet) if @facet
87
-
86
+ builder.start = @start if @start
87
+ builder.rows = @rows if @rows
88
+ builder.page = @page if @page
89
+ builder.facet = @facet if @facet
88
90
  builder
89
91
  end
90
92
 
91
93
  ##
92
94
  # Merge additional, repository-specific parameters
93
- def merge extra_params, &block
95
+ def merge(extra_params, &block)
94
96
  if extra_params
95
97
  params_will_change!
96
98
  @merged_params.merge!(extra_params.to_hash, &block)
97
99
  end
98
100
  self
99
101
  end
100
-
102
+
101
103
  ##
102
104
  # "Reverse merge" additional, repository-specific parameters
103
- def reverse_merge extra_params, &block
105
+ def reverse_merge(extra_params, &block)
104
106
  if extra_params
105
107
  params_will_change!
106
108
  @reverse_merged_params.reverse_merge!(extra_params.to_hash, &block)
@@ -111,23 +113,18 @@ module Blacklight
111
113
  delegate :[], :key?, to: :to_hash
112
114
 
113
115
  # a solr query method
114
- # @param [Hash] extra_controller_params (nil) extra parameters to add to the search
115
116
  # @return [Blacklight::Solr::Response] the solr response object
116
117
  def to_hash
117
- if params_need_update?
118
- @params = processed_parameters.
119
- reverse_merge(@reverse_merged_params).
120
- merge(@merged_params).
121
- tap { self.clear_changes }
122
- else
123
- @params
124
- end
118
+ return @params unless params_need_update?
119
+ @params = processed_parameters.
120
+ reverse_merge(@reverse_merged_params).
121
+ merge(@merged_params).
122
+ tap { self.clear_changes }
125
123
  end
126
124
 
127
125
  alias_method :query, :to_hash
128
126
  alias_method :to_h, :to_hash
129
127
 
130
- # @returns a params hash for searching solr.
131
128
  # The CatalogController #index action uses this.
132
129
  # Solr parameters can come from a number of places. From lowest
133
130
  # precedence to highest:
@@ -142,6 +139,8 @@ module Blacklight
142
139
  # specified otherwise.
143
140
  #
144
141
  # Incoming parameter :f is mapped to :fq solr parameter.
142
+ #
143
+ # @return a params hash for searching solr.
145
144
  def processed_parameters
146
145
  request.tap do |request_parameters|
147
146
  processor_chain.each do |method_name|
@@ -150,80 +149,90 @@ module Blacklight
150
149
  end
151
150
  end
152
151
 
153
- def blacklight_config
154
- scope.blacklight_config
155
- end
152
+ delegate :blacklight_config, to: :scope
156
153
 
157
- def start start = nil
158
- if start
159
- params_will_change!
160
- @start = start.to_i
161
- self
162
- else
163
- @start ||= (page - 1) * (rows || 10)
154
+ def start=(value)
155
+ params_will_change!
156
+ @start = value.to_i
157
+ end
164
158
 
165
- val = @start || 0
166
- val = 0 if @start < 0
167
- val
159
+ # @param [#to_i] value
160
+ def start(value = nil)
161
+ if value
162
+ self.start = value
163
+ return self
168
164
  end
165
+ @start ||= (page - 1) * (rows || 10)
166
+ val = @start || 0
167
+ val = 0 if @start < 0
168
+ val
169
169
  end
170
170
  alias_method :padding, :start
171
171
 
172
- def page page = nil
173
- if page
174
- params_will_change!
175
- @page = page.to_i
176
- @page = 1 if @page < 1
177
- self
178
- else
179
- @page ||= begin
180
- page = if blacklight_params[:page].blank?
181
- 1
182
- else
183
- blacklight_params[:page].to_i
184
- end
185
-
186
- page
187
- end
188
- end
172
+ def page=(value)
173
+ params_will_change!
174
+ @page = value.to_i
175
+ @page = 1 if @page < 1
189
176
  end
190
177
 
191
- def rows rows = nil
192
- if rows
193
- params_will_change!
194
- @rows = rows.to_i
195
- @rows = blacklight_config.max_per_page if @rows > blacklight_config.max_per_page
196
- self
197
- else
198
- @rows ||= begin
199
- rows = blacklight_config.default_per_page
200
-
201
- # user-provided parameters should override any default row
202
- rows = blacklight_params[:rows].to_i unless blacklight_params[:rows].blank?
203
- rows = blacklight_params[:per_page].to_i unless blacklight_params[:per_page].blank?
178
+ # @param [#to_i] value
179
+ def page(value = nil)
180
+ if value
181
+ self.page = value
182
+ return self
183
+ end
184
+ @page ||= blacklight_params[:page].blank? ? 1 : blacklight_params[:page].to_i
185
+ end
204
186
 
205
- # ensure we don't excede the max page size
206
- rows = blacklight_config.max_per_page if rows.to_i > blacklight_config.max_per_page
187
+ def rows=(value)
188
+ params_will_change!
189
+ @rows = [value, blacklight_config.max_per_page].map(&:to_i).min
190
+ end
207
191
 
208
- rows.to_i unless rows.nil?
209
- end
192
+ # @param [#to_i] value
193
+ def rows(value = nil)
194
+ if value
195
+ self.rows = value
196
+ return self
197
+ end
198
+ @rows ||= begin
199
+ # user-provided parameters should override any default row
200
+ r = [:rows, :per_page].map {|k| blacklight_params[k] }.reject(&:blank?).first
201
+ r ||= blacklight_config.default_per_page
202
+ # ensure we don't excede the max page size
203
+ r.nil? ? nil : [r, blacklight_config.max_per_page].map(&:to_i).min
210
204
  end
211
205
  end
212
206
 
213
207
  alias per rows
214
208
 
209
+ # sets the facet that this query pertains to, for the purpose of facet pagination
210
+ def facet=(value)
211
+ params_will_change!
212
+ @facet = value
213
+ end
214
+
215
+ # @param [Object] value
216
+ def facet(value = nil)
217
+ if value
218
+ self.facet = value
219
+ return self
220
+ end
221
+ @facet
222
+ end
223
+
215
224
  def sort
216
225
  sort_field = if blacklight_params[:sort].blank?
217
226
  # no sort param provided, use default
218
227
  blacklight_config.default_sort_field
219
228
  else
220
- # check for sort field key
229
+ # check for sort field key
221
230
  blacklight_config.sort_fields[blacklight_params[:sort]]
222
231
  end
223
232
 
224
233
  field = if sort_field.present?
225
234
  sort_field.sort
226
- else
235
+ else
227
236
  # just pass the key through
228
237
  blacklight_params[:sort]
229
238
  end
@@ -231,23 +240,12 @@ module Blacklight
231
240
  field unless field.blank?
232
241
  end
233
242
 
234
- # sets the facet that this query pertains to, if it is for the purpose of
235
- # facet pagination
236
- def facet(facet = nil)
237
- if facet
238
- params_will_change!
239
- @facet = facet
240
- self
241
- else
242
- @facet
243
- end
244
- end
245
-
246
243
  def search_field
247
244
  blacklight_config.search_fields[blacklight_params[:search_field]]
248
245
  end
249
246
 
250
247
  protected
248
+
251
249
  def request
252
250
  Blacklight::Solr::Request.new
253
251
  end
@@ -256,9 +254,7 @@ module Blacklight
256
254
  field.include_in_request || (field.include_in_request.nil? && blacklight_config.add_field_configuration_to_solr_request)
257
255
  end
258
256
 
259
- def scope
260
- @scope
261
- end
257
+ attr_reader :scope
262
258
 
263
259
  def params_will_change!
264
260
  @dirty = true
@@ -3,10 +3,11 @@ module Blacklight
3
3
  # This class encapsulates the search state as represented by the query
4
4
  # parameters namely: :f, :q, :page, :per_page and, :sort
5
5
  class SearchState
6
- include Blacklight::Facet
7
6
  attr_reader :blacklight_config # Must be called blacklight_config, because Blacklight::Facet calls blacklight_config.
8
7
  attr_reader :params
9
8
 
9
+ delegate :facet_configuration_for_field, to: :blacklight_config
10
+
10
11
  # @param [ActionController::Parameters] params
11
12
  # @param [Blacklight::Config] blacklight_config
12
13
  def initialize(params, blacklight_config)