blacklight 5.19.2 → 6.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -3
- data/.hound.yml +2 -0
- data/.jshintrc +67 -0
- data/.rubocop_hound.yml +4 -0
- data/.travis.yml +11 -8
- data/Gemfile +11 -21
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight/blacklight.js +1 -0
- data/app/assets/javascripts/blacklight/core.js +5 -19
- data/app/assets/javascripts/blacklight/facet_load.js +23 -0
- data/app/assets/stylesheets/blacklight/_balanced_list.scss +18 -0
- data/app/assets/stylesheets/blacklight/_blacklight_base.scss +5 -1
- data/app/assets/stylesheets/blacklight/_bookmark.scss +14 -6
- data/app/assets/stylesheets/blacklight/_constraints.scss +52 -0
- data/app/assets/stylesheets/blacklight/_controls.scss +61 -0
- data/app/assets/stylesheets/blacklight/_facets.scss +31 -4
- data/app/assets/stylesheets/blacklight/_header.scss +17 -3
- data/app/assets/stylesheets/blacklight/_pagination.scss +21 -0
- data/app/assets/stylesheets/blacklight/_search_results.scss +28 -0
- data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +0 -3
- data/app/controllers/concerns/blacklight/bookmarks.rb +1 -1
- data/app/controllers/concerns/blacklight/catalog.rb +3 -45
- data/app/controllers/concerns/blacklight/controller.rb +29 -18
- data/app/controllers/concerns/blacklight/default_component_configuration.rb +4 -3
- data/app/controllers/concerns/blacklight/facet.rb +1 -0
- data/app/controllers/concerns/blacklight/request_builders.rb +4 -107
- data/app/controllers/concerns/blacklight/search_fields.rb +1 -1
- data/app/controllers/concerns/blacklight/search_helper.rb +8 -160
- data/app/controllers/saved_searches_controller.rb +1 -1
- data/app/controllers/search_history_controller.rb +18 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +17 -85
- data/app/helpers/blacklight/catalog_helper_behavior.rb +4 -48
- data/app/helpers/blacklight/component_helper_behavior.rb +9 -2
- data/app/helpers/blacklight/configuration_helper_behavior.rb +3 -43
- data/app/helpers/blacklight/facets_helper_behavior.rb +10 -6
- data/app/helpers/blacklight/layout_helper_behavior.rb +0 -8
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +9 -10
- data/app/helpers/blacklight/render_partials_helper.rb +1 -3
- data/app/helpers/blacklight/url_helper_behavior.rb +15 -187
- data/{lib → app/models}/blacklight/abstract_repository.rb +0 -15
- data/{lib → app/models}/blacklight/configuration.rb +22 -59
- data/app/models/blacklight/configuration/context.rb +47 -0
- data/{lib → app/models}/blacklight/configuration/facet_field.rb +1 -0
- data/{lib → app/models}/blacklight/configuration/field.rb +0 -0
- data/{lib → app/models}/blacklight/configuration/fields.rb +2 -6
- data/{lib → app/models}/blacklight/configuration/search_field.rb +0 -0
- data/{lib → app/models}/blacklight/configuration/solr_field.rb +0 -0
- data/{lib → app/models}/blacklight/configuration/sort_field.rb +0 -0
- data/{lib → app/models}/blacklight/configuration/tool_config.rb +0 -0
- data/app/models/blacklight/configuration/view_config.rb +9 -0
- data/app/models/blacklight/facet_paginator.rb +14 -28
- data/{lib → app/models}/blacklight/search_builder.rb +16 -24
- data/app/models/blacklight/solr/facet_paginator.rb +6 -2
- data/{lib → app/models}/blacklight/solr/repository.rb +0 -21
- data/{lib → app/models}/blacklight/solr/request.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response.rb +9 -8
- data/{lib → app/models}/blacklight/solr/response/facets.rb +37 -29
- data/{lib → app/models}/blacklight/solr/response/group.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/group_response.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/more_like_this.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/pagination_methods.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/response.rb +0 -0
- data/{lib → app/models}/blacklight/solr/response/spelling.rb +2 -1
- data/{lib → app/models}/blacklight/solr/search_builder.rb +0 -0
- data/app/models/concerns/blacklight/document.rb +11 -27
- data/app/models/concerns/blacklight/document/active_model_shim.rb +8 -0
- data/app/models/concerns/blacklight/solr/document.rb +8 -3
- data/{lib → app/models/concerns}/blacklight/solr/search_builder_behavior.rb +21 -33
- data/app/models/concerns/blacklight/user.rb +0 -9
- data/app/models/record_mailer.rb +0 -1
- data/app/presenters/blacklight/document_presenter.rb +23 -13
- data/app/views/blacklight/nav/_saved_searches.html.erb +1 -1
- data/app/views/blacklight/nav/_search_history.html.erb +1 -1
- data/app/views/bookmarks/_tools.html.erb +1 -2
- data/app/views/bookmarks/index.html.erb +2 -2
- data/app/views/catalog/_document_default.atom.builder +4 -2
- data/app/views/catalog/_facet_index_navigation.html.erb +9 -0
- data/app/views/catalog/_facet_layout.html.erb +2 -3
- data/app/views/catalog/_facet_pagination.html.erb +19 -21
- data/app/views/catalog/_facets.html.erb +2 -3
- data/app/views/catalog/_home_text.html.erb +2 -3
- data/app/views/catalog/_index_header_default.html.erb +2 -2
- data/app/views/catalog/_per_page_widget.html.erb +1 -1
- data/app/views/catalog/_search_form.html.erb +21 -18
- data/app/views/catalog/_sort_widget.html.erb +1 -1
- data/app/views/catalog/_zero_results.html.erb +2 -2
- data/app/views/catalog/facet.html.erb +3 -0
- data/app/views/catalog/index.atom.builder +1 -1
- data/app/views/layouts/blacklight.html.erb +2 -2
- data/app/views/saved_searches/index.html.erb +6 -7
- data/app/views/search_history/index.html.erb +5 -5
- data/app/views/shared/_header_navbar.html.erb +2 -2
- data/blacklight.gemspec +5 -5
- data/config/locales/blacklight.de.yml +1 -4
- data/config/locales/blacklight.en.yml +2 -7
- data/config/locales/blacklight.es.yml +1 -4
- data/config/locales/blacklight.fr.yml +1 -4
- data/config/locales/blacklight.it.yml +1 -4
- data/config/locales/blacklight.pt-BR.yml +1 -4
- data/config/routes.rb +9 -0
- data/db/migrate/20140202020201_create_searches.rb +1 -1
- data/db/migrate/20140202020202_create_bookmarks.rb +1 -1
- data/lib/blacklight.rb +5 -82
- data/lib/blacklight/engine.rb +0 -5
- data/lib/blacklight/parameters.rb +13 -0
- data/lib/blacklight/path.rb +143 -0
- data/lib/blacklight/routes.rb +3 -134
- data/lib/blacklight/routes/exportable.rb +25 -0
- data/lib/blacklight/routes/searchable.rb +20 -0
- data/lib/blacklight/solr.rb +1 -9
- data/lib/blacklight/utils.rb +2 -44
- data/lib/generators/blacklight/controller_generator.rb +7 -4
- data/lib/generators/blacklight/install_generator.rb +16 -9
- data/lib/generators/blacklight/models_generator.rb +18 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +85 -91
- data/lib/generators/blacklight/test_support_generator.rb +22 -15
- data/solr/conf/_rest_managed.json +3 -0
- data/solr/conf/admin-extra.html +31 -0
- data/solr/conf/elevate.xml +36 -0
- data/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
- data/solr/conf/protwords.txt +21 -0
- data/solr/conf/schema.xml +621 -0
- data/solr/conf/scripts.conf +24 -0
- data/solr/conf/solrconfig.xml +391 -0
- data/solr/conf/spellings.txt +2 -0
- data/solr/conf/stopwords.txt +58 -0
- data/solr/conf/stopwords_en.txt +58 -0
- data/solr/conf/synonyms.txt +31 -0
- data/solr/conf/xslt/example.xsl +132 -0
- data/solr/conf/xslt/example_atom.xsl +67 -0
- data/solr/conf/xslt/example_rss.xsl +66 -0
- data/solr/conf/xslt/luke.xsl +337 -0
- data/solr/sample_solr_documents.yml +1 -0
- data/spec/controllers/blacklight/base_spec.rb +17 -0
- data/spec/controllers/blacklight/search_helper_spec.rb +25 -297
- data/spec/controllers/catalog_controller_spec.rb +7 -6
- data/spec/controllers/saved_searches_controller_spec.rb +1 -0
- data/spec/controllers/search_history_controller_spec.rb +1 -0
- data/spec/features/alternate_controller_spec.rb +10 -10
- data/spec/features/bookmarks_spec.rb +8 -22
- data/spec/features/facets_spec.rb +27 -7
- data/spec/features/record_view_spec.rb +4 -13
- data/spec/features/search_formats_spec.rb +1 -26
- data/spec/features/sitelinks_search_box.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +8 -38
- data/spec/helpers/catalog_helper_spec.rb +0 -8
- data/spec/helpers/configuration_helper_spec.rb +0 -25
- data/spec/helpers/facets_helper_spec.rb +12 -11
- data/spec/helpers/hash_as_hidden_fields_spec.rb +7 -7
- data/spec/helpers/layout_helper_spec.rb +0 -7
- data/spec/helpers/render_constraints_helper_spec.rb +4 -2
- data/spec/helpers/url_helper_spec.rb +13 -254
- data/spec/lib/blacklight/parameters_spec.rb +22 -0
- data/spec/lib/blacklight/path_spec.rb +254 -0
- data/spec/lib/blacklight_spec.rb +6 -2
- data/spec/models/blacklight/configuration/context_spec.rb +33 -0
- data/spec/models/blacklight/document/active_model_shim_spec.rb +33 -0
- data/spec/models/blacklight/document_spec.rb +29 -1
- data/spec/models/blacklight/facet_paginator_spec.rb +14 -13
- data/spec/models/blacklight/search_builder_spec.rb +17 -23
- data/spec/models/blacklight/solr/facet_paginator_spec.rb +11 -1
- data/spec/models/blacklight/solr/response/facets_spec.rb +19 -25
- data/spec/models/blacklight/solr/response/group_response_spec.rb +5 -5
- data/spec/models/blacklight/solr/response_spec.rb +0 -11
- data/spec/models/blacklight/solr/search_builder_spec.rb +49 -57
- data/spec/presenters/document_presenter_spec.rb +15 -42
- data/spec/routing/catalog_routing_spec.rb +7 -11
- data/spec/spec_helper.rb +4 -42
- data/spec/support/controller_level_helpers.rb +17 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -2
- data/spec/views/_user_util_links.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +40 -0
- data/spec/views/catalog/_facet_layout.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_facets.html.erb_spec.rb +2 -2
- data/spec/views/catalog/_paginate_compact.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_show_tools.html.erb_spec.rb +8 -8
- data/spec/views/catalog/_sort_and_per_page.html.erb_spec.rb +2 -2
- data/tasks/blacklight.rake +25 -30
- metadata +93 -71
- data/app/assets/stylesheets/blacklight/_catalog.scss +0 -229
- data/app/controllers/concerns/blacklight/search_history.rb +0 -31
- data/app/views/catalog/_refworks_form.html.erb +0 -6
- data/lib/blacklight/configuration/view_config.rb +0 -71
- data/lib/blacklight/rails/routes.rb +0 -29
- data/lib/blacklight/solr_helper.rb +0 -9
- data/lib/generators/blacklight/templates/config/initializers/blacklight_initializer.rb +0 -9
- data/spec/helpers/component_helper_spec.rb +0 -19
- data/spec/lib/blacklight/routes_spec.rb +0 -25
- data/spec/lib/blacklight/solr_helper_spec.rb +0 -12
- data/spec/routing/routes_spec.rb +0 -20
- data/spec/views/catalog/_document_action.html.erb_spec.rb +0 -21
@@ -16,21 +16,6 @@ module Blacklight
|
|
16
16
|
@connection ||= build_connection
|
17
17
|
end
|
18
18
|
|
19
|
-
##
|
20
|
-
# Find a single document result by a known id
|
21
|
-
# @param [String] document's unique key value
|
22
|
-
# @param [Hash] additional query parameters
|
23
|
-
def find(id, params = {})
|
24
|
-
fail NotImplementedError
|
25
|
-
end
|
26
|
-
|
27
|
-
##
|
28
|
-
# Execute a search query against a search index
|
29
|
-
# @param [Hash] query parameters
|
30
|
-
def search(params = {})
|
31
|
-
fail NotImplementedError
|
32
|
-
end
|
33
|
-
|
34
19
|
protected
|
35
20
|
def connection_config
|
36
21
|
blacklight_config.connection_config
|
@@ -3,20 +3,19 @@ module Blacklight
|
|
3
3
|
# Blacklight::Configuration holds the configuration for a Blacklight::Controller, including
|
4
4
|
# fields to display, facets to show, sort options, and search fields.
|
5
5
|
class Configuration < OpenStructWithHashAccess
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
extend ActiveSupport::Autoload
|
7
|
+
|
8
|
+
eager_autoload do
|
9
|
+
autoload :ViewConfig
|
10
|
+
autoload :ToolConfig
|
11
|
+
autoload :Fields
|
12
|
+
autoload :Field
|
13
|
+
autoload :SolrField
|
14
|
+
autoload :SearchField
|
15
|
+
autoload :FacetField
|
16
|
+
autoload :SortField
|
17
|
+
end
|
17
18
|
include Fields
|
18
|
-
extend Deprecation
|
19
|
-
self.deprecation_horizon = 'blacklight 6.0'
|
20
19
|
|
21
20
|
# Set up Blacklight::Configuration.default_values to contain
|
22
21
|
# the basic, required Blacklight fields
|
@@ -31,20 +30,10 @@ module Blacklight
|
|
31
30
|
# HTTP method to use when making requests to solr; valid
|
32
31
|
# values are :get and :post.
|
33
32
|
http_method: :get,
|
34
|
-
# The solr request handler ('qt') to use for search requests
|
35
|
-
qt: 'search',
|
36
33
|
# The path to send requests to solr.
|
37
34
|
solr_path: 'select',
|
38
35
|
# Default values of parameters to send with every search request
|
39
36
|
default_solr_params: {},
|
40
|
-
## deprecated; use add_facet_field :include_in_request instead;
|
41
|
-
# if this is configured true, all facets will be included in the solr request
|
42
|
-
# unless explicitly disabled.
|
43
|
-
add_facet_fields_to_solr_request: false,
|
44
|
-
## deprecated; use add_index_field :include_in_request instead;
|
45
|
-
# if this is configured true, all show and index will be included in the solr request
|
46
|
-
# unless explicitly disabled.
|
47
|
-
add_field_configuration_to_solr_request: false,
|
48
37
|
##
|
49
38
|
# === Single document request configuration
|
50
39
|
##
|
@@ -60,7 +49,7 @@ module Blacklight
|
|
60
49
|
#fl: '*',
|
61
50
|
## this is a fancy way to say "find the document by id using
|
62
51
|
## the value in the id query parameter"
|
63
|
-
#q: "{!
|
52
|
+
#q: "{!term f=#{unique_key} v=$id}",
|
64
53
|
## disable features we don't need
|
65
54
|
#facet: false,
|
66
55
|
#rows: 1
|
@@ -140,7 +129,6 @@ module Blacklight
|
|
140
129
|
per_page: [10,20,50,100],
|
141
130
|
default_per_page: nil,
|
142
131
|
# how many searches to save in session history
|
143
|
-
# (TODO: move the value into the configuration?)
|
144
132
|
search_history_window: 100,
|
145
133
|
default_facet_limit: 10
|
146
134
|
}
|
@@ -188,14 +176,11 @@ module Blacklight
|
|
188
176
|
def document_model
|
189
177
|
super || ::SolrDocument
|
190
178
|
end
|
191
|
-
alias_method :solr_document_model, :document_model
|
192
179
|
|
193
180
|
# only here to support alias_method
|
194
181
|
def document_model= *args
|
195
182
|
super
|
196
183
|
end
|
197
|
-
alias_method :solr_document_model=, :document_model=
|
198
|
-
deprecation_deprecate solr_document_model: :document_model, :solr_document_model= => :document_model=
|
199
184
|
|
200
185
|
def document_presenter_class
|
201
186
|
super || Blacklight::DocumentPresenter
|
@@ -204,13 +189,10 @@ module Blacklight
|
|
204
189
|
def response_model
|
205
190
|
super || Blacklight::Solr::Response
|
206
191
|
end
|
207
|
-
|
208
|
-
# only here to support alias_method
|
192
|
+
|
209
193
|
def response_model= *args
|
210
194
|
super
|
211
195
|
end
|
212
|
-
alias_method :solr_response_model=, :response_model=
|
213
|
-
deprecation_deprecate solr_response_model: :response_model, :solr_response_model= => :response_model=
|
214
196
|
|
215
197
|
def repository_class
|
216
198
|
super || Blacklight::Solr::Repository
|
@@ -320,40 +302,21 @@ module Blacklight
|
|
320
302
|
end
|
321
303
|
end
|
322
304
|
|
323
|
-
##
|
324
|
-
# Deprecated. Get the list of facet fields to explicitly
|
325
|
-
# add to the solr request
|
326
|
-
def facet_fields_to_add_to_solr
|
327
|
-
facet_fields.select { |k,v| v.include_in_request }
|
328
|
-
.reject { |k,v| v[:query] || v[:pivot] }
|
329
|
-
.map { |k,v| v.field }
|
330
|
-
end
|
331
|
-
deprecation_deprecate :facet_fields_to_add_to_solr
|
332
|
-
|
333
305
|
##
|
334
306
|
# Provide a 'deep copy' of Blacklight::Configuration that can be modifyed without affecting
|
335
307
|
# the original Blacklight::Configuration instance.
|
336
308
|
#
|
337
|
-
#
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
##
|
345
|
-
# Rails 4.x provides `#deep_dup`, but it aggressively `#dup`'s class names
|
346
|
-
# too. These model names should not be `#dup`'ed or we might break ActiveModel::Naming.
|
347
|
-
def deep_copy
|
348
|
-
deep_dup.tap do |copy|
|
349
|
-
%w(repository_class response_model document_model document_presenter_class search_builder_class facet_paginator_class).each do |klass|
|
350
|
-
# Don't copy if nil, so as not to prematurely autoload default classes
|
351
|
-
copy.send("#{klass}=", send(klass)) unless fetch(klass.to_sym, nil).nil?
|
352
|
-
end
|
309
|
+
# Rails 4.x provides `#deep_dup`, but it aggressively `#dup`'s class names
|
310
|
+
# too. These model names should not be `#dup`'ed or we might break ActiveModel::Naming.
|
311
|
+
def deep_copy
|
312
|
+
deep_dup.tap do |copy|
|
313
|
+
%w(repository_class response_model document_model document_presenter_class search_builder_class facet_paginator_class).each do |klass|
|
314
|
+
# Don't copy if nil, so as not to prematurely autoload default classes
|
315
|
+
copy.send("#{klass}=", send(klass)) unless fetch(klass.to_sym, nil).nil?
|
353
316
|
end
|
354
317
|
end
|
355
|
-
alias_method :inheritable_copy, :deep_copy
|
356
318
|
end
|
319
|
+
alias_method :inheritable_copy, :deep_copy
|
357
320
|
|
358
321
|
##
|
359
322
|
# Get a view configuration for the given view type
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Blacklight
|
2
|
+
class Configuration
|
3
|
+
class Context
|
4
|
+
attr_reader :context
|
5
|
+
|
6
|
+
def initialize(context)
|
7
|
+
@context = context
|
8
|
+
end
|
9
|
+
|
10
|
+
##
|
11
|
+
# Evaluate conditionals for a configuration with if/unless attributes
|
12
|
+
#
|
13
|
+
# @param displayable_config [#if,#unless] an object that responds to if/unless
|
14
|
+
# @return [Boolean]
|
15
|
+
def evaluate_if_unless_configuration(config, *args)
|
16
|
+
return config if config === true or config === false
|
17
|
+
|
18
|
+
if_value = !config.respond_to?(:if) ||
|
19
|
+
config.if.nil? ||
|
20
|
+
evaluate_configuration_conditional(config.if, config, *args)
|
21
|
+
|
22
|
+
unless_value = !config.respond_to?(:unless) ||
|
23
|
+
config.unless.nil? ||
|
24
|
+
!evaluate_configuration_conditional(config.unless, config, *args)
|
25
|
+
|
26
|
+
if_value && unless_value
|
27
|
+
end
|
28
|
+
|
29
|
+
def evaluate_configuration_conditional(proc_helper_or_boolean, *args_for_procs_and_methods)
|
30
|
+
case proc_helper_or_boolean
|
31
|
+
when Symbol
|
32
|
+
arity = context.method(proc_helper_or_boolean).arity
|
33
|
+
|
34
|
+
if arity == 0
|
35
|
+
context.send(proc_helper_or_boolean)
|
36
|
+
else
|
37
|
+
context.send(proc_helper_or_boolean, *args_for_procs_and_methods)
|
38
|
+
end
|
39
|
+
when Proc
|
40
|
+
proc_helper_or_boolean.call context, *args_for_procs_and_methods
|
41
|
+
else
|
42
|
+
proc_helper_or_boolean
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
File without changes
|
@@ -4,8 +4,6 @@ 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"
|
9
7
|
|
10
8
|
module ClassMethods
|
11
9
|
|
@@ -118,14 +116,12 @@ module Blacklight
|
|
118
116
|
|
119
117
|
raise "A #{config_key} with the key #{field_config.key} already exists." if self[config_key.pluralize][field_config.key].present?
|
120
118
|
|
121
|
-
self[config_key.pluralize][ field_config.key ] = field_config
|
119
|
+
self[config_key.pluralize][ field_config.key ] = field_config
|
122
120
|
end
|
123
|
-
alias_method :add_solr_field, :add_blacklight_field
|
124
|
-
deprecation_deprecate add_solr_field: :add_blacklight_field
|
125
121
|
|
126
122
|
protected
|
127
123
|
def luke_fields
|
128
|
-
if @table[:luke_fields]
|
124
|
+
if @table[:luke_fields] === false
|
129
125
|
return nil
|
130
126
|
end
|
131
127
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -9,24 +9,16 @@ module Blacklight
|
|
9
9
|
# so we cannot know how many "pages" there are.
|
10
10
|
#
|
11
11
|
class FacetPaginator
|
12
|
-
extend Deprecation
|
13
|
-
|
14
|
-
self.deprecation_horizon = 'blacklight version 6.0.0'
|
15
|
-
|
16
12
|
# What request keys will we use for the parameters need. Need to
|
17
13
|
# make sure they do NOT conflict with catalog/index request params,
|
18
14
|
# and need to make them accessible in a list so we can easily
|
19
15
|
# strip em out before redirecting to catalog/index.
|
20
16
|
mattr_accessor :request_keys do
|
21
|
-
{ sort: :'facet.sort', page: :'facet.page' }
|
17
|
+
{ sort: :'facet.sort', page: :'facet.page', prefix: :'facet.prefix' }
|
22
18
|
end
|
23
19
|
|
24
|
-
|
25
|
-
self.request_keys = { sort: :'facet.sort', page: :'facet.page' }
|
26
|
-
end
|
20
|
+
attr_reader :offset, :limit, :sort, :prefix
|
27
21
|
|
28
|
-
attr_reader :offset, :limit, :sort
|
29
|
-
|
30
22
|
# all_facet_values is a list of facet value objects returned by solr,
|
31
23
|
# asking solr for n+1 facet values.
|
32
24
|
# options:
|
@@ -34,11 +26,12 @@ module Blacklight
|
|
34
26
|
# display all with no previous or next.
|
35
27
|
# :offset => current item offset, default 0
|
36
28
|
# :sort => 'count' or 'index', solr tokens for facet value sorting, default 'count'.
|
37
|
-
def initialize(all_facet_values, arguments)
|
29
|
+
def initialize(all_facet_values, arguments = {})
|
38
30
|
# to_s.to_i will conveniently default to 0 if nil
|
39
|
-
@offset = arguments[:offset].to_s.to_i
|
31
|
+
@offset = arguments[:offset].to_s.to_i
|
40
32
|
@limit = arguments[:limit]
|
41
33
|
@sort = arguments[:sort]
|
34
|
+
@prefix = arguments[:prefix]
|
42
35
|
|
43
36
|
@all = all_facet_values
|
44
37
|
end
|
@@ -57,8 +50,7 @@ module Blacklight
|
|
57
50
|
end
|
58
51
|
|
59
52
|
def current_page
|
60
|
-
|
61
|
-
if limit.nil? || limit == 0 #check for divide by zero
|
53
|
+
if limit == 0 #check for divide by zero
|
62
54
|
1
|
63
55
|
else
|
64
56
|
@offset / limit + 1
|
@@ -68,18 +60,6 @@ module Blacklight
|
|
68
60
|
def next_page
|
69
61
|
current_page + 1 unless last_page?
|
70
62
|
end
|
71
|
-
|
72
|
-
#@deprecated
|
73
|
-
def has_next?
|
74
|
-
!last_page?
|
75
|
-
end
|
76
|
-
deprecation_deprecate :has_next? => "use #!last_page?"
|
77
|
-
|
78
|
-
#@deprecated
|
79
|
-
def has_previous?
|
80
|
-
!first_page?
|
81
|
-
end
|
82
|
-
deprecation_deprecate :has_next? => "use #!first_page?"
|
83
63
|
|
84
64
|
def last_page?
|
85
65
|
limit.nil? || total_count <= limit
|
@@ -101,10 +81,16 @@ module Blacklight
|
|
101
81
|
# under facet.sort ), and your current request params.
|
102
82
|
# Get back params suitable to passing to an ActionHelper method for
|
103
83
|
# creating a url, to resort by that method.
|
104
|
-
def params_for_resort_url(sort_method, params)
|
84
|
+
def params_for_resort_url(sort_method, params = {})
|
105
85
|
# When resorting, we've got to reset the offset to start at beginning,
|
106
86
|
# no way to make it make sense otherwise.
|
107
|
-
params.merge(request_keys[:sort] => sort_method, request_keys[:page] => nil)
|
87
|
+
resort_params = params.merge(request_keys[:sort] => sort_method, request_keys[:page] => nil)
|
88
|
+
|
89
|
+
if sort_method == 'count'
|
90
|
+
resort_params.except!(request_keys[:prefix])
|
91
|
+
end
|
92
|
+
|
93
|
+
resort_params
|
108
94
|
end
|
109
95
|
|
110
96
|
def as_json(_ = nil)
|
@@ -1,27 +1,29 @@
|
|
1
1
|
module Blacklight
|
2
|
-
##
|
3
|
-
# Blacklight's SearchBuilder converts blacklight request parameters into
|
4
|
-
# query parameters appropriate for search index. It does so by evaluating a
|
5
|
-
# chain of processing methods to populate a result hash (see {#to_hash}).
|
6
2
|
class SearchBuilder
|
7
3
|
extend Deprecation
|
8
|
-
self.deprecation_horizon = "blacklight 6.0"
|
9
|
-
|
10
4
|
class_attribute :default_processor_chain
|
11
5
|
self.default_processor_chain = []
|
12
6
|
|
13
7
|
attr_reader :processor_chain, :blacklight_params
|
14
8
|
|
15
|
-
# @param [List<Symbol>,TrueClass]
|
9
|
+
# @param [List<Symbol>,TrueClass] options a list of filter methods to run or true, to use the default methods
|
16
10
|
# @param [Object] scope the scope where the filter methods reside in.
|
17
|
-
def initialize(
|
18
|
-
@
|
19
|
-
|
11
|
+
def initialize(*options)
|
12
|
+
@scope = case options.size
|
13
|
+
when 1
|
14
|
+
options.first
|
15
|
+
when 2
|
16
|
+
if options.first === true
|
17
|
+
Deprecation.warn Blacklight::SearchBuilder, "SearchBuilder#initialize now takes only one parameter, the scope. Passing `true' will be removed in Blacklight 7"
|
18
|
+
else
|
19
|
+
@processor_chain = options.first
|
20
|
+
end
|
21
|
+
options.last
|
20
22
|
else
|
21
|
-
|
23
|
+
raise ArgumentError, "wrong number of arguments. (#{options.size} for 1..2)"
|
22
24
|
end
|
23
25
|
|
24
|
-
@
|
26
|
+
@processor_chain ||= default_processor_chain.dup
|
25
27
|
@blacklight_params = {}
|
26
28
|
@merged_params = {}
|
27
29
|
@reverse_merged_params = {}
|
@@ -106,12 +108,7 @@ module Blacklight
|
|
106
108
|
# a solr query method
|
107
109
|
# @param [Hash,HashWithIndifferentAccess] extra_controller_params (nil) extra parameters to add to the search
|
108
110
|
# @return [Blacklight::Solr::Response] the solr response object
|
109
|
-
def to_hash
|
110
|
-
unless method_extra_params.nil?
|
111
|
-
Deprecation.warn(Blacklight::SearchBuilder, "Calling SearchBuilder#query with extra parameters is deprecated. Use #merge(Hash) instead")
|
112
|
-
merge(method_extra_params)
|
113
|
-
end
|
114
|
-
|
111
|
+
def to_hash
|
115
112
|
if params_need_update?
|
116
113
|
@params = processed_parameters.
|
117
114
|
reverse_merge(@reverse_merged_params).
|
@@ -143,12 +140,7 @@ module Blacklight
|
|
143
140
|
def processed_parameters
|
144
141
|
request.tap do |request_parameters|
|
145
142
|
processor_chain.each do |method_name|
|
146
|
-
|
147
|
-
Deprecation.warn Blacklight::SearchBuilder, "Building search parameters by calling #{method_name} on #{scope.class}. This behavior will be deprecated in Blacklight 6.0. Instead, define #{method_name} on a subclass of #{self.class} and set search_builder_class in the configuration"
|
148
|
-
scope.send(method_name, request_parameters, blacklight_params)
|
149
|
-
else
|
150
|
-
send(method_name, request_parameters)
|
151
|
-
end
|
143
|
+
send(method_name, request_parameters)
|
152
144
|
end
|
153
145
|
end
|
154
146
|
end
|
@@ -17,11 +17,15 @@ module Blacklight::Solr
|
|
17
17
|
# display all with no previous or next.
|
18
18
|
# :offset => current item offset, default 0
|
19
19
|
# :sort => 'count' or 'index', solr tokens for facet value sorting, default 'count'.
|
20
|
-
def initialize(all_facet_values, arguments)
|
20
|
+
def initialize(all_facet_values, arguments = {})
|
21
21
|
super
|
22
22
|
|
23
23
|
# count is solr's default
|
24
|
-
@sort ||=
|
24
|
+
@sort ||= if @limit.to_i > 0
|
25
|
+
'count'
|
26
|
+
else
|
27
|
+
'index'
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|