blacklight 9.0.0.beta1 → 9.0.0.beta2
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/.github/matrix.json +47 -0
- data/.github/workflows/build.yml +16 -0
- data/.github/workflows/lint.yml +25 -0
- data/.github/workflows/main.yml +22 -0
- data/.github/workflows/release_7_x_scheduled.yml +39 -0
- data/.github/workflows/release_8_x_scheduled.yml +39 -0
- data/.github/workflows/test.yml +53 -0
- data/.rubocop.yml +70 -2
- data/.rubocop_todo.yml +43 -67
- data/.solr_wrapper.yml +2 -0
- data/VERSION +1 -1
- data/app/assets/builds/blacklight.css +19 -15
- data/app/assets/javascripts/blacklight/blacklight.esm.js +31 -69
- data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
- data/app/assets/javascripts/blacklight/blacklight.js +31 -69
- data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
- data/app/assets/stylesheets/blacklight/_bootstrap_overrides.scss +4 -0
- data/app/assets/stylesheets/blacklight/_facets.scss +2 -2
- data/app/assets/stylesheets/blacklight/_header.scss +4 -0
- data/app/assets/stylesheets/blacklight/_modal.scss +9 -8
- data/app/assets/stylesheets/blacklight/_pagination.scss +1 -3
- data/app/assets/stylesheets/blacklight/_search_history.scss +0 -4
- data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +3 -0
- data/app/components/blacklight/advanced_search_form_component.rb +2 -2
- data/app/components/blacklight/constraints_component.rb +2 -2
- data/app/components/blacklight/document/action_component.rb +1 -3
- data/app/components/blacklight/document/bookmark_component.rb +2 -2
- data/app/components/blacklight/document/more_like_this_component.rb +2 -2
- data/app/components/blacklight/document/page_header_component.rb +2 -2
- data/app/components/blacklight/document/thumbnail_component.html.erb +3 -7
- data/app/components/blacklight/document/thumbnail_component.rb +7 -6
- data/app/components/blacklight/document_component.rb +3 -3
- data/app/components/blacklight/document_title_component.rb +3 -10
- data/app/components/blacklight/facet_field_checkboxes_component.rb +2 -20
- data/app/components/blacklight/facet_field_component.rb +2 -17
- data/app/components/blacklight/facet_field_filter_component.rb +2 -21
- data/app/components/blacklight/facet_field_inclusive_constraint_component.rb +4 -25
- data/app/components/blacklight/facet_field_list_component.rb +2 -32
- data/app/components/blacklight/facet_field_no_layout_component.rb +2 -10
- data/app/components/blacklight/facet_field_pagination_component.html.erb +2 -2
- data/app/components/blacklight/facet_item_component.rb +2 -74
- data/app/components/blacklight/facet_item_pivot_component.rb +1 -1
- data/app/components/blacklight/facets/checkboxes_component.rb +26 -0
- data/app/components/blacklight/facets/count_component.rb +23 -0
- data/app/components/blacklight/{facet_field_component.html.erb → facets/field_component.html.erb} +1 -1
- data/app/components/blacklight/facets/field_component.rb +23 -0
- data/app/components/blacklight/facets/filters_component.html.erb +4 -0
- data/app/components/blacklight/facets/filters_component.rb +27 -0
- data/app/components/blacklight/{facet_field_inclusive_constraint_component.html.erb → facets/inclusive_constraint_component.html.erb} +1 -1
- data/app/components/blacklight/facets/inclusive_constraint_component.rb +31 -0
- data/app/components/blacklight/{facet_field_filter_component.html.erb → facets/index_navigation_component.html.erb} +1 -1
- data/app/components/blacklight/facets/index_navigation_component.rb +32 -0
- data/app/components/blacklight/facets/item_component.rb +73 -0
- data/app/components/blacklight/facets/list_component.html.erb +11 -0
- data/app/components/blacklight/facets/list_component.rb +38 -0
- data/app/components/blacklight/facets/no_layout_component.rb +16 -0
- data/app/components/blacklight/facets/selected_value_component.rb +29 -0
- data/app/components/blacklight/facets/suggest_component.html.erb +12 -0
- data/app/components/blacklight/facets/suggest_component.rb +22 -0
- data/app/components/blacklight/metadata_field_plain_text_layout_component.rb +2 -2
- data/app/components/blacklight/response/facet_group_component.html.erb +1 -1
- data/app/components/blacklight/response/facet_group_component.rb +5 -1
- data/app/components/blacklight/system/dropdown_component.html.erb +1 -1
- data/app/components/blacklight/system/dropdown_component.rb +1 -1
- data/app/components/blacklight/top_navbar_component.html.erb +1 -1
- data/app/controllers/concerns/blacklight/bookmarks.rb +3 -3
- data/app/controllers/concerns/blacklight/catalog.rb +10 -25
- data/app/controllers/concerns/blacklight/controller.rb +1 -1
- data/app/controllers/concerns/blacklight/facetable.rb +34 -0
- data/app/controllers/concerns/blacklight/search_context.rb +1 -1
- data/app/controllers/concerns/blacklight/searchable.rb +1 -1
- data/app/helpers/blacklight/configuration_helper_behavior.rb +2 -2
- data/app/helpers/blacklight/document_helper_behavior.rb +3 -1
- data/app/helpers/blacklight/facets_helper_behavior.rb +9 -0
- data/app/helpers/blacklight/icon_helper_behavior.rb +2 -2
- data/app/javascript/blacklight-frontend/checkbox_submit.js +3 -0
- data/app/javascript/blacklight-frontend/debounce.js +1 -1
- data/app/javascript/blacklight-frontend/facet_suggest.js +23 -3
- data/app/javascript/blacklight-frontend/index.js +0 -2
- data/app/javascript/blacklight-frontend/modal.js +1 -4
- data/app/javascript/blacklight-frontend/search_context.js +3 -2
- data/app/models/facet_search_builder.rb +5 -0
- data/app/presenters/blacklight/facet_field_presenter.rb +1 -1
- data/app/presenters/blacklight/json_presenter.rb +1 -3
- data/app/presenters/blacklight/rendering/helper_method.rb +4 -4
- data/app/presenters/blacklight/rendering/join.rb +2 -2
- data/app/services/blacklight/facet_search_service.rb +44 -0
- data/app/services/blacklight/field_retriever.rb +1 -1
- data/app/services/blacklight/search_service.rb +6 -6
- data/app/values/blacklight/types.rb +2 -2
- data/app/views/catalog/_facet_pivot.html.erb +1 -1
- data/app/views/catalog/_home_text.html.erb +2 -2
- data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
- data/app/views/catalog/facet.html.erb +8 -10
- data/config/locales/blacklight.ar.yml +2 -2
- data/config/locales/blacklight.es.yml +2 -2
- data/config/locales/blacklight.fr.yml +2 -2
- data/config/locales/blacklight.hu.yml +2 -2
- data/config/locales/blacklight.it.yml +2 -2
- data/config/locales/blacklight.nl.yml +1 -1
- data/config/locales/blacklight.pt-BR.yml +2 -2
- data/config/locales/blacklight.sq.yml +2 -2
- data/config/locales/blacklight.zh.yml +2 -2
- data/lib/blacklight/abstract_repository.rb +2 -2
- data/lib/blacklight/abstract_search_builder.rb +154 -0
- data/lib/blacklight/configuration/context.rb +3 -3
- data/lib/blacklight/configuration/facet_field.rb +6 -6
- data/lib/blacklight/configuration/field.rb +4 -4
- data/lib/blacklight/configuration/fields.rb +0 -1
- data/lib/blacklight/configuration/search_field.rb +1 -1
- data/lib/blacklight/configuration/view_config.rb +2 -2
- data/lib/blacklight/configuration.rb +6 -7
- data/lib/blacklight/facet_search_builder.rb +18 -0
- data/lib/blacklight/nested_open_struct_with_hash_access.rb +1 -1
- data/lib/blacklight/open_struct_with_hash_access.rb +2 -2
- data/lib/blacklight/search_builder.rb +1 -159
- data/lib/blacklight/search_state/filter_field.rb +4 -4
- data/lib/blacklight/search_state/pivot_filter_field.rb +4 -4
- data/lib/blacklight/solr/abstract_filter_query_builder.rb +77 -0
- data/lib/blacklight/solr/default_filter_query_builder.rb +20 -0
- data/lib/blacklight/solr/facet_search_builder_behavior.rb +62 -0
- data/lib/blacklight/solr/repository.rb +8 -9
- data/lib/blacklight/solr/response/facets.rb +2 -2
- data/lib/blacklight/solr/response/params.rb +0 -4
- data/lib/blacklight/solr/response.rb +5 -1
- data/lib/blacklight/solr/search_builder_behavior.rb +17 -132
- data/lib/blacklight.rb +1 -1
- data/lib/generators/blacklight/assets/importmap_generator.rb +3 -5
- data/lib/generators/blacklight/assets_generator.rb +1 -1
- data/lib/generators/blacklight/search_builder_generator.rb +1 -1
- data/lib/generators/blacklight/templates/.solr_wrapper.yml +2 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +3 -1
- data/lib/generators/blacklight/templates/solr/conf/solrconfig.xml +0 -4
- data/package.json +3 -3
- data/spec/components/blacklight/advanced_search_form_component_spec.rb +18 -22
- data/spec/components/blacklight/constraint_layout_component_spec.rb +8 -8
- data/spec/components/blacklight/constraints_component_spec.rb +11 -11
- data/spec/components/blacklight/document/action_component_spec.rb +23 -15
- data/spec/components/blacklight/document/group_component_spec.rb +10 -15
- data/spec/components/blacklight/document/page_header_component_spec.rb +35 -28
- data/spec/components/blacklight/document/sidebar_component_spec.rb +5 -11
- data/spec/components/blacklight/document_component_spec.rb +98 -65
- data/spec/components/blacklight/facet_component_spec.rb +12 -8
- data/spec/components/blacklight/facet_item_pivot_component_spec.rb +12 -12
- data/spec/components/blacklight/{facet_field_checkboxes_component_spec.rb → facets/checkboxes_component_spec.rb} +13 -13
- data/spec/components/blacklight/facets/filters_component_spec.rb +36 -0
- data/spec/components/blacklight/facets/index_navigation_component_spec.rb +40 -0
- data/spec/components/blacklight/{facet_item_component_spec.rb → facets/item_component_spec.rb} +10 -10
- data/spec/components/blacklight/{facet_field_list_component_spec.rb → facets/list_component_spec.rb} +23 -23
- data/spec/components/blacklight/facets/suggest_component_spec.rb +68 -0
- data/spec/components/blacklight/header_component_spec.rb +2 -4
- data/spec/components/blacklight/hidden_search_state_component_spec.rb +7 -7
- data/spec/components/blacklight/metadata_field_component_spec.rb +17 -15
- data/spec/components/blacklight/response/facet_group_component_spec.rb +37 -0
- data/spec/components/blacklight/response/pagination_component_spec.rb +1 -1
- data/spec/components/blacklight/response/spellcheck_component_spec.rb +1 -1
- data/spec/components/blacklight/search_bar_component_spec.rb +4 -4
- data/spec/components/blacklight/search_context/server_applied_params_component_spec.rb +2 -2
- data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +3 -5
- data/spec/components/blacklight/skip_link_component_spec.rb +8 -11
- data/spec/components/blacklight/start_over_button_component_spec.rb +4 -4
- data/spec/components/blacklight/system/dropdown_component_spec.rb +26 -0
- data/spec/components/blacklight/system/flash_message_component_spec.rb +7 -11
- data/spec/controllers/catalog_controller_spec.rb +12 -20
- data/spec/features/facets_spec.rb +70 -7
- data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +10 -0
- data/spec/lib/blacklight/configuration/facet_field_spec.rb +2 -2
- data/spec/lib/blacklight/parameters_spec.rb +12 -1
- data/spec/lib/blacklight/search_state/filter_field_spec.rb +18 -0
- data/spec/models/blacklight/configuration_spec.rb +32 -28
- data/spec/models/blacklight/facet_search_builder_spec.rb +19 -0
- data/spec/models/blacklight/search_builder_spec.rb +1 -11
- data/spec/models/blacklight/solr/default_filter_query_builder_spec.rb +72 -0
- data/spec/models/blacklight/solr/document_spec.rb +0 -4
- data/spec/models/blacklight/solr/facet_search_builder_behavior_spec.rb +929 -0
- data/spec/models/blacklight/solr/repository_spec.rb +31 -29
- data/spec/models/blacklight/solr/response/facets_spec.rb +86 -40
- data/spec/models/blacklight/solr/response/group_response_spec.rb +8 -5
- data/spec/models/blacklight/solr/response/group_spec.rb +9 -5
- data/spec/models/blacklight/solr/response_spec.rb +96 -64
- data/spec/models/blacklight/solr/search_builder_behavior_spec.rb +2 -227
- data/spec/models/solr_document_spec.rb +5 -1
- data/spec/services/blacklight/search_service_spec.rb +6 -27
- data/spec/spec_helper.rb +0 -1
- data/spec/support/view_component_test_helpers.rb +0 -18
- data/spec/views/catalog/facet.html.erb_spec.rb +10 -3
- data/spec/views/catalog/index.atom.builder_spec.rb +6 -3
- data/spec/views/catalog/index.html.erb_spec.rb +3 -1
- metadata +58 -29
- data/.github/workflows/ruby.yml +0 -98
- data/app/components/blacklight/facet_field_list_component.html.erb +0 -19
- data/app/components/blacklight/search/facet_suggest_input.html.erb +0 -9
- data/app/components/blacklight/search/facet_suggest_input.rb +0 -16
- data/app/javascript/blacklight-frontend/modalForm.js +0 -60
- data/app/views/catalog/_facet_index_navigation.html.erb +0 -1
- data/app/views/catalog/_facet_layout.html.erb +0 -8
- data/app/views/catalog/_facet_pagination.html.erb +0 -1
- data/spec/components/blacklight/document_metadata_component_spec.rb +0 -0
- data/spec/components/blacklight/search/facet_suggest_input_spec.rb +0 -33
- data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +0 -43
- data/spec/views/catalog/_facet_layout.html.erb_spec.rb +0 -41
- /data/app/components/blacklight/{facet_field_checkboxes_component.html.erb → facets/checkboxes_component.html.erb} +0 -0
@@ -0,0 +1,929 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Blacklight::Solr::FacetSearchBuilderBehavior, :api do
|
4
|
+
subject { search_builder.with(user_params) }
|
5
|
+
|
6
|
+
let(:single_facet) { { format: ['Book'] } }
|
7
|
+
let(:search_builder_class) do
|
8
|
+
Class.new(Blacklight::FacetSearchBuilder) do
|
9
|
+
include Blacklight::Solr::FacetSearchBuilderBehavior
|
10
|
+
end
|
11
|
+
end
|
12
|
+
let(:search_builder) { search_builder_class.new(context) }
|
13
|
+
let(:multi_facets) { { format: ['Book'], language_ssim: ['Tibetan'] } }
|
14
|
+
let(:mult_word_query) { 'tibetan history' }
|
15
|
+
let(:subject_search_params) { { commit: "search", search_field: "subject", action: "index", controller: "catalog", rows: "10", q: "wome" } }
|
16
|
+
|
17
|
+
let(:blacklight_config) { CatalogController.blacklight_config.deep_copy }
|
18
|
+
let(:user_params) { {} }
|
19
|
+
let(:context) { CatalogController.new }
|
20
|
+
|
21
|
+
before { allow(context).to receive(:blacklight_config).and_return(blacklight_config) }
|
22
|
+
|
23
|
+
# context "with default processor chain" do
|
24
|
+
# subject { search_builder }
|
25
|
+
|
26
|
+
# it "uses the class-level default_processor_chain" do
|
27
|
+
# expect(subject.processor_chain).to eq search_builder_class.default_processor_chain
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
|
31
|
+
# context 'with merged parameters from the defaults + the search field' do
|
32
|
+
# before do
|
33
|
+
# blacklight_config.default_solr_params = { json: { whatever: [1, 2, 3] } }
|
34
|
+
# blacklight_config.search_fields['all_fields'].solr_parameters = { json: { and_also: [4, 5, 6] } }
|
35
|
+
# end
|
36
|
+
|
37
|
+
# let(:user_params) { { search_field: 'all_fields' } }
|
38
|
+
|
39
|
+
# it 'deep merges hash values' do
|
40
|
+
# expect(subject.to_hash.dig(:json, :whatever)).to eq [1, 2, 3]
|
41
|
+
# expect(subject.to_hash.dig(:json, :and_also)).to eq [4, 5, 6]
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
|
45
|
+
# context "with a complex parameter environment" do
|
46
|
+
# subject { search_builder.with(user_params).send(:processed_parameters) }
|
47
|
+
|
48
|
+
# let(:user_params) do
|
49
|
+
# { :search_field => "test_field", :q => "test query", "facet.field" => "extra_facet" }
|
50
|
+
# end
|
51
|
+
|
52
|
+
# let(:blacklight_config) do
|
53
|
+
# Blacklight::Configuration.new.tap do |config|
|
54
|
+
# config.add_search_field("test_field",
|
55
|
+
# display_label: "Test",
|
56
|
+
# key: "test_field",
|
57
|
+
# solr_parameters: {
|
58
|
+
# qf: "fieldOne^2.3 fieldTwo fieldThree^0.4",
|
59
|
+
# pf: "",
|
60
|
+
# spellcheck: 'false',
|
61
|
+
# sort: "request_params_sort"
|
62
|
+
# })
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
|
66
|
+
# it "merges parameters from search_field definition" do
|
67
|
+
# expect(subject[:qf]).to eq "fieldOne^2.3 fieldTwo fieldThree^0.4"
|
68
|
+
# expect(subject[:spellcheck]).to eq 'false'
|
69
|
+
# end
|
70
|
+
|
71
|
+
# it "merges empty string parameters from search_field definition" do
|
72
|
+
# expect(subject[:pf]).to eq ""
|
73
|
+
# end
|
74
|
+
|
75
|
+
# describe "should respect proper precedence of settings," do
|
76
|
+
# it "does not put :search_field in produced params" do
|
77
|
+
# expect(subject[:search_field]).to be_nil
|
78
|
+
# end
|
79
|
+
|
80
|
+
# it "falls through to BL general defaults for qt not otherwise specified" do
|
81
|
+
# expect(subject[:qt]).to eq blacklight_config[:default_solr_params][:qt]
|
82
|
+
# end
|
83
|
+
|
84
|
+
# it "takes q from request params" do
|
85
|
+
# expect(subject[:q]).to eq "test query"
|
86
|
+
# end
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
|
90
|
+
# # SPECS for actual search parameter generation
|
91
|
+
# describe "#processed_parameters" do
|
92
|
+
# subject do
|
93
|
+
# search_builder.with(user_params).send(:processed_parameters)
|
94
|
+
# end
|
95
|
+
|
96
|
+
# context "when search_params_logic is customized" do
|
97
|
+
# let(:search_builder) { search_builder_class.new(method_chain, context) }
|
98
|
+
# let(:method_chain) { [:add_foo_to_solr_params] }
|
99
|
+
|
100
|
+
# it "allows customization of search_params_logic" do
|
101
|
+
# allow(search_builder).to receive(:add_foo_to_solr_params) do |solr_params, _user_params|
|
102
|
+
# solr_params[:wt] = "TESTING"
|
103
|
+
# end
|
104
|
+
|
105
|
+
# expect(subject[:wt]).to eq "TESTING"
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
|
109
|
+
# it "generates a facet limit" do
|
110
|
+
# expect(subject[:'f.subject_ssim.facet.limit']).to eq 21
|
111
|
+
# end
|
112
|
+
|
113
|
+
# context 'with a negative facet limit' do
|
114
|
+
# before do
|
115
|
+
# blacklight_config.facet_fields['subject_ssim'].limit = -1
|
116
|
+
# end
|
117
|
+
|
118
|
+
# it 'is negative' do
|
119
|
+
# expect(subject[:'f.subject_ssim.facet.limit']).to eq(-1)
|
120
|
+
# end
|
121
|
+
# end
|
122
|
+
|
123
|
+
# context 'with a facet limit set to 0' do
|
124
|
+
# before do
|
125
|
+
# blacklight_config.facet_fields['subject_ssim'].limit = 0
|
126
|
+
# end
|
127
|
+
|
128
|
+
# it 'is negative' do
|
129
|
+
# expect(subject[:'f.subject_ssim.facet.limit']).to eq 0
|
130
|
+
# end
|
131
|
+
# end
|
132
|
+
|
133
|
+
# it "handles no facet_limits in config" do
|
134
|
+
# blacklight_config.facet_fields = {}
|
135
|
+
# expect(subject).not_to have_key(:'f.subject_ssim.facet.limit')
|
136
|
+
# end
|
137
|
+
|
138
|
+
# describe "with max per page enforced" do
|
139
|
+
# let(:blacklight_config) do
|
140
|
+
# Blacklight::Configuration.new.tap do |config|
|
141
|
+
# config.max_per_page = 123
|
142
|
+
# end
|
143
|
+
# end
|
144
|
+
|
145
|
+
# let(:user_params) { { per_page: 98_765 } }
|
146
|
+
|
147
|
+
# it "enforces max_per_page against all parameters" do
|
148
|
+
# expect(blacklight_config.max_per_page).to eq 123
|
149
|
+
# expect(subject[:rows]).to eq 123
|
150
|
+
# end
|
151
|
+
# end
|
152
|
+
|
153
|
+
# context "facet parameters" do
|
154
|
+
# let(:blacklight_config) do
|
155
|
+
# Blacklight::Configuration.new.tap do |config|
|
156
|
+
# config.add_facet_field key: 'param_key', field: 'solr_field', limit: 50, ex: 'other'
|
157
|
+
|
158
|
+
# config.add_facet_fields_to_solr_request!
|
159
|
+
# end
|
160
|
+
# end
|
161
|
+
|
162
|
+
# it "uses the configured solr field name in queries" do
|
163
|
+
# expect(subject).to include 'f.solr_field.facet.limit': 51,
|
164
|
+
# 'facet.field': ['{!ex=other}solr_field']
|
165
|
+
# end
|
166
|
+
# end
|
167
|
+
|
168
|
+
# describe 'for an entirely empty search' do
|
169
|
+
# it 'does not have a q param' do
|
170
|
+
# expect(subject[:q]).to be_nil
|
171
|
+
# expect(subject["spellcheck.q"]).to be_nil
|
172
|
+
# end
|
173
|
+
|
174
|
+
# it 'has default rows' do
|
175
|
+
# expect(subject[:rows]).to eq 10
|
176
|
+
# end
|
177
|
+
|
178
|
+
# it 'has default facet fields' do
|
179
|
+
# # remove local params from the facet.field
|
180
|
+
# expect(subject[:'facet.field'].map { |x| x.gsub(/\{![^}]+\}/, '') }).to match_array %w[format subject_ssim pub_date_ssim language_ssim lc_1letter_ssim subject_geo_ssim subject_era_ssim]
|
181
|
+
# end
|
182
|
+
|
183
|
+
# it "does not have a default qt" do
|
184
|
+
# expect(subject[:qt]).to be_nil
|
185
|
+
# end
|
186
|
+
|
187
|
+
# it "has no fq" do
|
188
|
+
# expect(subject[:phrase_filters]).to be_blank
|
189
|
+
# expect(subject[:fq]).to be_blank
|
190
|
+
# end
|
191
|
+
# end
|
192
|
+
|
193
|
+
# describe "for a missing string search" do
|
194
|
+
# let(:user_params) { { q: nil } }
|
195
|
+
|
196
|
+
# it "does not populate the q parameter in solr parameters" do
|
197
|
+
# expect(subject).not_to have_key :q
|
198
|
+
# end
|
199
|
+
# end
|
200
|
+
|
201
|
+
# describe "for an empty string search" do
|
202
|
+
# let(:user_params) { { q: "" } }
|
203
|
+
|
204
|
+
# it "returns empty string q in solr parameters" do
|
205
|
+
# expect(subject[:q]).to eq ""
|
206
|
+
# end
|
207
|
+
# end
|
208
|
+
|
209
|
+
# describe "for request params also passed in as argument" do
|
210
|
+
# let(:user_params) { { 'q' => 'another value', q: "some query" } }
|
211
|
+
|
212
|
+
# it "only has one value for the key 'q' regardless if a symbol or string" do
|
213
|
+
# expect(subject[:q]).to eq 'some query'
|
214
|
+
# expect(subject['q']).to eq 'some query'
|
215
|
+
# end
|
216
|
+
# end
|
217
|
+
|
218
|
+
# describe "for one facet, no query" do
|
219
|
+
# let(:user_params) { { f: single_facet } }
|
220
|
+
|
221
|
+
# it "has proper solr parameters" do
|
222
|
+
# expect(subject[:q]).to be_blank
|
223
|
+
# expect(subject["spellcheck.q"]).to be_blank
|
224
|
+
|
225
|
+
# single_facet.each_value do |value|
|
226
|
+
# value.each do |v|
|
227
|
+
# expect(subject[:fq]).to include("{!term f=#{single_facet.keys[0]}}#{v}")
|
228
|
+
# end
|
229
|
+
# end
|
230
|
+
# end
|
231
|
+
# end
|
232
|
+
|
233
|
+
# describe "for an empty facet limit param" do
|
234
|
+
# let(:user_params) { { f: { "format" => [""] } } }
|
235
|
+
|
236
|
+
# it "does not add any fq to solr" do
|
237
|
+
# expect(subject[:fq]).to be_blank
|
238
|
+
# end
|
239
|
+
# end
|
240
|
+
|
241
|
+
# describe "with Multi Facets, No Query" do
|
242
|
+
# let(:user_params) { { f: multi_facets } }
|
243
|
+
|
244
|
+
# it 'has fq set properly' do
|
245
|
+
# multi_facets.each_pair do |facet_field, value_list|
|
246
|
+
# value_list ||= []
|
247
|
+
# value_list = [value_list] unless value_list.respond_to? :each
|
248
|
+
# value_list.each do |value|
|
249
|
+
# expect(subject[:fq]).to include("{!term f=#{facet_field}}#{value}")
|
250
|
+
# end
|
251
|
+
# end
|
252
|
+
# end
|
253
|
+
# end
|
254
|
+
|
255
|
+
# describe "with Multi Facets, Multi Word Query" do
|
256
|
+
# let(:user_params) { { q: mult_word_query, f: multi_facets } }
|
257
|
+
|
258
|
+
# it 'has fq and q set properly' do
|
259
|
+
# multi_facets.each_pair do |facet_field, value_list|
|
260
|
+
# value_list ||= []
|
261
|
+
# value_list = [value_list] unless value_list.respond_to? :each
|
262
|
+
# value_list.each do |value|
|
263
|
+
# expect(subject[:fq]).to include("{!term f=#{facet_field}}#{value}")
|
264
|
+
# end
|
265
|
+
# end
|
266
|
+
# expect(subject[:q]).to eq mult_word_query
|
267
|
+
# end
|
268
|
+
# end
|
269
|
+
|
270
|
+
# describe 'with a facet with a custom filter query builder' do
|
271
|
+
# let(:user_params) { { f: { some: ['value'] } }.with_indifferent_access }
|
272
|
+
|
273
|
+
# before do
|
274
|
+
# blacklight_config.add_facet_field 'some', filter_query_builder: (lambda do |*_args|
|
275
|
+
# ['some:filter', { qq1: 'abc' }]
|
276
|
+
# end)
|
277
|
+
# end
|
278
|
+
|
279
|
+
# it "has proper solr parameters" do
|
280
|
+
# expect(subject[:fq]).to include('some:filter')
|
281
|
+
# expect(subject[:qq1]).to include('abc')
|
282
|
+
# end
|
283
|
+
# end
|
284
|
+
|
285
|
+
# context 'with a facet with a custom filter query builder that returns multiple values' do
|
286
|
+
# let(:user_params) { { f: { some: ['value'] } }.with_indifferent_access }
|
287
|
+
|
288
|
+
# before do
|
289
|
+
# blacklight_config.add_facet_field 'some', filter_query_builder: (lambda do |*_args|
|
290
|
+
# [['some:filter', 'another:filter'], { qq1: 'abc' }]
|
291
|
+
# end)
|
292
|
+
# end
|
293
|
+
|
294
|
+
# it "has proper solr parameters" do
|
295
|
+
# expect(subject[:fq]).to include('some:filter', 'another:filter')
|
296
|
+
# expect(subject[:qq1]).to include('abc')
|
297
|
+
# end
|
298
|
+
# end
|
299
|
+
|
300
|
+
# describe 'with a json facet' do
|
301
|
+
# let(:user_params) { { f: { json_facet: ['value'] } }.with_indifferent_access }
|
302
|
+
|
303
|
+
# before do
|
304
|
+
# blacklight_config.add_facet_field 'json_facet', field: 'foo', json: { bar: 'baz' }
|
305
|
+
# end
|
306
|
+
|
307
|
+
# it "has proper solr parameters" do
|
308
|
+
# expect(subject[:fq]).to include('{!term f=foo}value')
|
309
|
+
# expect(subject.dig(:json, :facet, 'json_facet')).to include(
|
310
|
+
# field: 'foo',
|
311
|
+
# type: 'terms',
|
312
|
+
# bar: 'baz'
|
313
|
+
# )
|
314
|
+
# end
|
315
|
+
# end
|
316
|
+
|
317
|
+
# describe 'with multi-valued facets' do
|
318
|
+
# let(:user_params) { { f_inclusive: { format: %w[Book Movie CD] } } }
|
319
|
+
|
320
|
+
# it "has proper solr parameters" do
|
321
|
+
# expect(subject[:fq]).to include('{!lucene}{!query v=$f_inclusive.format.0} OR {!query v=$f_inclusive.format.1} OR {!query v=$f_inclusive.format.2}')
|
322
|
+
# expect(subject['f_inclusive.format.0']).to eq '{!term f=format}Book'
|
323
|
+
# expect(subject['f_inclusive.format.1']).to eq '{!term f=format}Movie'
|
324
|
+
# expect(subject['f_inclusive.format.2']).to eq '{!term f=format}CD'
|
325
|
+
# end
|
326
|
+
# end
|
327
|
+
|
328
|
+
# describe "solr parameters for a field search from config (subject)" do
|
329
|
+
# let(:user_params) { subject_search_params }
|
330
|
+
|
331
|
+
# before do
|
332
|
+
# # The tests below expect pre-solr-7.2 queries with local params
|
333
|
+
# blacklight_config.search_fields['subject'].solr_local_parameters = {
|
334
|
+
# qf: '$subject_qf',
|
335
|
+
# pf: '$subject_pf'
|
336
|
+
# }
|
337
|
+
# blacklight_config.search_fields['subject'].clause_params = nil
|
338
|
+
# end
|
339
|
+
|
340
|
+
# it "looks up qt from field definition" do
|
341
|
+
# expect(subject[:qt]).to eq "search"
|
342
|
+
# end
|
343
|
+
|
344
|
+
# it "does not include weird keys not in field definition" do
|
345
|
+
# expect(subject[:phrase_filters]).to be_nil
|
346
|
+
# expect(subject[:commit]).to be_nil
|
347
|
+
# expect(subject[:action]).to be_nil
|
348
|
+
# expect(subject[:controller]).to be_nil
|
349
|
+
# end
|
350
|
+
|
351
|
+
# it "includes proper 'q', possibly with LocalParams" do
|
352
|
+
# expect(subject[:q]).to match(/(\{[^}]+\})?wome/)
|
353
|
+
# end
|
354
|
+
|
355
|
+
# it "includes proper 'q' when LocalParams are used" do
|
356
|
+
# if /\{[^}]+\}/.match?(subject[:q])
|
357
|
+
# expect(subject[:q]).to match(/\{[^}]+\}wome/)
|
358
|
+
# end
|
359
|
+
# end
|
360
|
+
|
361
|
+
# it "includes spellcheck.q, without LocalParams" do
|
362
|
+
# expect(subject["spellcheck.q"]).to eq "wome"
|
363
|
+
# end
|
364
|
+
|
365
|
+
# it "includes spellcheck.dictionary from field def solr_parameters" do
|
366
|
+
# expect(subject[:'spellcheck.dictionary']).to eq "subject"
|
367
|
+
# end
|
368
|
+
|
369
|
+
# it "adds on :solr_local_parameters using Solr LocalParams style" do
|
370
|
+
# # q == "{!pf=$subject_pf $qf=subject_qf} wome", make sure
|
371
|
+
# # the LocalParams are really there
|
372
|
+
# subject[:q] =~ /^\{!([^}]+)\}/
|
373
|
+
# key_value_pairs = Regexp.last_match(1).split
|
374
|
+
# expect(key_value_pairs).to include("pf=$subject_pf")
|
375
|
+
# expect(key_value_pairs).to include("qf=$subject_qf")
|
376
|
+
# end
|
377
|
+
|
378
|
+
# context 'when subject field uses JSON query DSL' do
|
379
|
+
# before do
|
380
|
+
# blacklight_config.search_fields['subject'].clause_params = {
|
381
|
+
# edismax: {}
|
382
|
+
# }
|
383
|
+
# end
|
384
|
+
|
385
|
+
# it "includes spellcheck.q, without LocalParams" do
|
386
|
+
# expect(subject["spellcheck.q"]).to eq "wome"
|
387
|
+
# end
|
388
|
+
# end
|
389
|
+
# end
|
390
|
+
|
391
|
+
# describe "solr json query parameters from the fielded search" do
|
392
|
+
# let(:user_params) { subject_search_params }
|
393
|
+
|
394
|
+
# before do
|
395
|
+
# blacklight_config.search_fields['subject'].solr_parameters = {
|
396
|
+
# some: :parameter
|
397
|
+
# }
|
398
|
+
|
399
|
+
# blacklight_config.search_fields['subject'].clause_params = {
|
400
|
+
# edismax: {
|
401
|
+
# another: :parameter
|
402
|
+
# }
|
403
|
+
# }
|
404
|
+
# end
|
405
|
+
|
406
|
+
# it 'sets solr parameters from the field' do
|
407
|
+
# expect(subject[:some]).to eq :parameter
|
408
|
+
# end
|
409
|
+
|
410
|
+
# it 'does not set a q parameter' do
|
411
|
+
# expect(subject).not_to have_key :q
|
412
|
+
# end
|
413
|
+
|
414
|
+
# it 'includes the user query in the JSON query DSL request' do
|
415
|
+
# expect(subject.dig(:json, :query, :bool, :must, 0, :edismax)).to include query: 'wome'
|
416
|
+
# end
|
417
|
+
|
418
|
+
# it 'includes addtional clause parameters for the field' do
|
419
|
+
# expect(subject.dig(:json, :query, :bool, :must, 0, :edismax)).to include another: :parameter
|
420
|
+
# end
|
421
|
+
|
422
|
+
# context 'with an empty search' do
|
423
|
+
# let(:subject_search_params) { { commit: "search", search_field: "subject", action: "index", controller: "catalog", rows: "10", q: nil } }
|
424
|
+
|
425
|
+
# it 'does not add nil query value clauses to json query' do
|
426
|
+
# expect(subject).not_to have_key :json
|
427
|
+
# end
|
428
|
+
# end
|
429
|
+
# end
|
430
|
+
|
431
|
+
# describe "sorting" do
|
432
|
+
# context 'when the user has not provided a value' do
|
433
|
+
# it 'sends the default sort parameter to solr' do
|
434
|
+
# expect(subject[:sort]).to eq 'score desc, pub_date_si desc, title_si asc'
|
435
|
+
# end
|
436
|
+
# end
|
437
|
+
|
438
|
+
# context "when the configured sort field is blank" do
|
439
|
+
# before do
|
440
|
+
# blacklight_config.sort_fields = {}
|
441
|
+
# blacklight_config.add_sort_field('', label: 'test')
|
442
|
+
# end
|
443
|
+
|
444
|
+
# it "does not send a sort parameter to solr if the sort value is blank" do
|
445
|
+
# expect(subject).not_to have_key(:sort)
|
446
|
+
# end
|
447
|
+
# end
|
448
|
+
|
449
|
+
# context "when the user provides a valid sort parmeter" do
|
450
|
+
# let(:user_params) { { sort: 'title_si asc, pub_date_si desc' } }
|
451
|
+
|
452
|
+
# it "passes them through" do
|
453
|
+
# expect(subject[:sort]).to eq 'title_si asc, pub_date_si desc'
|
454
|
+
# end
|
455
|
+
# end
|
456
|
+
|
457
|
+
# context "when the user provides a valid customized sort parmeter" do
|
458
|
+
# let(:user_params) { { sort: 'year-desc' } }
|
459
|
+
|
460
|
+
# it "passes solr sort paramters through" do
|
461
|
+
# expect(subject[:sort]).to eq 'pub_date_si desc, title_si asc'
|
462
|
+
# end
|
463
|
+
# end
|
464
|
+
|
465
|
+
# context "when the user provides an invalid sort parameter" do
|
466
|
+
# let(:user_params) { { sort: 'bad' } }
|
467
|
+
|
468
|
+
# it "removes them" do
|
469
|
+
# expect(subject).not_to have_key(:sort)
|
470
|
+
# end
|
471
|
+
# end
|
472
|
+
# end
|
473
|
+
|
474
|
+
# describe "for :solr_local_parameters config" do
|
475
|
+
# let(:blacklight_config) do
|
476
|
+
# config = Blacklight::Configuration.new
|
477
|
+
# config.add_search_field(
|
478
|
+
# "custom_author_key",
|
479
|
+
# display_label: "Author",
|
480
|
+
# qt: "author_qt",
|
481
|
+
# key: "custom_author_key",
|
482
|
+
# solr_local_parameters: {
|
483
|
+
# qf: "$author_qf",
|
484
|
+
# pf: "you'll have \" to escape this",
|
485
|
+
# pf2: "$pf2_do_not_escape_or_quote"
|
486
|
+
# },
|
487
|
+
# solr_parameters: {
|
488
|
+
# qf: "someField^1000",
|
489
|
+
# ps: "2"
|
490
|
+
# }
|
491
|
+
# )
|
492
|
+
# return config
|
493
|
+
# end
|
494
|
+
|
495
|
+
# let(:user_params) { { search_field: "custom_author_key", q: "query" } }
|
496
|
+
|
497
|
+
# it "passes through ordinary params" do
|
498
|
+
# expect(subject[:qt]).to eq "author_qt"
|
499
|
+
# expect(subject[:ps]).to eq "2"
|
500
|
+
# expect(subject[:qf]).to eq "someField^1000"
|
501
|
+
# end
|
502
|
+
|
503
|
+
# it "includes include local params with escaping" do
|
504
|
+
# expect(subject[:q]).to include('qf=$author_qf')
|
505
|
+
# expect(subject[:q]).to include('pf=\'you\\\'ll have \\" to escape this\'')
|
506
|
+
# expect(subject[:q]).to include('pf2=$pf2_do_not_escape_or_quote')
|
507
|
+
# end
|
508
|
+
# end
|
509
|
+
|
510
|
+
# describe 'the search field query_builder config' do
|
511
|
+
# let(:blacklight_config) do
|
512
|
+
# Blacklight::Configuration.new do |config|
|
513
|
+
# config.add_search_field('built_query', query_builder: ->(builder, *_args) { [builder.blacklight_params[:q].reverse, { qq1: 'xyz' }] })
|
514
|
+
# end
|
515
|
+
# end
|
516
|
+
|
517
|
+
# let(:user_params) { { search_field: 'built_query', q: 'value' } }
|
518
|
+
|
519
|
+
# it 'uses the provided query builder' do
|
520
|
+
# expect(subject[:q]).to eq 'eulav'
|
521
|
+
# expect(subject[:qq1]).to eq 'xyz'
|
522
|
+
# end
|
523
|
+
# end
|
524
|
+
# end
|
525
|
+
|
526
|
+
# describe "#facet_value_to_fq_string" do
|
527
|
+
# it "uses the configured field name" do
|
528
|
+
# blacklight_config.add_facet_field :facet_key, field: "facet_name"
|
529
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_key", "my value")).to eq "{!term f=facet_name}my value"
|
530
|
+
# end
|
531
|
+
|
532
|
+
# it "uses the raw handler for strings" do
|
533
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", "my value")).to eq "{!term f=facet_name}my value"
|
534
|
+
# end
|
535
|
+
|
536
|
+
# it "passes booleans through" do
|
537
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", true)).to eq '{!term f=facet_name}true'
|
538
|
+
# end
|
539
|
+
|
540
|
+
# it "passes boolean-like strings through" do
|
541
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", "true")).to eq '{!term f=facet_name}true'
|
542
|
+
# end
|
543
|
+
|
544
|
+
# it "passes integers through" do
|
545
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", 1)).to eq '{!term f=facet_name}1'
|
546
|
+
# end
|
547
|
+
|
548
|
+
# it "passes integer-like strings through" do
|
549
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", "1")).to eq '{!term f=facet_name}1'
|
550
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", -1)).to eq '{!term f=facet_name}-1'
|
551
|
+
# end
|
552
|
+
|
553
|
+
# it "passes floats through" do
|
554
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", 1.11)).to eq '{!term f=facet_name}1.11'
|
555
|
+
# end
|
556
|
+
|
557
|
+
# it "passes floats in strings through" do
|
558
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", "1.11")).to eq '{!term f=facet_name}1.11'
|
559
|
+
# end
|
560
|
+
|
561
|
+
# context 'date handling' do
|
562
|
+
# before { allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(date: true, query: nil, tag: nil, field: 'facet_name')) }
|
563
|
+
|
564
|
+
# it "passes date-type fields through" do
|
565
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", "2012-01-01")).to eq '{!term f=facet_name}2012-01-01'
|
566
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", "2003-04-09T00:00:00Z")).to eq '{!term f=facet_name}2003-04-09T00:00:00Z'
|
567
|
+
# end
|
568
|
+
|
569
|
+
# it "formats Date objects correctly" do
|
570
|
+
# allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(date: nil, query: nil, tag: nil, field: 'facet_name'))
|
571
|
+
# d = DateTime.parse("2003-04-09T00:00:00")
|
572
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", d)).to eq '{!term f=facet_name}2003-04-09T00:00:00Z'
|
573
|
+
# end
|
574
|
+
# end
|
575
|
+
|
576
|
+
# it "handles range requests" do
|
577
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", 1..5)).to eq "facet_name:[1 TO 5]"
|
578
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", 1..nil)).to eq "facet_name:[1 TO *]"
|
579
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", nil..5)).to eq "facet_name:[* TO 5]"
|
580
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", nil..nil)).to eq "facet_name:[* TO *]"
|
581
|
+
# end
|
582
|
+
|
583
|
+
# it "adds tag local parameters" do
|
584
|
+
# allow(blacklight_config.facet_fields).to receive(:[]).with('facet_name').and_return(double(query: nil, tag: 'asdf', date: nil, field: 'facet_name'))
|
585
|
+
|
586
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", true)).to eq "{!term f=facet_name tag=asdf}true"
|
587
|
+
# expect(subject.send(:facet_value_to_fq_string, "facet_name", "my value")).to eq "{!term f=facet_name tag=asdf}my value"
|
588
|
+
# end
|
589
|
+
# end
|
590
|
+
|
591
|
+
# describe "#add_facet_fq_to_solr" do
|
592
|
+
# it "converts a String fq into an Array" do
|
593
|
+
# solr_parameters = { fq: 'a string' }
|
594
|
+
|
595
|
+
# subject.add_facet_fq_to_solr(solr_parameters)
|
596
|
+
|
597
|
+
# expect(solr_parameters[:fq]).to be_a Array
|
598
|
+
# end
|
599
|
+
|
600
|
+
# context "facet not defined in config" do
|
601
|
+
# let(:single_facet) { { unknown_facet_field: "foo" } }
|
602
|
+
# let(:user_params) { { f: single_facet } }
|
603
|
+
|
604
|
+
# it "does not add facet to solr_parameters" do
|
605
|
+
# solr_parameters = Blacklight::Solr::Request.new
|
606
|
+
# subject.add_facet_fq_to_solr(solr_parameters)
|
607
|
+
# expect(solr_parameters[:fq]).to be_blank
|
608
|
+
# end
|
609
|
+
# end
|
610
|
+
# end
|
611
|
+
|
612
|
+
# describe "#add_solr_fields_to_query" do
|
613
|
+
# let(:blacklight_config) do
|
614
|
+
# Blacklight::Configuration.new do |config|
|
615
|
+
# config.add_index_field 'an_index_field', solr_params: { 'hl.alternativeField' => 'field_x' }
|
616
|
+
# config.add_show_field 'a_show_field', solr_params: { 'hl.alternativeField' => 'field_y' }
|
617
|
+
# config.add_field_configuration_to_solr_request!
|
618
|
+
# end
|
619
|
+
# end
|
620
|
+
|
621
|
+
# let(:solr_parameters) do
|
622
|
+
# solr_parameters = Blacklight::Solr::Request.new
|
623
|
+
|
624
|
+
# subject.add_solr_fields_to_query(solr_parameters)
|
625
|
+
|
626
|
+
# solr_parameters
|
627
|
+
# end
|
628
|
+
|
629
|
+
# it "adds any extra solr parameters from index and show fields" do
|
630
|
+
# expect(solr_parameters[:'f.an_index_field.hl.alternativeField']).to eq "field_x"
|
631
|
+
# expect(solr_parameters[:'f.a_show_field.hl.alternativeField']).to eq "field_y"
|
632
|
+
# end
|
633
|
+
# end
|
634
|
+
|
635
|
+
# describe "#add_facetting_to_solr" do
|
636
|
+
# let(:blacklight_config) do
|
637
|
+
# Blacklight::Configuration.new do |config|
|
638
|
+
# config.add_facet_field 'test_field', sort: 'count'
|
639
|
+
# config.add_facet_field 'some-query', query: { 'x' => { fq: 'some:query' } }, ex: 'xyz'
|
640
|
+
# config.add_facet_field 'some-pivot', pivot: %w[a b], ex: 'xyz'
|
641
|
+
# config.add_facet_field 'some-field', solr_params: { 'facet.mincount' => 15 }
|
642
|
+
# config.add_facet_fields_to_solr_request!
|
643
|
+
# end
|
644
|
+
# end
|
645
|
+
|
646
|
+
# let(:solr_parameters) do
|
647
|
+
# solr_parameters = Blacklight::Solr::Request.new
|
648
|
+
|
649
|
+
# subject.add_facetting_to_solr(solr_parameters)
|
650
|
+
|
651
|
+
# solr_parameters
|
652
|
+
# end
|
653
|
+
|
654
|
+
# it "adds sort parameters" do
|
655
|
+
# expect(solr_parameters[:facet]).to be true
|
656
|
+
|
657
|
+
# expect(solr_parameters[:'facet.field']).to include('test_field')
|
658
|
+
# expect(solr_parameters[:'f.test_field.facet.sort']).to eq 'count'
|
659
|
+
# end
|
660
|
+
|
661
|
+
# it "adds facet exclusions" do
|
662
|
+
# expect(solr_parameters[:'facet.query']).to include('{!ex=xyz}some:query')
|
663
|
+
# expect(solr_parameters[:'facet.pivot']).to include('{!ex=xyz}a,b')
|
664
|
+
# end
|
665
|
+
|
666
|
+
# it "adds any additional solr_params" do
|
667
|
+
# expect(solr_parameters[:'f.some-field.facet.mincount']).to eq 15
|
668
|
+
# end
|
669
|
+
|
670
|
+
# describe ":include_in_request" do
|
671
|
+
# let(:solr_parameters) do
|
672
|
+
# solr_parameters = Blacklight::Solr::Request.new
|
673
|
+
# subject.add_facetting_to_solr(solr_parameters)
|
674
|
+
# solr_parameters
|
675
|
+
# end
|
676
|
+
|
677
|
+
# it "respects the include_in_request parameter" do
|
678
|
+
# blacklight_config.add_facet_field 'yes_facet', include_in_request: true
|
679
|
+
# blacklight_config.add_facet_field 'no_facet', include_in_request: false
|
680
|
+
|
681
|
+
# expect(solr_parameters[:'facet.field']).to include('yes_facet')
|
682
|
+
# expect(solr_parameters[:'facet.field']).not_to include('no_facet')
|
683
|
+
# end
|
684
|
+
|
685
|
+
# it "defaults to including facets if add_facet_fields_to_solr_request! was called" do
|
686
|
+
# blacklight_config.add_facet_field 'yes_facet'
|
687
|
+
# blacklight_config.add_facet_field 'no_facet', include_in_request: false
|
688
|
+
# blacklight_config.add_facet_fields_to_solr_request!
|
689
|
+
|
690
|
+
# expect(solr_parameters[:'facet.field']).to include('yes_facet')
|
691
|
+
# expect(solr_parameters[:'facet.field']).not_to include('no_facet')
|
692
|
+
# end
|
693
|
+
# end
|
694
|
+
|
695
|
+
# describe ":add_facet_fields_to_solr_request!" do
|
696
|
+
# let(:blacklight_config) do
|
697
|
+
# config = Blacklight::Configuration.new
|
698
|
+
# config.add_facet_field 'yes_facet', include_in_request: true
|
699
|
+
# config.add_facet_field 'no_facet', include_in_request: false
|
700
|
+
# config.add_facet_field 'maybe_facet'
|
701
|
+
# config.add_facet_field 'another_facet'
|
702
|
+
# config
|
703
|
+
# end
|
704
|
+
|
705
|
+
# let(:solr_parameters) do
|
706
|
+
# solr_parameters = Blacklight::Solr::Request.new
|
707
|
+
# subject.add_facetting_to_solr(solr_parameters)
|
708
|
+
# solr_parameters
|
709
|
+
# end
|
710
|
+
|
711
|
+
# it "adds facets to the solr request" do
|
712
|
+
# blacklight_config.add_facet_fields_to_solr_request!
|
713
|
+
# expect(solr_parameters[:'facet.field']).to match_array %w[yes_facet maybe_facet another_facet]
|
714
|
+
# end
|
715
|
+
|
716
|
+
# it "does not override field-specific configuration by default" do
|
717
|
+
# blacklight_config.add_facet_fields_to_solr_request!
|
718
|
+
# expect(solr_parameters[:'facet.field']).not_to include 'no_facet'
|
719
|
+
# end
|
720
|
+
|
721
|
+
# it "allows white-listing facets" do
|
722
|
+
# blacklight_config.add_facet_fields_to_solr_request! 'maybe_facet'
|
723
|
+
# expect(solr_parameters[:'facet.field']).to include 'maybe_facet'
|
724
|
+
# expect(solr_parameters[:'facet.field']).not_to include 'another_facet'
|
725
|
+
# end
|
726
|
+
|
727
|
+
# it "allows white-listed facets to override any field-specific include_in_request configuration" do
|
728
|
+
# blacklight_config.add_facet_fields_to_solr_request! 'no_facet'
|
729
|
+
# expect(solr_parameters[:'facet.field']).to include 'no_facet'
|
730
|
+
# end
|
731
|
+
# end
|
732
|
+
# end
|
733
|
+
|
734
|
+
describe "#add_facet_paging_to_solr" do
|
735
|
+
let(:facet_field) { 'format' }
|
736
|
+
let(:sort_key) { Blacklight::Solr::FacetPaginator.request_keys[:sort] }
|
737
|
+
let(:page_key) { Blacklight::Solr::FacetPaginator.request_keys[:page] }
|
738
|
+
let(:prefix_key) { Blacklight::Solr::FacetPaginator.request_keys[:prefix] }
|
739
|
+
|
740
|
+
let(:blacklight_config) do
|
741
|
+
Blacklight::Configuration.new do |config|
|
742
|
+
config.add_facet_fields_to_solr_request!
|
743
|
+
config.add_facet_field 'format'
|
744
|
+
config.add_facet_field 'format_ordered', sort: :count
|
745
|
+
config.add_facet_field 'format_limited', limit: 5
|
746
|
+
config.add_facet_field 'format_more_limited', limit: 5, more_limit: 50
|
747
|
+
end
|
748
|
+
end
|
749
|
+
|
750
|
+
let(:solr_parameters) do
|
751
|
+
solr_parameters = Blacklight::Solr::Request.new
|
752
|
+
subject.facet(facet_field).add_facet_paging_to_solr(solr_parameters)
|
753
|
+
solr_parameters
|
754
|
+
end
|
755
|
+
|
756
|
+
it 'sets rows to 0' do
|
757
|
+
expect(solr_parameters[:rows]).to eq 0
|
758
|
+
end
|
759
|
+
|
760
|
+
it 'sets facets requested to facet_field argument' do
|
761
|
+
expect(solr_parameters[:'facet.field']).to eq facet_field
|
762
|
+
end
|
763
|
+
|
764
|
+
it 'defaults offset to 0' do
|
765
|
+
expect(solr_parameters[:"f.#{facet_field}.facet.offset"]).to eq 0
|
766
|
+
end
|
767
|
+
|
768
|
+
context 'when offset is manually set' do
|
769
|
+
let(:user_params) { { page_key => 2 } }
|
770
|
+
|
771
|
+
it 'uses offset manually set, and converts it to an integer' do
|
772
|
+
expect(solr_parameters[:"f.#{facet_field}.facet.offset"]).to eq 20
|
773
|
+
end
|
774
|
+
end
|
775
|
+
|
776
|
+
context 'for a field with a configured more_limit' do
|
777
|
+
let(:facet_field) { 'format_more_limited' }
|
778
|
+
|
779
|
+
it 'uses the more_limit configuration' do
|
780
|
+
expect(solr_parameters[:"f.#{facet_field}.facet.limit"]).to eq 51
|
781
|
+
end
|
782
|
+
end
|
783
|
+
|
784
|
+
context 'for a field with a param key different from the field name' do
|
785
|
+
let(:user_params) { { page_key => 2, 'facet.sort': 'index', 'facet.prefix': 'x' } }
|
786
|
+
let(:facet_field) { 'param_key' }
|
787
|
+
|
788
|
+
let(:blacklight_config) do
|
789
|
+
Blacklight::Configuration.new.tap do |config|
|
790
|
+
config.add_facet_field key: 'param_key', field: 'solr_field', more_limit: 50, ex: 'other'
|
791
|
+
|
792
|
+
config.add_facet_fields_to_solr_request!
|
793
|
+
end
|
794
|
+
end
|
795
|
+
|
796
|
+
it "uses the configured solr field name in queries" do
|
797
|
+
expect(solr_parameters).to include 'f.solr_field.facet.limit': 51,
|
798
|
+
'f.solr_field.facet.offset': 50,
|
799
|
+
'f.solr_field.facet.sort': 'index',
|
800
|
+
'f.solr_field.facet.prefix': 'x',
|
801
|
+
'facet.field': '{!ex=other}solr_field'
|
802
|
+
end
|
803
|
+
end
|
804
|
+
|
805
|
+
it 'defaults limit to 20' do
|
806
|
+
expect(solr_parameters[:"f.#{facet_field}.facet.limit"]).to eq 21
|
807
|
+
end
|
808
|
+
|
809
|
+
it 'uses the default sort' do
|
810
|
+
expect(solr_parameters[:"f.#{facet_field}.facet.sort"]).to be_blank
|
811
|
+
end
|
812
|
+
|
813
|
+
context 'when sort is provided' do
|
814
|
+
let(:user_params) { { sort_key => 'index' } }
|
815
|
+
|
816
|
+
it 'uses sort provided in the parameters' do
|
817
|
+
expect(solr_parameters[:"f.#{facet_field}.facet.sort"]).to eq 'index'
|
818
|
+
end
|
819
|
+
end
|
820
|
+
|
821
|
+
context 'when a prefix is provided' do
|
822
|
+
let(:user_params) { { prefix_key => 'A' } }
|
823
|
+
|
824
|
+
it 'includes the prefix in the query' do
|
825
|
+
expect(solr_parameters[:"f.#{facet_field}.facet.prefix"]).to eq 'A'
|
826
|
+
end
|
827
|
+
end
|
828
|
+
end
|
829
|
+
|
830
|
+
describe "#add_facet_suggestion_parameters" do
|
831
|
+
it "does not add anything when the builder has no facet_suggestion_query and no facet" do
|
832
|
+
expect(subject.facet).to be_nil
|
833
|
+
expect(subject.facet_suggestion_query).to be_nil
|
834
|
+
solr_params = Blacklight::Solr::Request.new
|
835
|
+
|
836
|
+
expect do
|
837
|
+
subject.add_facet_suggestion_parameters(solr_params)
|
838
|
+
end.not_to(change { solr_params })
|
839
|
+
end
|
840
|
+
|
841
|
+
it "does not add anything when the builder has a facet_suggestion_query but no facet" do
|
842
|
+
subject.facet_suggestion_query = 'artic'
|
843
|
+
expect(subject.facet_suggestion_query).to eq 'artic'
|
844
|
+
expect(subject.facet).to be_nil
|
845
|
+
solr_params = Blacklight::Solr::Request.new
|
846
|
+
|
847
|
+
expect do
|
848
|
+
subject.add_facet_suggestion_parameters(solr_params)
|
849
|
+
end.not_to(change { solr_params })
|
850
|
+
end
|
851
|
+
|
852
|
+
it "does not add anything when the builder has a facet but no facet_suggestion_query" do
|
853
|
+
subject.facet = 'subject_facet'
|
854
|
+
expect(subject.facet_suggestion_query).to be_nil
|
855
|
+
expect(subject.facet).to eq 'subject_facet'
|
856
|
+
solr_params = Blacklight::Solr::Request.new
|
857
|
+
|
858
|
+
expect do
|
859
|
+
subject.add_facet_suggestion_parameters(solr_params)
|
860
|
+
end.not_to(change { solr_params })
|
861
|
+
end
|
862
|
+
|
863
|
+
it "adds the facet_suggestion_query to facet.contains" do
|
864
|
+
subject.facet = 'subject_facet'
|
865
|
+
subject.facet_suggestion_query = 'artic'
|
866
|
+
solr_params = Blacklight::Solr::Request.new
|
867
|
+
|
868
|
+
subject.add_facet_suggestion_parameters(solr_params)
|
869
|
+
|
870
|
+
expect(solr_params[:'facet.contains']).to eq 'artic'
|
871
|
+
end
|
872
|
+
|
873
|
+
it "adds the first part of facet_suggestion_query to facet.contains if it is extremely long" do
|
874
|
+
subject.facet = 'subject_facet'
|
875
|
+
subject.facet_suggestion_query = 'Call me Ishmael. Some years ago—never mind how long precisely'
|
876
|
+
solr_params = Blacklight::Solr::Request.new
|
877
|
+
|
878
|
+
subject.add_facet_suggestion_parameters(solr_params)
|
879
|
+
|
880
|
+
expect(solr_params[:'facet.contains']).to eq 'Call me Ishmael. Some years ago—never mind how long'
|
881
|
+
end
|
882
|
+
|
883
|
+
it "adds facet.contains.ignoreCase" do
|
884
|
+
subject.facet = 'subject_facet'
|
885
|
+
subject.facet_suggestion_query = 'artic'
|
886
|
+
solr_params = Blacklight::Solr::Request.new
|
887
|
+
|
888
|
+
subject.add_facet_suggestion_parameters(solr_params)
|
889
|
+
|
890
|
+
expect(solr_params[:'facet.contains.ignoreCase']).to be true
|
891
|
+
end
|
892
|
+
end
|
893
|
+
|
894
|
+
describe "#with_tag_ex" do
|
895
|
+
it "adds an !ex local parameter if the facet configuration requests it" do
|
896
|
+
expect(subject.with_ex_local_param("xyz", "some-value")).to eq "{!ex=xyz}some-value"
|
897
|
+
end
|
898
|
+
|
899
|
+
it "does not add an !ex local parameter if it isn't configured" do
|
900
|
+
expect(subject.with_ex_local_param(nil, "some-value")).to eq "some-value"
|
901
|
+
end
|
902
|
+
end
|
903
|
+
|
904
|
+
# context 'with advanced search clause parameters' do
|
905
|
+
# before do
|
906
|
+
# blacklight_config.search_fields.each_value do |v|
|
907
|
+
# v.clause_params = { edismax: v.solr_parameters.dup }
|
908
|
+
# end
|
909
|
+
# end
|
910
|
+
|
911
|
+
# let(:user_params) { { op: 'must', clause: { '0': { field: 'title', query: 'the book' }, '1': { field: 'author', query: 'the person' } } } }
|
912
|
+
|
913
|
+
# it "has proper solr parameters" do
|
914
|
+
# expect(subject.to_hash.with_indifferent_access.dig(:json, :query, :bool, :must, 0, :edismax, :query)).to eq 'the book'
|
915
|
+
# expect(subject.to_hash.with_indifferent_access.dig(:json, :query, :bool, :must, 0, :edismax, :qf)).to eq '${title_qf}'
|
916
|
+
# expect(subject.to_hash.with_indifferent_access.dig(:json, :query, :bool, :must, 1, :edismax, :query)).to eq 'the person'
|
917
|
+
# expect(subject.to_hash.with_indifferent_access.dig(:json, :query, :bool, :must, 1, :edismax, :qf)).to eq '${author_qf}'
|
918
|
+
# end
|
919
|
+
# end
|
920
|
+
|
921
|
+
# describe '#where' do
|
922
|
+
# let(:user_params) { {} }
|
923
|
+
|
924
|
+
# it 'adds additional query filters on the search' do
|
925
|
+
# subject.where(id: [1, 2, 3])
|
926
|
+
# expect(subject.to_hash).to include q: '{!lucene}id:(1 OR 2 OR 3)'
|
927
|
+
# end
|
928
|
+
# end
|
929
|
+
end
|