blacklight 7.11.1 → 7.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.solr_wrapper.yml +5 -0
- data/VERSION +1 -1
- data/app/builders/blacklight/action_builder.rb +6 -0
- data/app/components/blacklight/constraint_component.html.erb +5 -0
- data/app/components/blacklight/constraint_component.rb +13 -0
- data/app/components/blacklight/constraint_layout_component.rb +2 -1
- data/app/components/blacklight/constraints_component.html.erb +10 -0
- data/app/components/blacklight/constraints_component.rb +65 -0
- data/app/components/blacklight/document/action_component.html.erb +9 -0
- data/app/components/blacklight/document/action_component.rb +38 -0
- data/app/components/blacklight/document/actions_component.html.erb +13 -0
- data/app/components/blacklight/document/actions_component.rb +26 -0
- data/app/components/blacklight/document/bookmark_component.html.erb +1 -1
- data/app/components/blacklight/document/bookmark_component.rb +8 -0
- data/app/components/blacklight/document/citation_component.html.erb +4 -2
- data/app/components/blacklight/document/citation_component.rb +8 -1
- data/app/components/blacklight/document/group_component.html.erb +9 -0
- data/app/components/blacklight/document/group_component.rb +26 -0
- data/app/components/blacklight/document/more_like_this_component.rb +2 -0
- data/app/components/blacklight/document/thumbnail_component.html.erb +12 -0
- data/app/components/blacklight/document/thumbnail_component.rb +25 -0
- data/app/components/blacklight/document_component.rb +27 -26
- data/app/components/blacklight/facet_field_filter_component.html.erb +12 -0
- data/app/components/blacklight/facet_field_filter_component.rb +25 -0
- data/app/components/blacklight/facet_field_pagination_component.html.erb +19 -0
- data/app/components/blacklight/facet_field_pagination_component.rb +21 -0
- data/app/components/blacklight/facet_item_component.rb +4 -8
- data/app/components/blacklight/response/facet_group_component.html.erb +3 -1
- data/app/components/blacklight/response/facet_group_component.rb +8 -1
- data/app/components/blacklight/response/pagination_component.rb +3 -0
- data/app/components/blacklight/response/sort_component.html.erb +1 -1
- data/app/components/blacklight/response/spellcheck_component.rb +9 -2
- data/app/components/blacklight/response/view_type_component.html.erb +11 -0
- data/app/components/blacklight/response/view_type_component.rb +36 -0
- data/app/components/blacklight/search_bar_component.html.erb +1 -1
- data/app/components/blacklight/search_bar_component.rb +6 -0
- data/app/components/blacklight/search_context_component.rb +6 -2
- data/app/components/blacklight/system/dropdown_component.html.erb +1 -1
- data/app/components/blacklight/system/flash_message_component.html.erb +4 -0
- data/app/components/blacklight/system/flash_message_component.rb +24 -0
- data/app/controllers/concerns/blacklight/catalog.rb +7 -1
- data/app/controllers/concerns/blacklight/controller.rb +12 -3
- data/app/controllers/concerns/blacklight/facet.rb +19 -5
- data/app/controllers/concerns/blacklight/search_fields.rb +7 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +127 -17
- data/app/helpers/blacklight/catalog_helper_behavior.rb +36 -5
- data/app/helpers/blacklight/component_helper_behavior.rb +36 -6
- data/app/helpers/blacklight/configuration_helper_behavior.rb +32 -4
- data/app/helpers/blacklight/facets_helper_behavior.rb +31 -8
- data/app/helpers/blacklight/hash_as_hidden_fields_helper_behavior.rb +5 -0
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +28 -11
- data/app/helpers/blacklight/render_partials_helper_behavior.rb +8 -3
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +4 -2
- data/app/helpers/blacklight/suggest_helper_behavior.rb +1 -0
- data/app/helpers/blacklight/url_helper_behavior.rb +23 -3
- data/app/models/blacklight/icon.rb +0 -1
- data/app/models/concerns/blacklight/document.rb +1 -1
- data/app/models/concerns/blacklight/suggest/response.rb +1 -1
- data/app/models/record_mailer.rb +1 -1
- data/app/presenters/blacklight/document_presenter.rb +42 -1
- data/app/presenters/blacklight/facet_field_presenter.rb +3 -1
- data/app/presenters/blacklight/facet_item_presenter.rb +8 -0
- data/app/presenters/blacklight/field_presenter.rb +9 -6
- data/app/presenters/blacklight/json_presenter.rb +3 -1
- data/app/presenters/blacklight/show_presenter.rb +4 -30
- data/app/presenters/blacklight/thumbnail_presenter.rb +5 -1
- data/app/services/blacklight/document_factory.rb +3 -0
- data/app/services/blacklight/field_retriever.rb +18 -4
- data/app/services/blacklight/search_service.rb +0 -1
- data/app/views/bookmarks/_tools.html.erb +12 -7
- data/app/views/catalog/_bookmark_control.html.erb +1 -1
- data/app/views/catalog/_constraints.html.erb +12 -7
- data/app/views/catalog/_document.atom.builder +9 -6
- data/app/views/catalog/_document.rss.builder +4 -2
- data/app/views/catalog/_facet_index_navigation.html.erb +1 -10
- data/app/views/catalog/_facet_pagination.html.erb +1 -19
- data/app/views/catalog/_facets.html.erb +1 -1
- data/app/views/catalog/_group.html.erb +1 -9
- data/app/views/catalog/_index.html.erb +1 -1
- data/app/views/catalog/_search_results.html.erb +1 -1
- data/app/views/catalog/_show.html.erb +1 -1
- data/app/views/catalog/_show_header.html.erb +1 -1
- data/app/views/catalog/_show_main_content.html.erb +2 -2
- data/app/views/catalog/_show_tools.html.erb +12 -8
- data/app/views/catalog/_start_over.html.erb +1 -1
- data/app/views/catalog/_thumbnail.html.erb +1 -5
- data/app/views/catalog/_view_type_group.html.erb +5 -13
- data/app/views/catalog/index.json.jbuilder +8 -6
- data/app/views/catalog/show.json.jbuilder +1 -1
- data/app/views/shared/_flash_msg.html.erb +1 -15
- data/blacklight.gemspec +1 -0
- data/config/locales/blacklight.ca.yml +241 -0
- data/lib/blacklight/abstract_repository.rb +13 -4
- data/lib/blacklight/configuration.rb +11 -5
- data/lib/blacklight/configuration/display_field.rb +50 -0
- data/lib/blacklight/configuration/facet_field.rb +58 -1
- data/lib/blacklight/configuration/field.rb +13 -0
- data/lib/blacklight/configuration/index_field.rb +5 -0
- data/lib/blacklight/configuration/search_field.rb +3 -0
- data/lib/blacklight/configuration/show_field.rb +5 -0
- data/lib/blacklight/configuration/sort_field.rb +3 -0
- data/lib/blacklight/configuration/tool_config.rb +1 -0
- data/lib/blacklight/configuration/view_config.rb +25 -0
- data/lib/blacklight/search_state.rb +4 -2
- data/lib/blacklight/solr/repository.rb +1 -1
- data/lib/generators/blacklight/templates/catalog_controller.rb +8 -7
- data/spec/components/blacklight/document/action_component_spec.rb +43 -0
- data/spec/components/blacklight/document/group_component_spec.rb +45 -0
- data/spec/components/blacklight/document_component_spec.rb +8 -0
- data/spec/components/blacklight/facet_item_pivot_component_spec.rb +0 -1
- data/spec/components/blacklight/system/flash_message_component_spec.rb +54 -0
- data/spec/controllers/blacklight/search_fields_spec.rb +2 -0
- data/spec/controllers/catalog_controller_spec.rb +2 -0
- data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +6 -1
- data/spec/helpers/blacklight/hash_as_hidden_fields_behavior_spec.rb +2 -0
- data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +2 -0
- data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +3 -1
- data/spec/helpers/blacklight/url_helper_behavior_spec.rb +2 -0
- data/spec/helpers/blacklight_helper_spec.rb +10 -0
- data/spec/helpers/catalog_helper_spec.rb +4 -4
- data/spec/lib/blacklight/configuration/facet_field_spec.rb +17 -0
- data/spec/models/blacklight/search_builder_spec.rb +1 -1
- data/spec/models/blacklight/solr/search_builder_spec.rb +8 -0
- data/spec/presenters/blacklight/field_presenter_spec.rb +30 -5
- data/spec/services/blacklight/search_service_spec.rb +1 -5
- data/spec/views/catalog/_constraints.html.erb_spec.rb +2 -1
- data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +4 -2
- data/spec/views/catalog/_show_tools.html.erb_spec.rb +8 -8
- data/spec/views/catalog/show.json.jbuilder_spec.rb +1 -0
- data/tasks/blacklight.rake +27 -12
- metadata +47 -2
@@ -1,33 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Blacklight
|
3
|
+
# Base class for Blacklight repository adapters
|
3
4
|
class AbstractRepository
|
5
|
+
# @return [Blacklight::Configuration]
|
4
6
|
attr_accessor :blacklight_config
|
7
|
+
|
8
|
+
# Direct writer for the connection
|
5
9
|
attr_writer :connection
|
6
10
|
|
7
|
-
# ActiveSupport::Benchmarkable requires a logger method
|
11
|
+
# (Note: ActiveSupport::Benchmarkable requires a logger method)
|
12
|
+
# @return [Logger]
|
8
13
|
attr_writer :logger
|
9
14
|
|
10
15
|
include ActiveSupport::Benchmarkable
|
11
16
|
|
17
|
+
##
|
18
|
+
# @param [Blacklight::Configuration] blacklight_config
|
12
19
|
def initialize blacklight_config
|
13
20
|
@blacklight_config = blacklight_config
|
14
21
|
end
|
15
22
|
|
23
|
+
##
|
24
|
+
# The raw data store connection
|
16
25
|
def connection
|
17
26
|
@connection ||= build_connection
|
18
27
|
end
|
19
28
|
|
20
29
|
##
|
21
30
|
# Find a single document result by a known id
|
22
|
-
# @param [String]
|
23
|
-
# @param [Hash]
|
31
|
+
# @param [String] _id document's unique key value
|
32
|
+
# @param [Hash] _params additional query parameters
|
24
33
|
def find(_id, _params = {})
|
25
34
|
raise NotImplementedError
|
26
35
|
end
|
27
36
|
|
28
37
|
##
|
29
38
|
# Execute a search query against a search index
|
30
|
-
# @param [Hash]
|
39
|
+
# @param [Hash] _params query parameters
|
31
40
|
def search(_params = {})
|
32
41
|
raise NotImplementedError
|
33
42
|
end
|
@@ -71,7 +71,7 @@ module Blacklight
|
|
71
71
|
# solr field to use to render a document title
|
72
72
|
title_field: nil,
|
73
73
|
# solr field to use to render format-specific partials
|
74
|
-
display_type_field:
|
74
|
+
display_type_field: nil,
|
75
75
|
# partials to render for each document(see #render_document_partials)
|
76
76
|
partials: [:index_header, :thumbnail, :index],
|
77
77
|
document_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
|
@@ -86,7 +86,7 @@ module Blacklight
|
|
86
86
|
# document presenter class used by helpers and views
|
87
87
|
document_presenter_class: nil,
|
88
88
|
document_component: nil,
|
89
|
-
display_type_field:
|
89
|
+
display_type_field: nil,
|
90
90
|
# Default route parameters for 'show' requests.
|
91
91
|
# Set this to a hash with additional arguments to merge into the route,
|
92
92
|
# or set `controller: :current` to route to the current controller.
|
@@ -256,6 +256,11 @@ module Blacklight
|
|
256
256
|
facet_fields.select { |_facet, opts| group == opts[:group] }.values.map(&:field)
|
257
257
|
end
|
258
258
|
|
259
|
+
# @return [Array<String>] a list of facet groups
|
260
|
+
def facet_group_names
|
261
|
+
facet_fields.map { |_facet, opts| opts[:group] }.uniq
|
262
|
+
end
|
263
|
+
|
259
264
|
# Add any configured facet fields to the default solr parameters hash
|
260
265
|
# @overload add_facet_fields_to_solr_request!
|
261
266
|
# add all facet fields to the solr request
|
@@ -360,7 +365,7 @@ module Blacklight
|
|
360
365
|
def index_fields_for(document_or_display_types)
|
361
366
|
display_types = if document_or_display_types.is_a? Blacklight::Document
|
362
367
|
Deprecation.warn self, "Calling index_fields_for with a #{document_or_display_types.class} is deprecated and will be removed in Blacklight 8. Pass the display type instead."
|
363
|
-
document_or_display_types[index.display_type_field]
|
368
|
+
document_or_display_types[index.display_type_field || 'format']
|
364
369
|
else
|
365
370
|
document_or_display_types
|
366
371
|
end
|
@@ -380,7 +385,7 @@ module Blacklight
|
|
380
385
|
def show_fields_for(document_or_display_types)
|
381
386
|
display_types = if document_or_display_types.is_a? Blacklight::Document
|
382
387
|
Deprecation.warn self, "Calling show_fields_for with a #{document_or_display_types.class} is deprecated and will be removed in Blacklight 8. Pass the display type instead."
|
383
|
-
document_or_display_types[show.display_type_field]
|
388
|
+
document_or_display_types[show.display_type_field || 'format']
|
384
389
|
else
|
385
390
|
document_or_display_types
|
386
391
|
end
|
@@ -398,7 +403,8 @@ module Blacklight
|
|
398
403
|
|
399
404
|
def add_action(config_hash, name, opts)
|
400
405
|
config = Blacklight::Configuration::ToolConfig.new opts
|
401
|
-
config.name
|
406
|
+
config.name ||= name
|
407
|
+
config.key = name
|
402
408
|
yield(config) if block_given?
|
403
409
|
config_hash[name] = config
|
404
410
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Blacklight
|
3
|
+
class Configuration::DisplayField < Blacklight::Configuration::Field
|
4
|
+
##
|
5
|
+
# The following is a non-exhaustive list of display field config parameters that are used
|
6
|
+
# by Blacklight directly. Application-specific code or plugins may add or replace
|
7
|
+
# the parameters and behaviors specified below.
|
8
|
+
#
|
9
|
+
|
10
|
+
##
|
11
|
+
# Data parameters:
|
12
|
+
# @!attribute values
|
13
|
+
# @return [Proc]
|
14
|
+
# @!attribute accessor
|
15
|
+
# @return [Boolean,Symbol]
|
16
|
+
# @!attribute highlight
|
17
|
+
# @return [Boolean]
|
18
|
+
# @!attribute default
|
19
|
+
# @return [Object]
|
20
|
+
# @!attribute solr_params
|
21
|
+
# @return [Hash]
|
22
|
+
# @!attribute include_in_request
|
23
|
+
# @return [Boolean]
|
24
|
+
|
25
|
+
##
|
26
|
+
# Rendering:
|
27
|
+
# @!attribute presenter
|
28
|
+
# @return [Blacklight::FieldPresenter]
|
29
|
+
# @!attribute component
|
30
|
+
# @return [Blacklight::MetadataFieldComponent]
|
31
|
+
|
32
|
+
##
|
33
|
+
# Default rendering pipeline:
|
34
|
+
# @!attribute link_to_facet
|
35
|
+
# @return [Boolean]
|
36
|
+
# @!attribute link_to_search
|
37
|
+
# @deprecated use link_to_facet instead.
|
38
|
+
# @return [Boolean]
|
39
|
+
# @!attribute itemprop
|
40
|
+
# @return [String]
|
41
|
+
# @!attribute separator_options
|
42
|
+
# @return [Hash]
|
43
|
+
|
44
|
+
# @param [Blacklight::Configuration] _blacklight_config
|
45
|
+
def normalize! _blacklight_config = nil
|
46
|
+
super
|
47
|
+
self.presenter ||= Blacklight::FieldPresenter
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,6 +1,63 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Blacklight
|
3
3
|
class Configuration::FacetField < Blacklight::Configuration::Field
|
4
|
+
##
|
5
|
+
# The following is a non-exhaustive list of facet config parameters that are used
|
6
|
+
# by Blacklight directly. Application-specific code or plugins may add or replace
|
7
|
+
# the parameters and behaviors specified below.
|
8
|
+
#
|
9
|
+
|
10
|
+
##
|
11
|
+
# Display parameters:
|
12
|
+
# @!attribute collapse
|
13
|
+
# @return [Boolean] whether to display the facet in a collapsed state by default
|
14
|
+
# @!attribute show
|
15
|
+
# @return [Boolean] whether to show the facet to the user or not (very similar to the more generic if/unless)
|
16
|
+
# @!attribute index_range
|
17
|
+
# @return [Enumerable] a list of facet prefixes (default: A-Z) to allow users to 'jump' to particular values
|
18
|
+
# @!attribute date
|
19
|
+
# @return [Symbol|Hash] the i18n localization option for a date or time value; used as the second parameter for the I18n.l method
|
20
|
+
# @!attribute link_to_facet
|
21
|
+
# @return [Boolean]
|
22
|
+
# @!attribute link_to_search
|
23
|
+
# @deprecated use link_to_facet instead.
|
24
|
+
# @return [Boolean]
|
25
|
+
# @!attribute helper_method
|
26
|
+
# @return [Symbol] the name of a helper method used to display the facet's value to the user; it receives the facet value.
|
27
|
+
# @!attribute url_method
|
28
|
+
# @return [Symbol] The name of a helper to use for getting the url for a facet link; the method will receive the facet field's key and value.
|
29
|
+
# @!attribute collapsing
|
30
|
+
# @return [Boolean] display pivot facets with an expand / collapse toggle
|
31
|
+
# @!attribute icons
|
32
|
+
# @return [Hash] Icons to use for pivot facet expand + collapse
|
33
|
+
|
34
|
+
##
|
35
|
+
# Query parameters:
|
36
|
+
# @!attribute sort
|
37
|
+
# @return [String] the ordering of the facet field constraints; when using Solr, this is either 'count' or 'index'
|
38
|
+
# @!attribute single
|
39
|
+
# @return [Boolean] whether the facet values are mutually exclusive; or, for more granular control, see tag + ex
|
40
|
+
# @!attribute tag
|
41
|
+
# @return [String] See https://lucene.apache.org/solr/guide/8_6/faceting.html#tagging-and-excluding-filters
|
42
|
+
# @!attribute ex
|
43
|
+
# @return [String] See https://lucene.apache.org/solr/guide/8_6/faceting.html#tagging-and-excluding-filters
|
44
|
+
# @!attribute query
|
45
|
+
# @return [Hash{String => Hash}] Provides support for facet queries; the keys are mapped to user-facing parameters, and the values
|
46
|
+
# are a hash containing: label (a label to show the user in the facet interface), fq (a string passed into solr as an fq (when selected) or a facet.query)
|
47
|
+
# @!attribute pivot
|
48
|
+
# @return []
|
49
|
+
|
50
|
+
##
|
51
|
+
# Rendering:
|
52
|
+
# @!attribute presenter
|
53
|
+
# @return [Blacklight::FacetFieldPresenter]
|
54
|
+
# @!attribute component
|
55
|
+
# @return [Blacklight::FacetFieldListComponent]
|
56
|
+
# @!attribute item_component
|
57
|
+
# @return [Blacklight::FacetItemComponent]
|
58
|
+
# @!attribute partial
|
59
|
+
# @return [String] Rails view partial used to render the facet field
|
60
|
+
|
4
61
|
extend Deprecation
|
5
62
|
|
6
63
|
def normalize! blacklight_config = nil
|
@@ -10,7 +67,7 @@ module Blacklight
|
|
10
67
|
self.show = true if show.nil?
|
11
68
|
self.if = show if self.if.nil?
|
12
69
|
self.index_range = 'A'..'Z' if index_range == true
|
13
|
-
self.presenter
|
70
|
+
self.presenter ||= Blacklight::FacetFieldPresenter
|
14
71
|
|
15
72
|
if link_to_search
|
16
73
|
Deprecation.warn(Blacklight::Configuration::FacetField, '`link_to_search:` is deprecated, use `link_to_facet:` instead')
|
@@ -1,6 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Blacklight
|
3
3
|
class Configuration::Field < OpenStructWithHashAccess
|
4
|
+
# @!attribute field
|
5
|
+
# @return [String] the field name in the search response data from Solr
|
6
|
+
# @!attribute key
|
7
|
+
# @return [String] the field name as used in the application + user-facing HTML
|
8
|
+
# @!attribute label
|
9
|
+
# @return [String, Symbol] the label or i18n key to use for labeling data from this field
|
10
|
+
# @!attribute if
|
11
|
+
# @return [Proc, Symbol] a proc or the symbol name of a helper to test whether the field should be rendered.
|
12
|
+
# The helper or proc will receive this field configuration object as the first parameter. See Blacklight::Configuration::Context.
|
13
|
+
# @!attribute unless
|
14
|
+
# @return [Proc, Symbol] a proc or the symbol name of a helper to test whether the field should not be rendered.
|
15
|
+
# The helper or proc will receive this field configuration object as the first parameter. See Blacklight::Configuration::Context.
|
16
|
+
|
4
17
|
def normalize! _blacklight_config = nil
|
5
18
|
self.field ||= key
|
6
19
|
self.key ||= self.field
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Blacklight
|
3
3
|
class Configuration::SearchField < Blacklight::Configuration::Field
|
4
|
+
# @!attribute include_in_simple_select
|
5
|
+
# @!attribute qt
|
6
|
+
|
4
7
|
def normalize! blacklight_config = nil
|
5
8
|
self.if = include_in_simple_select if self.if.nil?
|
6
9
|
|
@@ -1,6 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Blacklight
|
3
3
|
class Configuration::SortField < Blacklight::Configuration::Field
|
4
|
+
# @!attribute sort
|
5
|
+
# @return [String] the sort specification to use; defaults to the value of field (which is used in the user-facing parameters)
|
6
|
+
|
4
7
|
def normalize! blacklight_config = nil
|
5
8
|
super
|
6
9
|
self.field ||= label.try(:parameterize)
|
@@ -1,17 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
class Blacklight::Configuration
|
3
3
|
class ViewConfig < Blacklight::OpenStructWithHashAccess
|
4
|
+
# @!attribute partials
|
5
|
+
# @return [Array<String>] partials to render for each document(see #render_document_partials)
|
6
|
+
# @!attribute document_presenter_class
|
7
|
+
# @return [Class] document presenter class used by helpers and views
|
8
|
+
# @!attribute document_component
|
9
|
+
# @return [Class] component class used to render a document; defaults to Blacklight::DocumentComponent
|
10
|
+
# @!attribute title_field
|
11
|
+
# @return [String, Symbol] solr field to use to render a document title
|
12
|
+
# @!attribute display_type_field
|
13
|
+
# @return [String, Symbol] solr field to use to render format-specific partials
|
14
|
+
# @!attribute document_actions
|
15
|
+
# @return [NestedOpenStructWithHashAccess{Symbol => Blacklight::Configuration::ToolConfig}] 'tools' to render for each document
|
4
16
|
def search_bar_presenter_class
|
5
17
|
super || Blacklight::SearchBarPresenter
|
6
18
|
end
|
7
19
|
|
8
20
|
class Show < ViewConfig
|
21
|
+
# @!attribute route
|
22
|
+
# @return [Hash] Default route parameters for 'show' requests.
|
23
|
+
# Set this to a hash with additional arguments to merge into the route,
|
24
|
+
# or set `controller: :current` to route to the current controller.
|
25
|
+
|
9
26
|
def document_presenter_class
|
10
27
|
super || Blacklight::ShowPresenter
|
11
28
|
end
|
12
29
|
end
|
13
30
|
|
14
31
|
class Index < ViewConfig
|
32
|
+
# @!attribute group
|
33
|
+
# @return [false, String, Symbol] what field, if any, to use to render grouped results
|
34
|
+
# @!attribute respond_to
|
35
|
+
# @return [OpenStructWithHashAccess{Symbol => OpenStruct}] additional response formats for search results;
|
36
|
+
# see Blacklight::Catalog#additional_response_formats for information about the OpenStruct data
|
37
|
+
# @!attribute collection_actions
|
38
|
+
# @return [String, Symbol]
|
39
|
+
|
15
40
|
def document_presenter_class
|
16
41
|
super || Blacklight::IndexPresenter
|
17
42
|
end
|
@@ -3,6 +3,8 @@ 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
|
+
extend Deprecation
|
7
|
+
|
6
8
|
attr_reader :blacklight_config # Must be called blacklight_config, because Blacklight::Facet calls blacklight_config.
|
7
9
|
attr_reader :params
|
8
10
|
|
@@ -52,13 +54,13 @@ module Blacklight
|
|
52
54
|
alias to_h to_hash
|
53
55
|
|
54
56
|
def to_unsafe_h
|
55
|
-
Deprecation.warn(self, 'Use SearchState#to_h instead of SearchState#to_unsafe_h')
|
57
|
+
Deprecation.warn(self.class, 'Use SearchState#to_h instead of SearchState#to_unsafe_h')
|
56
58
|
to_hash
|
57
59
|
end
|
58
60
|
|
59
61
|
def method_missing(method_name, *arguments, &block)
|
60
62
|
if @params.respond_to?(method_name)
|
61
|
-
Deprecation.warn(self, "Calling `#{method_name}` on Blacklight::SearchState " \
|
63
|
+
Deprecation.warn(self.class, "Calling `#{method_name}` on Blacklight::SearchState " \
|
62
64
|
'is deprecated and will be removed in Blacklight 8. Call #to_h first if you ' \
|
63
65
|
' need to use hash methods (or, preferably, use your own SearchState implementation)')
|
64
66
|
@params.public_send(method_name, *arguments, &block)
|
@@ -23,7 +23,7 @@ module Blacklight::Solr
|
|
23
23
|
send_and_receive blacklight_config.solr_path, params.reverse_merge(qt: blacklight_config.qt)
|
24
24
|
end
|
25
25
|
|
26
|
-
# @param [Hash]
|
26
|
+
# @param [Hash] request_params
|
27
27
|
# @return [Blacklight::Suggest::Response]
|
28
28
|
def suggestions(request_params)
|
29
29
|
suggest_results = connection.send_and_receive(suggest_handler_path, params: request_params)
|
@@ -182,22 +182,23 @@ class <%= controller_name.classify %>Controller < ApplicationController
|
|
182
182
|
end
|
183
183
|
|
184
184
|
# "sort results by" select (pulldown)
|
185
|
-
# label in pulldown is followed by the name of the
|
185
|
+
# label in pulldown is followed by the name of the Solr field to sort by and
|
186
186
|
# whether the sort is ascending or descending (it must be asc or desc
|
187
|
-
# except in the relevancy case).
|
188
|
-
|
189
|
-
config.add_sort_field 'pub_date_si desc, title_si asc', label: '
|
190
|
-
config.add_sort_field '
|
187
|
+
# except in the relevancy case). Add the sort: option to configure a
|
188
|
+
# custom Blacklight url parameter value separate from the Solr sort fields.
|
189
|
+
config.add_sort_field 'relevance', sort: 'score desc, pub_date_si desc, title_si asc', label: 'relevance'
|
190
|
+
config.add_sort_field 'year-desc', sort: 'pub_date_si desc, title_si asc', label: 'year'
|
191
|
+
config.add_sort_field 'author', sort: 'author_si asc, title_si asc', label: 'author'
|
191
192
|
config.add_sort_field 'title_si asc, pub_date_si desc', label: 'title'
|
192
193
|
|
193
194
|
# If there are more than this many search results, no spelling ("did you
|
194
195
|
# mean") suggestion is offered.
|
195
196
|
config.spell_max = 5
|
196
197
|
|
197
|
-
# Configuration for autocomplete
|
198
|
+
# Configuration for autocomplete suggester
|
198
199
|
config.autocomplete_enabled = true
|
199
200
|
config.autocomplete_path = 'suggest'
|
200
|
-
# if the name of the solr.SuggestComponent provided in your
|
201
|
+
# if the name of the solr.SuggestComponent provided in your solrconfig.xml is not the
|
201
202
|
# default 'mySuggester', uncomment and provide it below
|
202
203
|
# config.autocomplete_suggester = 'mySuggester'
|
203
204
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Blacklight::Document::ActionComponent, type: :component do
|
6
|
+
subject(:component) { described_class.new(document: document, action: action, **attr) }
|
7
|
+
|
8
|
+
let(:action) { Blacklight::Configuration::ToolConfig.new(key: 'some_tool', name: 'some_tool', component: true) }
|
9
|
+
let(:attr) { {} }
|
10
|
+
let(:view_context) { controller.view_context }
|
11
|
+
let(:render) do
|
12
|
+
component.render_in(view_context)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:rendered) do
|
16
|
+
Capybara::Node::Simple.new(render)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:document) do
|
20
|
+
SolrDocument.new(
|
21
|
+
id: 'x'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'renders an action link' do
|
26
|
+
if Rails.version >= '6'
|
27
|
+
allow(view_context).to receive(:some_tool_solr_document_path).with(document, only_path: true).and_return('/asdf')
|
28
|
+
else
|
29
|
+
allow(view_context).to receive(:some_tool_solr_document_path).with(document).and_return('/asdf')
|
30
|
+
end
|
31
|
+
expect(rendered).to have_link 'Some tool', href: '/asdf'
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'with a partial configured' do
|
35
|
+
let(:action) { Blacklight::Configuration::ToolConfig.new(name: '', partial: '/some/tool') }
|
36
|
+
|
37
|
+
it 'render the partial' do
|
38
|
+
allow(view_context).to receive(:render).with(hash_including(partial: '/some/tool')).and_return('tool')
|
39
|
+
|
40
|
+
expect(rendered).to have_content 'tool'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Blacklight::Document::GroupComponent, type: :component do
|
6
|
+
subject(:component) { described_class.new(group: group, **attr) }
|
7
|
+
|
8
|
+
let(:attr) { {} }
|
9
|
+
let(:view_context) { controller.view_context }
|
10
|
+
let(:render) do
|
11
|
+
component.render_in(view_context)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:rendered) do
|
15
|
+
Capybara::Node::Simple.new(render)
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:docs) { 10.times.map { double } }
|
19
|
+
|
20
|
+
let(:group) do
|
21
|
+
instance_double(Blacklight::Solr::Response::Group, key: 'group1', field: 'group_field', total: 15, docs: docs)
|
22
|
+
end
|
23
|
+
|
24
|
+
before do
|
25
|
+
allow(view_context).to receive(:render_document_index).with(docs).and_return('results')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'renders the group with a header' do
|
29
|
+
expect(rendered).to have_selector 'div.group'
|
30
|
+
expect(rendered).to have_selector 'h2', text: 'group1'
|
31
|
+
expect(rendered).not_to have_link 'more'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'renders the group documents' do
|
35
|
+
expect(rendered).to have_content 'results'
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with a limit applied' do
|
39
|
+
let(:attr) { { group_limit: 5 } }
|
40
|
+
|
41
|
+
it 'renders a control to see more results' do
|
42
|
+
expect(rendered).to have_link 'more'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|