blacklight 5.1.1 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight/search_context.js +38 -24
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +49 -70
- data/app/helpers/blacklight/catalog_helper_behavior.rb +1 -8
- data/app/helpers/blacklight/configuration_helper_behavior.rb +10 -2
- data/app/helpers/blacklight/facets_helper_behavior.rb +4 -1
- data/app/helpers/blacklight/search_history_constraints_helper_behavior.rb +2 -2
- data/app/helpers/blacklight/url_helper_behavior.rb +41 -7
- data/app/views/catalog/_facet_layout.html.erb +2 -2
- data/app/views/catalog/_per_page_widget.html.erb +4 -4
- data/app/views/catalog/_previous_next_doc.html.erb +1 -1
- data/app/views/catalog/_show_tools.html.erb +1 -1
- data/app/views/catalog/show.html.erb +1 -1
- data/app/views/layouts/blacklight.html.erb +1 -1
- data/blacklight.gemspec +1 -1
- data/config/jetty.yml +3 -0
- data/config/locales/blacklight.es.yml +220 -0
- data/gemfiles/rails4.1.gemfile +10 -0
- data/lib/blacklight/base.rb +1 -1
- data/lib/blacklight/catalog/search_context.rb +15 -15
- data/lib/blacklight/catalog.rb +19 -6
- data/lib/blacklight/configuration.rb +126 -31
- data/lib/blacklight/document_presenter.rb +168 -0
- data/lib/blacklight/request_builders.rb +288 -0
- data/lib/blacklight/routes.rb +6 -2
- data/lib/blacklight/solr/request.rb +1 -1
- data/lib/blacklight/solr_helper.rb +50 -323
- data/lib/blacklight/solr_response/facets.rb +7 -3
- data/lib/blacklight/utils.rb +39 -7
- data/lib/blacklight.rb +5 -3
- data/lib/generators/blacklight/install_generator.rb +17 -5
- data/lib/generators/blacklight/models_generator.rb +0 -1
- data/lib/generators/blacklight/templates/catalog_controller.rb +6 -0
- data/lib/generators/blacklight/templates/config/jetty.yml +8 -4
- data/lib/generators/blacklight/templates/config/solr.yml +2 -0
- data/spec/controllers/catalog_controller_spec.rb +41 -22
- data/spec/features/alternate_controller_spec.rb +1 -1
- data/spec/features/search_filters_spec.rb +24 -24
- data/spec/features/search_results_spec.rb +9 -4
- data/spec/features/search_sort_spec.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +87 -0
- data/spec/helpers/catalog_helper_spec.rb +5 -10
- data/spec/helpers/configuration_helper_spec.rb +22 -1
- data/spec/helpers/facets_helper_spec.rb +6 -0
- data/spec/helpers/render_constraints_helper_spec.rb +1 -2
- data/spec/helpers/url_helper_spec.rb +45 -2
- data/spec/lib/blacklight/routes_spec.rb +4 -4
- data/spec/lib/blacklight/solr_helper_spec.rb +364 -253
- data/spec/lib/blacklight/solr_response/facets_spec.rb +82 -0
- data/spec/lib/blacklight/solr_response_spec.rb +3 -1
- data/spec/lib/document_presenter_spec.rb +216 -0
- data/spec/lib/utils_spec.rb +8 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -1
- data/spec/views/catalog/index.html.erb_spec.rb +29 -21
- data/spec/views/catalog/show.html.erb_spec.rb +11 -7
- data/template.demo.rb +20 -0
- metadata +12 -4
- data/lib/generators/blacklight/jetty_generator.rb +0 -70
@@ -9,24 +9,36 @@ require 'spec_helper'
|
|
9
9
|
# to talk with solr and get results)? when we do a document request, does
|
10
10
|
# blacklight code get a single document returned?)
|
11
11
|
#
|
12
|
-
describe
|
12
|
+
describe Blacklight::SolrHelper do
|
13
13
|
|
14
14
|
# SolrHelper is a controller layer mixin, which depends
|
15
15
|
# on being mixed into a class which has #params (from Rails)
|
16
16
|
# and #blacklight_config
|
17
|
-
|
18
|
-
|
19
|
-
end
|
17
|
+
class SolrHelperTestClass
|
18
|
+
include Blacklight::SolrHelper
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
attr_accessor :blacklight_config
|
21
|
+
attr_accessor :blacklight_solr
|
22
|
+
|
23
|
+
def initialize blacklight_config, blacklight_solr
|
24
|
+
self.blacklight_config = blacklight_config
|
25
|
+
self.blacklight_solr = blacklight_solr
|
26
|
+
end
|
27
|
+
|
28
|
+
def params
|
29
|
+
{}
|
30
|
+
end
|
31
|
+
|
32
|
+
def logger
|
33
|
+
Rails.logger
|
34
|
+
end
|
27
35
|
end
|
28
36
|
|
29
|
-
|
37
|
+
subject { SolrHelperTestClass.new blacklight_config, blacklight_solr }
|
38
|
+
|
39
|
+
let(:blacklight_config) { Blacklight::Configuration.new }
|
40
|
+
let(:copy_of_catalog_config) { ::CatalogController.blacklight_config.deep_copy }
|
41
|
+
let(:blacklight_solr) { Blacklight.solr }
|
30
42
|
|
31
43
|
before(:each) do
|
32
44
|
@all_docs_query = ''
|
@@ -40,32 +52,92 @@ describe 'Blacklight::SolrHelper' do
|
|
40
52
|
@subject_search_params = {:commit=>"search", :search_field=>"subject", :action=>"index", :"controller"=>"catalog", :"rows"=>"10", :"q"=>"wome"}
|
41
53
|
end
|
42
54
|
|
55
|
+
describe "#find" do
|
56
|
+
it "should use the configured solr path" do
|
57
|
+
blacklight_config.solr_path = 'xyz'
|
58
|
+
blacklight_solr.should_receive(:send_and_receive).with('xyz', anything).and_return("{}".to_json)
|
59
|
+
expect(subject.find({})).to be_a_kind_of Blacklight::SolrResponse
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should override the configured solr path" do
|
63
|
+
blacklight_config.solr_path = 'xyz'
|
64
|
+
blacklight_solr.should_receive(:send_and_receive).with('abc', anything).and_return("{}".to_json)
|
65
|
+
expect(subject.find('abc', {})).to be_a_kind_of Blacklight::SolrResponse
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should use a default :qt param" do
|
69
|
+
blacklight_config.qt = 'xyz'
|
70
|
+
blacklight_solr.should_receive(:send_and_receive).with('select', hash_including(params: { qt: 'xyz'})).and_return("{}".to_json)
|
71
|
+
expect(subject.find({})).to be_a_kind_of Blacklight::SolrResponse
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should use the provided :qt param" do
|
75
|
+
blacklight_config.qt = 'xyz'
|
76
|
+
blacklight_solr.should_receive(:send_and_receive).with('select', hash_including(params: { qt: 'abc'})).and_return("{}".to_json)
|
77
|
+
expect(subject.find({qt: 'abc'})).to be_a_kind_of Blacklight::SolrResponse
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "http_method configuration" do
|
81
|
+
describe "using default" do
|
82
|
+
|
83
|
+
it "defaults to get" do
|
84
|
+
expect(blacklight_config.http_method).to eq :get
|
85
|
+
blacklight_solr.should_receive(:send_and_receive) do |path, params|
|
86
|
+
expect(path).to eq 'select'
|
87
|
+
expect(params[:method]).to eq :get
|
88
|
+
expect(params[:params]).to include(:q)
|
89
|
+
end.and_return({'response'=>{'docs'=>[]}})
|
90
|
+
subject.find(:q => @all_docs_query)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "setting to post" do
|
95
|
+
let (:blacklight_config) {config = Blacklight::Configuration.new; config.http_method=:post; config}
|
96
|
+
|
97
|
+
it "keep value set to post" do
|
98
|
+
expect(blacklight_config.http_method).to eq :post
|
99
|
+
blacklight_solr.should_receive(:send_and_receive) do |path, params|
|
100
|
+
expect(path).to eq 'select'
|
101
|
+
expect(params[:method]).to eq :post
|
102
|
+
expect(params[:data]).to include(:q)
|
103
|
+
end.and_return({'response'=>{'docs'=>[]}})
|
104
|
+
subject.find(:q => @all_docs_query)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
43
109
|
|
110
|
+
describe "http_method configuration", :integration => true do
|
111
|
+
let (:blacklight_config) {config = Blacklight::Configuration.new; config.http_method=:post; config}
|
112
|
+
|
113
|
+
it "should send a post request to solr and get a response back" do
|
114
|
+
response = subject.find(:q => @all_docs_query)
|
115
|
+
expect(response.docs.length).to be >= 1
|
116
|
+
end
|
117
|
+
end
|
44
118
|
|
45
119
|
# SPECS for actual search parameter generation
|
46
120
|
describe "solr_search_params" do
|
47
121
|
it "allows customization of solr_search_params_logic" do
|
48
122
|
# Normally you'd include a new module into (eg) your CatalogController
|
49
123
|
# but a sub-class defininig it directly is simpler for test.
|
50
|
-
|
124
|
+
subject.stub(:add_foo_to_solr_params) do |solr_params, user_params|
|
51
125
|
solr_params[:wt] = "TESTING"
|
52
126
|
end
|
53
|
-
|
54
127
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
expect(self.solr_search_params[:wt]).to eq "TESTING"
|
128
|
+
subject.solr_search_params_logic += [:add_foo_to_solr_params]
|
129
|
+
|
130
|
+
expect(subject.solr_search_params[:wt]).to eq "TESTING"
|
59
131
|
end
|
60
132
|
|
61
133
|
|
62
134
|
describe 'for an entirely empty search' do
|
63
|
-
def params
|
64
|
-
{}
|
65
|
-
end
|
66
135
|
before do
|
67
|
-
@produced_params =
|
136
|
+
@produced_params = subject.solr_search_params.with_indifferent_access
|
68
137
|
end
|
138
|
+
|
139
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
140
|
+
|
69
141
|
it 'should not have a q param' do
|
70
142
|
expect(@produced_params[:q]).to be_nil
|
71
143
|
expect(@produced_params["spellcheck.q"]).to be_nil
|
@@ -75,7 +147,7 @@ describe 'Blacklight::SolrHelper' do
|
|
75
147
|
end
|
76
148
|
it 'should have default facet fields' do
|
77
149
|
# remove local params from the facet.field
|
78
|
-
expect(@produced_params[:"facet.field"].map { |x| x.gsub(/\{![^}]+\}/, '') }).to
|
150
|
+
expect(@produced_params[:"facet.field"].map { |x| x.gsub(/\{![^}]+\}/, '') }).to match_array ["format", "subject_topic_facet", "pub_date", "language_facet", "lc_1letter_facet", "subject_geo_facet", "subject_era_facet"]
|
79
151
|
end
|
80
152
|
|
81
153
|
it "should have default qt" do
|
@@ -90,7 +162,7 @@ describe 'Blacklight::SolrHelper' do
|
|
90
162
|
|
91
163
|
describe "for an empty string search" do
|
92
164
|
it "should return empty string q in solr parameters" do
|
93
|
-
solr_params = solr_search_params(:q => "")
|
165
|
+
solr_params = subject.solr_search_params(:q => "")
|
94
166
|
expect(solr_params[:q]).to eq ""
|
95
167
|
expect(solr_params["spellcheck.q"]).to eq ""
|
96
168
|
end
|
@@ -98,7 +170,7 @@ describe 'Blacklight::SolrHelper' do
|
|
98
170
|
|
99
171
|
describe "for request params also passed in as argument" do
|
100
172
|
it "should only have one value for the key 'q' regardless if a symbol or string" do
|
101
|
-
solr_params = solr_search_params( :q => "some query", 'q' => 'another value' )
|
173
|
+
solr_params = subject.solr_search_params( :q => "some query", 'q' => 'another value' )
|
102
174
|
expect(solr_params[:q]).to eq 'some query'
|
103
175
|
expect(solr_params['q']).to eq 'some query'
|
104
176
|
end
|
@@ -108,7 +180,7 @@ describe 'Blacklight::SolrHelper' do
|
|
108
180
|
describe "for one facet, no query" do
|
109
181
|
it "should have proper solr parameters" do
|
110
182
|
|
111
|
-
solr_params = solr_search_params(:f => @single_facet)
|
183
|
+
solr_params = subject.solr_search_params(:f => @single_facet)
|
112
184
|
|
113
185
|
expect(solr_params[:q]).to be_blank
|
114
186
|
expect(solr_params["spellcheck.q"]).to be_blank
|
@@ -121,7 +193,7 @@ describe 'Blacklight::SolrHelper' do
|
|
121
193
|
|
122
194
|
describe "with Multi Facets, No Query" do
|
123
195
|
it 'should have fq set properly' do
|
124
|
-
solr_params = solr_search_params(:f => @multi_facets)
|
196
|
+
solr_params = subject.solr_search_params(:f => @multi_facets)
|
125
197
|
|
126
198
|
@multi_facets.each_pair do |facet_field, value_list|
|
127
199
|
value_list ||= []
|
@@ -136,7 +208,7 @@ describe 'Blacklight::SolrHelper' do
|
|
136
208
|
|
137
209
|
describe "with Multi Facets, Multi Word Query" do
|
138
210
|
it 'should have fq and q set properly' do
|
139
|
-
solr_params = solr_search_params(:q => @mult_word_query, :f => @multi_facets)
|
211
|
+
solr_params = subject.solr_search_params(:q => @mult_word_query, :f => @multi_facets)
|
140
212
|
|
141
213
|
@multi_facets.each_pair do |facet_field, value_list|
|
142
214
|
value_list ||= []
|
@@ -151,58 +223,55 @@ describe 'Blacklight::SolrHelper' do
|
|
151
223
|
|
152
224
|
describe "facet_value_to_fq_string" do
|
153
225
|
|
154
|
-
let :blacklight_config do
|
155
|
-
Blacklight::Configuration.new
|
156
|
-
end
|
157
|
-
|
158
226
|
it "should use the raw handler for strings" do
|
159
|
-
expect(facet_value_to_fq_string
|
227
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", "my value")).to eq "{!raw f=facet_name}my value"
|
160
228
|
end
|
161
229
|
|
162
230
|
it "should pass booleans through" do
|
163
|
-
expect(facet_value_to_fq_string
|
231
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", true)).to eq "facet_name:true"
|
164
232
|
end
|
165
233
|
|
166
234
|
it "should pass boolean-like strings through" do
|
167
|
-
expect(facet_value_to_fq_string
|
235
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", "true")).to eq "facet_name:true"
|
168
236
|
end
|
169
237
|
|
170
238
|
it "should pass integers through" do
|
171
|
-
expect(facet_value_to_fq_string
|
239
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", 1)).to eq "facet_name:1"
|
172
240
|
end
|
173
241
|
|
174
242
|
it "should pass integer-like strings through" do
|
175
|
-
expect(facet_value_to_fq_string
|
243
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", "1")).to eq "facet_name:1"
|
176
244
|
end
|
177
245
|
|
178
246
|
it "should pass floats through" do
|
179
|
-
expect(facet_value_to_fq_string
|
247
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", 1.11)).to eq "facet_name:1.11"
|
180
248
|
end
|
181
249
|
|
182
250
|
it "should pass floats through" do
|
183
|
-
expect(facet_value_to_fq_string
|
251
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", "1.11")).to eq "facet_name:1.11"
|
184
252
|
end
|
185
253
|
|
186
254
|
it "should pass date-type fields through" do
|
187
255
|
blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(double(:date => true, :query => nil, :tag => nil))
|
188
256
|
|
189
|
-
expect(facet_value_to_fq_string
|
257
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", "2012-01-01")).to eq "facet_name:2012-01-01"
|
190
258
|
end
|
191
259
|
|
192
260
|
it "should handle range requests" do
|
193
|
-
expect(facet_value_to_fq_string
|
261
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", 1..5)).to eq "facet_name:[1 TO 5]"
|
194
262
|
end
|
195
263
|
|
196
264
|
it "should add tag local parameters" do
|
197
265
|
blacklight_config.facet_fields.stub(:[]).with('facet_name').and_return(double(:query => nil, :tag => 'asdf', :date => nil))
|
198
266
|
|
199
|
-
expect(facet_value_to_fq_string
|
200
|
-
expect(facet_value_to_fq_string
|
267
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", true)).to eq "{!tag=asdf}facet_name:true"
|
268
|
+
expect(subject.send(:facet_value_to_fq_string, "facet_name", "my value")).to eq "{!raw f=facet_name tag=asdf}my value"
|
201
269
|
end
|
202
270
|
end
|
203
271
|
|
204
272
|
describe "solr parameters for a field search from config (subject)" do
|
205
|
-
let(:solr_params) { solr_search_params @subject_search_params }
|
273
|
+
let(:solr_params) { subject.solr_search_params @subject_search_params }
|
274
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
206
275
|
|
207
276
|
it "should look up qt from field definition" do
|
208
277
|
expect(solr_params[:qt]).to eq "search"
|
@@ -232,7 +301,7 @@ describe 'Blacklight::SolrHelper' do
|
|
232
301
|
expect(solr_params[:"spellcheck.dictionary"]).to eq "subject"
|
233
302
|
end
|
234
303
|
it "should add on :solr_local_parameters using Solr LocalParams style" do
|
235
|
-
params = solr_search_params( @subject_search_params )
|
304
|
+
params = subject.solr_search_params( @subject_search_params )
|
236
305
|
|
237
306
|
#q == "{!pf=$subject_pf $qf=subject_qf} wome", make sure
|
238
307
|
#the LocalParams are really there
|
@@ -245,11 +314,9 @@ describe 'Blacklight::SolrHelper' do
|
|
245
314
|
|
246
315
|
describe "overriding of qt parameter" do
|
247
316
|
it "should return the correct overriden parameter" do
|
248
|
-
|
249
|
-
super.merge(:qt => "overridden")
|
250
|
-
end
|
317
|
+
subject.stub(params: { qt: 'overridden' })
|
251
318
|
|
252
|
-
expect(solr_search_params[:qt]).to eq "overridden"
|
319
|
+
expect(subject.solr_search_params[:qt]).to eq "overridden"
|
253
320
|
end
|
254
321
|
end
|
255
322
|
|
@@ -257,7 +324,7 @@ describe 'Blacklight::SolrHelper' do
|
|
257
324
|
it "should return the correct overriden parameter" do
|
258
325
|
solr_parameters = {:fq => 'a string' }
|
259
326
|
|
260
|
-
add_facet_fq_to_solr(solr_parameters, {})
|
327
|
+
subject.add_facet_fq_to_solr(solr_parameters, {})
|
261
328
|
|
262
329
|
expect(solr_parameters[:fq]).to be_a_kind_of Array
|
263
330
|
end
|
@@ -273,17 +340,17 @@ describe 'Blacklight::SolrHelper' do
|
|
273
340
|
end
|
274
341
|
end
|
275
342
|
|
276
|
-
|
343
|
+
let(:solr_parameters) do
|
277
344
|
solr_parameters = Blacklight::Solr::Request.new
|
278
345
|
|
279
|
-
add_solr_fields_to_query(solr_parameters, {})
|
346
|
+
subject.add_solr_fields_to_query(solr_parameters, {})
|
280
347
|
|
281
348
|
solr_parameters
|
282
349
|
end
|
283
350
|
|
284
351
|
it "should add any extra solr parameters from index and show fields" do
|
285
|
-
expect(
|
286
|
-
expect(
|
352
|
+
expect(solr_parameters[:'f.an_index_field.hl.alternativeField']).to eq "field_x"
|
353
|
+
expect(solr_parameters[:'f.a_show_field.hl.alternativeField']).to eq "field_y"
|
287
354
|
end
|
288
355
|
end
|
289
356
|
|
@@ -301,12 +368,15 @@ describe 'Blacklight::SolrHelper' do
|
|
301
368
|
config
|
302
369
|
end
|
303
370
|
|
304
|
-
|
305
|
-
|
371
|
+
let(:solr_parameters) do
|
306
372
|
solr_parameters = Blacklight::Solr::Request.new
|
307
373
|
|
308
|
-
add_facetting_to_solr(solr_parameters, {})
|
374
|
+
subject.add_facetting_to_solr(solr_parameters, {})
|
309
375
|
|
376
|
+
solr_parameters
|
377
|
+
end
|
378
|
+
|
379
|
+
it "should add sort parameters" do
|
310
380
|
expect(solr_parameters[:facet]).to be_true
|
311
381
|
|
312
382
|
expect(solr_parameters[:'facet.field']).to include('test_field')
|
@@ -314,25 +384,81 @@ describe 'Blacklight::SolrHelper' do
|
|
314
384
|
end
|
315
385
|
|
316
386
|
it "should add facet exclusions" do
|
317
|
-
solr_parameters = Blacklight::Solr::Request.new
|
318
|
-
|
319
|
-
add_facetting_to_solr(solr_parameters, {})
|
320
|
-
|
321
387
|
expect(solr_parameters[:'facet.query']).to include('{!ex=xyz}some:query')
|
322
388
|
expect(solr_parameters[:'facet.pivot']).to include('{!ex=xyz}a,b')
|
323
389
|
end
|
324
390
|
|
325
391
|
it "should add any additional solr_params" do
|
326
|
-
solr_parameters
|
392
|
+
expect(solr_parameters[:'f.some-field.facet.mincount']).to eq 15
|
393
|
+
end
|
327
394
|
|
328
|
-
|
395
|
+
describe ":include_in_request" do
|
396
|
+
let(:solr_parameters) do
|
397
|
+
solr_parameters = Blacklight::Solr::Request.new
|
398
|
+
subject.add_facetting_to_solr(solr_parameters, {})
|
399
|
+
solr_parameters
|
400
|
+
end
|
329
401
|
|
330
|
-
|
402
|
+
it "should respect the include_in_request parameter" do
|
403
|
+
blacklight_config.add_facet_field 'yes_facet', include_in_request: true
|
404
|
+
blacklight_config.add_facet_field 'no_facet', include_in_request: false
|
405
|
+
|
406
|
+
expect(solr_parameters[:'facet.field']).to include('yes_facet')
|
407
|
+
expect(solr_parameters[:'facet.field']).not_to include('no_facet')
|
408
|
+
end
|
409
|
+
|
410
|
+
it "should default to including facets if add_facet_fields_to_solr_request! was called" do
|
411
|
+
blacklight_config.add_facet_field 'yes_facet'
|
412
|
+
blacklight_config.add_facet_field 'no_facet', include_in_request: false
|
413
|
+
blacklight_config.add_facet_fields_to_solr_request!
|
414
|
+
|
415
|
+
expect(solr_parameters[:'facet.field']).to include('yes_facet')
|
416
|
+
expect(solr_parameters[:'facet.field']).not_to include('no_facet')
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
describe ":add_facet_fields_to_solr_request!" do
|
421
|
+
|
422
|
+
let(:blacklight_config) do
|
423
|
+
config = Blacklight::Configuration.new
|
424
|
+
config.add_facet_field 'yes_facet', include_in_request: true
|
425
|
+
config.add_facet_field 'no_facet', include_in_request: false
|
426
|
+
config.add_facet_field 'maybe_facet'
|
427
|
+
config.add_facet_field 'another_facet'
|
428
|
+
config
|
429
|
+
end
|
430
|
+
|
431
|
+
let(:solr_parameters) do
|
432
|
+
solr_parameters = Blacklight::Solr::Request.new
|
433
|
+
subject.add_facetting_to_solr(solr_parameters, {})
|
434
|
+
solr_parameters
|
435
|
+
end
|
436
|
+
|
437
|
+
it "should add facets to the solr request" do
|
438
|
+
blacklight_config.add_facet_fields_to_solr_request!
|
439
|
+
expect(solr_parameters[:'facet.field']).to match_array ['yes_facet', 'maybe_facet', 'another_facet']
|
440
|
+
end
|
441
|
+
|
442
|
+
it "should not override field-specific configuration by default" do
|
443
|
+
blacklight_config.add_facet_fields_to_solr_request!
|
444
|
+
expect(solr_parameters[:'facet.field']).to_not include 'no_facet'
|
445
|
+
end
|
446
|
+
|
447
|
+
it "should allow white-listing facets" do
|
448
|
+
blacklight_config.add_facet_fields_to_solr_request! 'maybe_facet'
|
449
|
+
expect(solr_parameters[:'facet.field']).to include 'maybe_facet'
|
450
|
+
expect(solr_parameters[:'facet.field']).not_to include 'another_facet'
|
451
|
+
end
|
452
|
+
|
453
|
+
it "should allow white-listed facets to override any field-specific include_in_request configuration" do
|
454
|
+
blacklight_config.add_facet_fields_to_solr_request! 'no_facet'
|
455
|
+
expect(solr_parameters[:'facet.field']).to include 'no_facet'
|
456
|
+
end
|
331
457
|
end
|
332
458
|
end
|
333
459
|
|
334
460
|
describe "with a complex parameter environment" do
|
335
|
-
|
461
|
+
let(:blacklight_config) do
|
336
462
|
config = Blacklight::Configuration.new
|
337
463
|
config.add_search_field("test_field",
|
338
464
|
:display_label => "Test",
|
@@ -341,23 +467,24 @@ describe 'Blacklight::SolrHelper' do
|
|
341
467
|
)
|
342
468
|
return config
|
343
469
|
end
|
344
|
-
|
345
|
-
|
470
|
+
|
471
|
+
before do
|
472
|
+
subject.stub params: {:search_field => "test_field", :q => "test query", "facet.field" => "extra_facet"}
|
346
473
|
end
|
347
474
|
|
348
475
|
it "should merge parameters from search_field definition" do
|
349
|
-
solr_params = solr_search_params
|
476
|
+
solr_params = subject.solr_search_params
|
350
477
|
|
351
478
|
expect(solr_params[:qf]).to eq "fieldOne^2.3 fieldTwo fieldThree^0.4"
|
352
479
|
expect(solr_params[:spellcheck]).to eq 'false'
|
353
480
|
end
|
354
481
|
it "should merge empty string parameters from search_field definition" do
|
355
|
-
expect(solr_search_params[:pf]).to eq ""
|
482
|
+
expect(subject.solr_search_params[:pf]).to eq ""
|
356
483
|
end
|
357
484
|
|
358
485
|
describe "should respect proper precedence of settings, " do
|
359
486
|
before do
|
360
|
-
@produced_params = solr_search_params
|
487
|
+
@produced_params = subject.solr_search_params
|
361
488
|
end
|
362
489
|
|
363
490
|
|
@@ -385,30 +512,28 @@ describe 'Blacklight::SolrHelper' do
|
|
385
512
|
end
|
386
513
|
|
387
514
|
describe "sorting" do
|
515
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
388
516
|
|
389
517
|
it "should send the default sort parameter to solr" do
|
390
|
-
expect(solr_search_params[:sort]).to eq 'score desc, pub_date_sort desc, title_sort asc'
|
518
|
+
expect(subject.solr_search_params[:sort]).to eq 'score desc, pub_date_sort desc, title_sort asc'
|
391
519
|
end
|
392
520
|
|
393
521
|
it "should not send a sort parameter to solr if the sort value is blank" do
|
394
|
-
|
395
|
-
|
396
|
-
config.add_sort_field('', :label => 'test')
|
397
|
-
return config
|
398
|
-
end
|
522
|
+
blacklight_config.sort_fields = {}
|
523
|
+
blacklight_config.add_sort_field('', :label => 'test')
|
399
524
|
|
400
|
-
produced_params = solr_search_params
|
525
|
+
produced_params = subject.solr_search_params
|
401
526
|
expect(produced_params).not_to have_key(:sort)
|
402
527
|
end
|
403
528
|
|
404
529
|
it "should pass through user sort parameters" do
|
405
|
-
produced_params = solr_search_params( :sort => 'solr_test_field desc' )
|
530
|
+
produced_params = subject.solr_search_params( :sort => 'solr_test_field desc' )
|
406
531
|
expect(produced_params[:sort]).to eq 'solr_test_field desc'
|
407
532
|
end
|
408
533
|
end
|
409
534
|
|
410
535
|
describe "for :solr_local_parameters config" do
|
411
|
-
|
536
|
+
let(:blacklight_config) do
|
412
537
|
config = Blacklight::Configuration.new
|
413
538
|
config.add_search_field(
|
414
539
|
"custom_author_key",
|
@@ -428,12 +553,12 @@ describe 'Blacklight::SolrHelper' do
|
|
428
553
|
return config
|
429
554
|
end
|
430
555
|
|
431
|
-
|
432
|
-
{:search_field => "custom_author_key", :q => "query"}
|
556
|
+
before do
|
557
|
+
subject.stub params: {:search_field => "custom_author_key", :q => "query"}
|
433
558
|
end
|
434
559
|
|
435
560
|
before do
|
436
|
-
@result = solr_search_params
|
561
|
+
@result = subject.solr_search_params
|
437
562
|
end
|
438
563
|
|
439
564
|
it "should pass through ordinary params" do
|
@@ -450,22 +575,29 @@ describe 'Blacklight::SolrHelper' do
|
|
450
575
|
end
|
451
576
|
|
452
577
|
describe "mapping facet.field" do
|
578
|
+
let(:blacklight_config) do
|
579
|
+
Blacklight::Configuration.new do |config|
|
580
|
+
config.add_facet_field 'some_field'
|
581
|
+
config.add_facet_fields_to_solr_request!
|
582
|
+
end
|
583
|
+
end
|
584
|
+
|
453
585
|
it "should add single additional facet.field from app" do
|
454
|
-
solr_params = solr_search_params( "facet.field" => "additional_facet" )
|
586
|
+
solr_params = subject.solr_search_params( "facet.field" => "additional_facet" )
|
455
587
|
expect(solr_params[:"facet.field"]).to include("additional_facet")
|
456
|
-
expect(solr_params[:"facet.field"]).to
|
588
|
+
expect(solr_params[:"facet.field"]).to have(2).fields
|
457
589
|
end
|
458
590
|
it "should map multiple facet.field to additional facet.field" do
|
459
|
-
solr_params = solr_search_params( "facet.field" => ["add_facet1", "add_facet2"] )
|
591
|
+
solr_params = subject.solr_search_params( "facet.field" => ["add_facet1", "add_facet2"] )
|
460
592
|
expect(solr_params[:"facet.field"]).to include("add_facet1")
|
461
593
|
expect(solr_params[:"facet.field"]).to include("add_facet2")
|
462
|
-
expect(solr_params[:"facet.field"]).to
|
594
|
+
expect(solr_params[:"facet.field"]).to have(3).fields
|
463
595
|
end
|
464
596
|
it "should map facets[fields][] to additional facet.field" do
|
465
|
-
solr_params = solr_search_params( "facets" => ["add_facet1", "add_facet2"] )
|
597
|
+
solr_params = subject.solr_search_params( "facets" => ["add_facet1", "add_facet2"] )
|
466
598
|
expect(solr_params[:"facet.field"]).to include("add_facet1")
|
467
599
|
expect(solr_params[:"facet.field"]).to include("add_facet2")
|
468
|
-
expect(solr_params[:"facet.field"]).to
|
600
|
+
expect(solr_params[:"facet.field"]).to have(3).fields
|
469
601
|
end
|
470
602
|
end
|
471
603
|
|
@@ -474,11 +606,13 @@ describe 'Blacklight::SolrHelper' do
|
|
474
606
|
describe "solr_facet_params" do
|
475
607
|
before do
|
476
608
|
@facet_field = 'format'
|
477
|
-
@generated_solr_facet_params = solr_facet_params(@facet_field)
|
609
|
+
@generated_solr_facet_params = subject.solr_facet_params(@facet_field)
|
478
610
|
|
479
611
|
@sort_key = Blacklight::Solr::FacetPaginator.request_keys[:sort]
|
480
612
|
@page_key = Blacklight::Solr::FacetPaginator.request_keys[:page]
|
481
|
-
|
613
|
+
end
|
614
|
+
let(:blacklight_config) do
|
615
|
+
Blacklight::Configuration.new do |config|
|
482
616
|
config.add_facet_fields_to_solr_request!
|
483
617
|
config.add_facet_field 'format'
|
484
618
|
config.add_facet_field 'format_ordered', :sort => :count
|
@@ -486,6 +620,7 @@ describe 'Blacklight::SolrHelper' do
|
|
486
620
|
|
487
621
|
end
|
488
622
|
end
|
623
|
+
|
489
624
|
it 'sets rows to 0' do
|
490
625
|
expect(@generated_solr_facet_params[:rows]).to eq 0
|
491
626
|
end
|
@@ -496,48 +631,47 @@ describe 'Blacklight::SolrHelper' do
|
|
496
631
|
expect(@generated_solr_facet_params[:"f.#{@facet_field}.facet.offset"]).to eq 0
|
497
632
|
end
|
498
633
|
it 'uses offset manually set, and converts it to an integer' do
|
499
|
-
solr_params = solr_facet_params(@facet_field, @page_key => 2)
|
634
|
+
solr_params = subject.solr_facet_params(@facet_field, @page_key => 2)
|
500
635
|
expect(solr_params[:"f.#{@facet_field}.facet.offset"]).to eq 20
|
501
636
|
end
|
502
637
|
it 'defaults limit to 20' do
|
503
|
-
solr_params = solr_facet_params(@facet_field)
|
638
|
+
solr_params = subject.solr_facet_params(@facet_field)
|
504
639
|
expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 21
|
505
640
|
end
|
506
641
|
|
507
642
|
describe 'if facet_list_limit is defined in controller' do
|
508
|
-
|
509
|
-
1000
|
643
|
+
before do
|
644
|
+
subject.stub facet_list_limit: 1000
|
510
645
|
end
|
511
646
|
it 'uses controller method for limit' do
|
512
|
-
solr_params = solr_facet_params(@facet_field)
|
647
|
+
solr_params = subject.solr_facet_params(@facet_field)
|
513
648
|
expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 1001
|
514
649
|
end
|
515
650
|
|
516
651
|
it 'uses controller method for limit when a ordinary limit is set' do
|
517
|
-
solr_params = solr_facet_params(@facet_field)
|
652
|
+
solr_params = subject.solr_facet_params(@facet_field)
|
518
653
|
expect(solr_params[:"f.#{@facet_field}.facet.limit"]).to eq 1001
|
519
654
|
end
|
520
655
|
end
|
521
656
|
|
522
657
|
it 'uses the default sort' do
|
523
|
-
solr_params = solr_facet_params(@facet_field)
|
658
|
+
solr_params = subject.solr_facet_params(@facet_field)
|
524
659
|
expect(solr_params[:"f.#{@facet_field}.facet.sort"]).to be_blank
|
525
660
|
end
|
526
661
|
|
527
662
|
it "uses the field-specific sort" do
|
528
|
-
|
529
|
-
solr_params
|
530
|
-
expect(solr_params[:"f.#{@facet_field}.facet.sort"]).to eq :count
|
663
|
+
solr_params = subject.solr_facet_params('format_ordered')
|
664
|
+
expect(solr_params[:"f.format_ordered.facet.sort"]).to eq :count
|
531
665
|
end
|
532
666
|
|
533
667
|
it 'uses sort provided in the parameters' do
|
534
|
-
solr_params = solr_facet_params(@facet_field, @sort_key => "index")
|
668
|
+
solr_params = subject.solr_facet_params(@facet_field, @sort_key => "index")
|
535
669
|
expect(solr_params[:"f.#{@facet_field}.facet.sort"]).to eq 'index'
|
536
670
|
end
|
537
671
|
it "comes up with the same params as #solr_search_params to constrain context for facet list" do
|
538
672
|
search_params = {:q => 'tibetan history', :f=> {:format=>'Book', :language_facet=>'Tibetan'}}
|
539
|
-
solr_search_params = solr_search_params( search_params )
|
540
|
-
solr_facet_params = solr_facet_params('format', search_params)
|
673
|
+
solr_search_params = subject.solr_search_params( search_params )
|
674
|
+
solr_facet_params = subject.solr_facet_params('format', search_params)
|
541
675
|
|
542
676
|
solr_search_params.each_pair do |key, value|
|
543
677
|
# The specific params used for fetching the facet list we
|
@@ -549,15 +683,13 @@ describe 'Blacklight::SolrHelper' do
|
|
549
683
|
|
550
684
|
end
|
551
685
|
end
|
552
|
-
describe "for facet limit parameters config ed" do
|
553
|
-
|
554
|
-
{:search_field => "test_field", :q => "test query"}
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
before do
|
559
|
-
@generated_params = solr_search_params
|
686
|
+
describe "for facet limit parameters config ed" do
|
687
|
+
before do
|
688
|
+
subject.stub params: {:search_field => "test_field", :q => "test query"}
|
689
|
+
@generated_params = subject.solr_search_params
|
560
690
|
end
|
691
|
+
|
692
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
561
693
|
|
562
694
|
it "should include specifically configged facet limits +1" do
|
563
695
|
expect(@generated_params[:"f.subject_topic_facet.facet.limit"]).to eq 21
|
@@ -570,7 +702,7 @@ describe 'Blacklight::SolrHelper' do
|
|
570
702
|
|
571
703
|
describe "get_facet_pagination", :integration => true do
|
572
704
|
before(:each) do
|
573
|
-
@facet_paginator = get_facet_pagination(@facet_field)
|
705
|
+
@facet_paginator = subject.get_facet_pagination(@facet_field)
|
574
706
|
end
|
575
707
|
it 'should return a facet paginator' do
|
576
708
|
expect(@facet_paginator).to be_a_kind_of(Blacklight::Solr::FacetPaginator)
|
@@ -583,21 +715,22 @@ describe 'Blacklight::SolrHelper' do
|
|
583
715
|
# SPECS FOR SEARCH RESULTS FOR QUERY
|
584
716
|
describe 'Search Results', :integration => true do
|
585
717
|
|
718
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
586
719
|
describe 'for a sample query returning results' do
|
587
720
|
|
588
|
-
before
|
589
|
-
(@solr_response, @document_list) = get_search_results(:q => @all_docs_query)
|
721
|
+
before do
|
722
|
+
(@solr_response, @document_list) = subject.get_search_results(:q => @all_docs_query)
|
590
723
|
end
|
591
724
|
|
592
725
|
it "should use the configured request handler " do
|
593
726
|
blacklight_config.stub(:default_solr_params).and_return({:qt => 'custom_request_handler'})
|
594
727
|
blacklight_solr.should_receive(:send_and_receive) do |path, params|
|
595
728
|
expect(path).to eq 'select'
|
596
|
-
expect(params[:params][
|
597
|
-
expect(params[:params][
|
598
|
-
expect(params[:params]).to include(
|
729
|
+
expect(params[:params]['facet.field']).to eq ["format", "{!ex=pub_date_single}pub_date", "subject_topic_facet", "language_facet", "lc_1letter_facet", "subject_geo_facet", "subject_era_facet"]
|
730
|
+
expect(params[:params]["facet.query"]).to eq ["pub_date:[#{5.years.ago.year} TO *]", "pub_date:[#{10.years.ago.year} TO *]", "pub_date:[#{25.years.ago.year} TO *]"]
|
731
|
+
expect(params[:params]).to include('rows' => 10, 'qt'=>"custom_request_handler", 'q'=>"", "spellcheck.q"=>"", "f.subject_topic_facet.facet.limit"=>21, 'sort'=>"score desc, pub_date_sort desc, title_sort asc")
|
599
732
|
end.and_return({'response'=>{'docs'=>[]}})
|
600
|
-
get_search_results(:q => @all_docs_query)
|
733
|
+
subject.get_search_results(:q => @all_docs_query)
|
601
734
|
end
|
602
735
|
|
603
736
|
it 'should have a @response.docs list of the same size as @document_list' do
|
@@ -619,8 +752,8 @@ describe 'Blacklight::SolrHelper' do
|
|
619
752
|
end
|
620
753
|
|
621
754
|
describe "for a query returning a grouped response" do
|
622
|
-
before
|
623
|
-
(@solr_response, @document_list) = get_search_results({:q => @all_docs_query}, :group => true, :'group.field' => 'pub_date_sort')
|
755
|
+
before do
|
756
|
+
(@solr_response, @document_list) = subject.get_search_results({:q => @all_docs_query}, :group => true, :'group.field' => 'pub_date_sort')
|
624
757
|
end
|
625
758
|
|
626
759
|
it "should have an empty document list" do
|
@@ -633,13 +766,12 @@ describe 'Blacklight::SolrHelper' do
|
|
633
766
|
end
|
634
767
|
end
|
635
768
|
|
636
|
-
describe "for a query returning multiple groups" do
|
637
|
-
|
638
|
-
(@solr_response, @document_list) = get_search_results({:q => @all_docs_query}, :group => true, :'group.field' => ['pub_date_sort', 'title_sort'])
|
639
|
-
end
|
769
|
+
describe "for a query returning multiple groups", integration: true do
|
770
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
640
771
|
|
641
|
-
|
642
|
-
'title_sort'
|
772
|
+
before do
|
773
|
+
subject.stub grouped_key_for_results: 'title_sort'
|
774
|
+
(@solr_response, @document_list) = subject.get_search_results({:q => @all_docs_query}, :group => true, :'group.field' => ['pub_date_sort', 'title_sort'])
|
643
775
|
end
|
644
776
|
|
645
777
|
it "should have an empty document list" do
|
@@ -654,7 +786,7 @@ describe 'Blacklight::SolrHelper' do
|
|
654
786
|
|
655
787
|
describe '#query_solr' do
|
656
788
|
it 'should have results' do
|
657
|
-
solr_response = query_solr(:q => @single_word_query)
|
789
|
+
solr_response = subject.query_solr(:q => @single_word_query)
|
658
790
|
expect(solr_response.docs).to have_at_least(1).result
|
659
791
|
end
|
660
792
|
|
@@ -662,7 +794,7 @@ describe 'Blacklight::SolrHelper' do
|
|
662
794
|
|
663
795
|
describe 'for All Docs Query, No Facets' do
|
664
796
|
it 'should have non-nil values for required doc fields set in initializer' do
|
665
|
-
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
797
|
+
(solr_response, document_list) = subject.get_search_results(:q => @all_docs_query)
|
666
798
|
result_docs = document_list
|
667
799
|
document = result_docs.first
|
668
800
|
expect(document.get(blacklight_config.index.title_field)).not_to be_nil
|
@@ -675,12 +807,12 @@ describe 'Blacklight::SolrHelper' do
|
|
675
807
|
describe "Single Word Query with no Facets" do
|
676
808
|
|
677
809
|
it 'should have results' do
|
678
|
-
solr_response = query_solr(:q => @single_word_query)
|
810
|
+
solr_response = subject.query_solr(:q => @single_word_query)
|
679
811
|
expect(solr_response.docs).to have_at_least(1).result
|
680
812
|
end
|
681
813
|
|
682
814
|
it 'should have results' do
|
683
|
-
(solr_response, document_list) = get_search_results(:q => @single_word_query)
|
815
|
+
(solr_response, document_list) = subject.get_search_results(:q => @single_word_query)
|
684
816
|
expect(solr_response.docs).to have(document_list.size).results
|
685
817
|
expect(solr_response.docs).to have_at_least(1).result
|
686
818
|
end
|
@@ -689,7 +821,7 @@ describe 'Blacklight::SolrHelper' do
|
|
689
821
|
describe "Multiple Words Query with No Facets" do
|
690
822
|
it 'should have results' do
|
691
823
|
|
692
|
-
(solr_response, document_list) = get_search_results(:q => @mult_word_query)
|
824
|
+
(solr_response, document_list) = subject.get_search_results(:q => @mult_word_query)
|
693
825
|
expect(solr_response.docs).to have(document_list.size).results
|
694
826
|
expect(solr_response.docs).to have_at_least(1).result
|
695
827
|
end
|
@@ -697,7 +829,7 @@ describe 'Blacklight::SolrHelper' do
|
|
697
829
|
|
698
830
|
describe "One Facet, No Query" do
|
699
831
|
it 'should have results' do
|
700
|
-
(solr_response, document_list) = get_search_results(:f => @single_facet)
|
832
|
+
(solr_response, document_list) = subject.get_search_results(:f => @single_facet)
|
701
833
|
expect(solr_response.docs).to have(document_list.size).results
|
702
834
|
expect(solr_response.docs).to have_at_least(1).result
|
703
835
|
end
|
@@ -705,7 +837,7 @@ describe 'Blacklight::SolrHelper' do
|
|
705
837
|
|
706
838
|
describe "Mult Facets, No Query" do
|
707
839
|
it 'should have results' do
|
708
|
-
(solr_response, document_list) = get_search_results(:f => @multi_facets)
|
840
|
+
(solr_response, document_list) = subject.get_search_results(:f => @multi_facets)
|
709
841
|
expect(solr_response.docs).to have(document_list.size).results
|
710
842
|
expect(solr_response.docs).to have_at_least(1).result
|
711
843
|
end
|
@@ -713,7 +845,7 @@ describe 'Blacklight::SolrHelper' do
|
|
713
845
|
|
714
846
|
describe "Single Word Query with One Facet" do
|
715
847
|
it 'should have results' do
|
716
|
-
(solr_response, document_list) = get_search_results(:q => @single_word_query, :f => @single_facet)
|
848
|
+
(solr_response, document_list) = subject.get_search_results(:q => @single_word_query, :f => @single_facet)
|
717
849
|
expect(solr_response.docs).to have(document_list.size).results
|
718
850
|
expect(solr_response.docs).to have_at_least(1).result
|
719
851
|
end
|
@@ -721,7 +853,7 @@ describe 'Blacklight::SolrHelper' do
|
|
721
853
|
|
722
854
|
describe "Multiple Words Query with Multiple Facets" do
|
723
855
|
it 'should have results' do
|
724
|
-
(solr_response, document_list) = get_search_results(:q => @mult_word_query, :f => @multi_facets)
|
856
|
+
(solr_response, document_list) = subject.get_search_results(:q => @mult_word_query, :f => @multi_facets)
|
725
857
|
expect(solr_response.docs).to have(document_list.size).results
|
726
858
|
expect(solr_response.docs).to have_at_least(1).result
|
727
859
|
end
|
@@ -729,7 +861,7 @@ describe 'Blacklight::SolrHelper' do
|
|
729
861
|
|
730
862
|
describe "for All Docs Query and One Facet" do
|
731
863
|
it 'should have results' do
|
732
|
-
(solr_response, document_list) = get_search_results(:q => @all_docs_query, :f => @single_facet)
|
864
|
+
(solr_response, document_list) = subject.get_search_results(:q => @all_docs_query, :f => @single_facet)
|
733
865
|
expect(solr_response.docs).to have(document_list.size).results
|
734
866
|
expect(solr_response.docs).to have_at_least(1).result
|
735
867
|
end
|
@@ -739,7 +871,7 @@ describe 'Blacklight::SolrHelper' do
|
|
739
871
|
|
740
872
|
describe "for Query Without Results and No Facet" do
|
741
873
|
it 'should have no results and not raise error' do
|
742
|
-
(solr_response, document_list) = get_search_results(:q => @no_docs_query)
|
874
|
+
(solr_response, document_list) = subject.get_search_results(:q => @no_docs_query)
|
743
875
|
expect(document_list).to have(0).results
|
744
876
|
expect(solr_response.docs).to have(0).results
|
745
877
|
end
|
@@ -747,7 +879,7 @@ describe 'Blacklight::SolrHelper' do
|
|
747
879
|
|
748
880
|
describe "for Query Without Results and One Facet" do
|
749
881
|
it 'should have no results and not raise error' do
|
750
|
-
(solr_response, document_list) = get_search_results(:q => @no_docs_query, :f => @single_facet)
|
882
|
+
(solr_response, document_list) = subject.get_search_results(:q => @no_docs_query, :f => @single_facet)
|
751
883
|
expect(document_list).to have(0).results
|
752
884
|
expect(solr_response.docs).to have(0).results
|
753
885
|
end
|
@@ -755,7 +887,7 @@ describe 'Blacklight::SolrHelper' do
|
|
755
887
|
|
756
888
|
describe "for All Docs Query and Bad Facet" do
|
757
889
|
it 'should have no results and not raise error' do
|
758
|
-
(solr_response, document_list) = get_search_results(:q => @all_docs_query, :f => @bad_facet)
|
890
|
+
(solr_response, document_list) = subject.get_search_results(:q => @all_docs_query, :f => @bad_facet)
|
759
891
|
expect(document_list).to have(0).results
|
760
892
|
expect(solr_response.docs).to have(0).results
|
761
893
|
end
|
@@ -770,17 +902,21 @@ describe 'Blacklight::SolrHelper' do
|
|
770
902
|
# SPECS FOR SEARCH RESULTS FOR FACETS
|
771
903
|
describe 'Facets in Search Results for All Docs Query', :integration => true do
|
772
904
|
|
773
|
-
|
774
|
-
|
905
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
906
|
+
|
907
|
+
before do
|
908
|
+
(solr_response, document_list) = subject.get_search_results(:q => @all_docs_query)
|
775
909
|
@facets = solr_response.facets
|
776
910
|
end
|
777
911
|
|
778
912
|
it 'should have more than one facet' do
|
779
913
|
expect(@facets).to have_at_least(1).facet
|
780
914
|
end
|
781
|
-
it 'should have all facets specified in initializer' do
|
782
|
-
blacklight_config.
|
783
|
-
|
915
|
+
it 'should have all facets specified in initializer' do
|
916
|
+
fields = blacklight_config.facet_fields.reject { |k,v| v.query || v.pivot }
|
917
|
+
expect(@facets.map { |f| f.name }).to match_array fields.map { |k, v| v.field }
|
918
|
+
fields.each do |key, field|
|
919
|
+
expect(@facets.find {|f| f.name == field.field}).not_to be_nil
|
784
920
|
end
|
785
921
|
end
|
786
922
|
it 'should have at least one value for each facet' do
|
@@ -810,46 +946,47 @@ describe 'Blacklight::SolrHelper' do
|
|
810
946
|
|
811
947
|
# SPECS FOR SEARCH RESULTS FOR PAGING
|
812
948
|
describe 'Paging', :integration => true do
|
949
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
813
950
|
|
814
951
|
it 'should start with first results by default' do
|
815
|
-
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
952
|
+
(solr_response, document_list) = subject.get_search_results(:q => @all_docs_query)
|
816
953
|
expect(solr_response.params[:start].to_i).to eq 0
|
817
954
|
end
|
818
955
|
it 'should have number of results (per page) set in initializer, by default' do
|
819
|
-
(solr_response, document_list) = get_search_results(:q => @all_docs_query)
|
956
|
+
(solr_response, document_list) = subject.get_search_results(:q => @all_docs_query)
|
820
957
|
expect(solr_response.docs).to have(blacklight_config[:default_solr_params][:rows]).items
|
821
958
|
expect(document_list).to have(blacklight_config[:default_solr_params][:rows]).items
|
822
959
|
end
|
823
960
|
|
824
961
|
it 'should get number of results per page requested' do
|
825
962
|
num_results = 3 # non-default value
|
826
|
-
(solr_response1, document_list1) = get_search_results(:q => @all_docs_query, :per_page => num_results)
|
963
|
+
(solr_response1, document_list1) = subject.get_search_results(:q => @all_docs_query, :per_page => num_results)
|
827
964
|
expect(document_list1).to have(num_results).docs
|
828
965
|
expect(solr_response1.docs).to have(num_results).docs
|
829
966
|
end
|
830
967
|
|
831
968
|
it 'should get number of rows requested' do
|
832
969
|
num_results = 4 # non-default value
|
833
|
-
(solr_response1, document_list1) = get_search_results(:q => @all_docs_query, :rows => num_results)
|
970
|
+
(solr_response1, document_list1) = subject.get_search_results(:q => @all_docs_query, :rows => num_results)
|
834
971
|
expect(document_list1).to have(num_results).docs
|
835
972
|
expect(solr_response1.docs).to have(num_results).docs
|
836
973
|
end
|
837
974
|
|
838
975
|
it 'should skip appropriate number of results when requested - default per page' do
|
839
976
|
page = 3
|
840
|
-
(solr_response2, document_list2) = get_search_results(:q => @all_docs_query, :page => page)
|
977
|
+
(solr_response2, document_list2) = subject.get_search_results(:q => @all_docs_query, :page => page)
|
841
978
|
expect(solr_response2.params[:start].to_i).to eq blacklight_config[:default_solr_params][:rows] * (page-1)
|
842
979
|
end
|
843
980
|
it 'should skip appropriate number of results when requested - non-default per page' do
|
844
981
|
page = 3
|
845
982
|
num_results = 3
|
846
|
-
(solr_response2a, document_list2a) = get_search_results(:q => @all_docs_query, :per_page => num_results, :page => page)
|
983
|
+
(solr_response2a, document_list2a) = subject.get_search_results(:q => @all_docs_query, :per_page => num_results, :page => page)
|
847
984
|
expect(solr_response2a.params[:start].to_i).to eq num_results * (page-1)
|
848
985
|
end
|
849
986
|
|
850
987
|
it 'should have no results when prompted for page after last result' do
|
851
988
|
big = 5000
|
852
|
-
(solr_response3, document_list3) = get_search_results(:q => @all_docs_query, :rows => big, :page => big)
|
989
|
+
(solr_response3, document_list3) = subject.get_search_results(:q => @all_docs_query, :rows => big, :page => big)
|
853
990
|
expect(document_list3).to have(0).docs
|
854
991
|
expect(solr_response3.docs).to have(0).docs
|
855
992
|
end
|
@@ -857,12 +994,12 @@ describe 'Blacklight::SolrHelper' do
|
|
857
994
|
it 'should show first results when prompted for page before first result' do
|
858
995
|
# FIXME: should it show first results, or should it throw an error for view to deal w?
|
859
996
|
# Solr throws an error for a negative start value
|
860
|
-
(solr_response4, document_list4) = get_search_results(:q => @all_docs_query, :page => '-1')
|
997
|
+
(solr_response4, document_list4) = subject.get_search_results(:q => @all_docs_query, :page => '-1')
|
861
998
|
expect(solr_response4.params[:start].to_i).to eq 0
|
862
999
|
end
|
863
1000
|
it 'should have results available when asked for more than are in response' do
|
864
1001
|
big = 5000
|
865
|
-
(solr_response5, document_list5) = get_search_results(:q => @all_docs_query, :rows => big, :page => 1)
|
1002
|
+
(solr_response5, document_list5) = subject.get_search_results(:q => @all_docs_query, :rows => big, :page => 1)
|
866
1003
|
expect(solr_response5.docs).to have(document_list5.length).docs
|
867
1004
|
expect(solr_response5.docs).to have_at_least(1).doc
|
868
1005
|
end
|
@@ -871,22 +1008,28 @@ describe 'Blacklight::SolrHelper' do
|
|
871
1008
|
|
872
1009
|
# SPECS FOR SINGLE DOCUMENT REQUESTS
|
873
1010
|
describe 'Get Document By Id', :integration => true do
|
874
|
-
before
|
1011
|
+
before do
|
875
1012
|
@doc_id = '2007020969'
|
876
1013
|
@bad_id = "redrum"
|
877
|
-
@response2, @document = get_solr_response_for_doc_id(@doc_id)
|
1014
|
+
@response2, @document = subject.get_solr_response_for_doc_id(@doc_id)
|
878
1015
|
end
|
879
1016
|
|
880
1017
|
it "should raise Blacklight::InvalidSolrID for an unknown id" do
|
881
1018
|
expect {
|
882
|
-
get_solr_response_for_doc_id(@bad_id)
|
1019
|
+
subject.get_solr_response_for_doc_id(@bad_id)
|
883
1020
|
}.to raise_error(Blacklight::Exceptions::InvalidSolrID)
|
884
1021
|
end
|
885
1022
|
|
886
1023
|
it "should use a provided document request handler " do
|
887
1024
|
blacklight_config.stub(:document_solr_request_handler => 'document')
|
888
|
-
blacklight_solr.should_receive(:
|
889
|
-
expect { get_solr_response_for_doc_id(@doc_id)}.to raise_error Blacklight::Exceptions::InvalidSolrID
|
1025
|
+
blacklight_solr.should_receive(:send_and_receive).with('select', kind_of(Hash)).and_return({'response'=>{'docs'=>[]}})
|
1026
|
+
expect { subject.get_solr_response_for_doc_id(@doc_id)}.to raise_error Blacklight::Exceptions::InvalidSolrID
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
it "should use a provided document solr path " do
|
1030
|
+
blacklight_config.stub(:document_solr_path => 'get')
|
1031
|
+
blacklight_solr.should_receive(:send_and_receive).with('get', kind_of(Hash)).and_return({'response'=>{'docs'=>[]}})
|
1032
|
+
expect { subject.get_solr_response_for_doc_id(@doc_id)}.to raise_error Blacklight::Exceptions::InvalidSolrID
|
890
1033
|
end
|
891
1034
|
|
892
1035
|
it "should have a non-nil result for a known id" do
|
@@ -906,20 +1049,25 @@ describe 'Blacklight::SolrHelper' do
|
|
906
1049
|
|
907
1050
|
describe "solr_doc_params" do
|
908
1051
|
it "should default to using the 'document' requestHandler" do
|
909
|
-
doc_params = solr_doc_params('asdfg')
|
1052
|
+
doc_params = subject.solr_doc_params('asdfg')
|
910
1053
|
expect(doc_params[:qt]).to eq 'document'
|
911
1054
|
end
|
912
1055
|
|
1056
|
+
it "should default to using the id parameter when sending solr queries" do
|
1057
|
+
doc_params = subject.solr_doc_params('asdfg')
|
1058
|
+
expect(doc_params[:id]).to eq 'asdfg'
|
1059
|
+
end
|
913
1060
|
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
end
|
1061
|
+
it "should use the document_unique_id_param configuration" do
|
1062
|
+
blacklight_config.stub(document_unique_id_param: :ids)
|
1063
|
+
doc_params = subject.solr_doc_params('asdfg')
|
1064
|
+
expect(doc_params[:ids]).to eq 'asdfg'
|
1065
|
+
end
|
920
1066
|
|
1067
|
+
describe "blacklight config's default_document_solr_parameters" do
|
921
1068
|
it "should use parameters from the controller's default_document_solr_parameters" do
|
922
|
-
|
1069
|
+
blacklight_config.default_document_solr_params = { :qt => 'my_custom_handler', :asdf => '1234' }
|
1070
|
+
doc_params = subject.solr_doc_params('asdfg')
|
923
1071
|
expect(doc_params[:qt]).to eq 'my_custom_handler'
|
924
1072
|
expect(doc_params[:asdf]).to eq '1234'
|
925
1073
|
end
|
@@ -938,7 +1086,7 @@ describe 'Blacklight::SolrHelper' do
|
|
938
1086
|
end
|
939
1087
|
=end
|
940
1088
|
it "should respect the configuration-supplied unique id" do
|
941
|
-
doc_params = solr_doc_params('"Strong Medicine speaks"')
|
1089
|
+
doc_params = subject.solr_doc_params('"Strong Medicine speaks"')
|
942
1090
|
expect(doc_params[:id]).to eq '"Strong Medicine speaks"'
|
943
1091
|
end
|
944
1092
|
end
|
@@ -947,9 +1095,9 @@ describe 'Blacklight::SolrHelper' do
|
|
947
1095
|
|
948
1096
|
# SPECS FOR SINGLE DOCUMENT VIA SEARCH
|
949
1097
|
describe "Get Document Via Search", :integration => true do
|
950
|
-
before
|
1098
|
+
before do
|
951
1099
|
@doc_row = 3
|
952
|
-
@doc = get_single_doc_via_search(@doc_row, :q => @all_docs_query)
|
1100
|
+
@doc = subject.get_single_doc_via_search(@doc_row, :q => @all_docs_query)
|
953
1101
|
end
|
954
1102
|
=begin
|
955
1103
|
# can't test these here, because the method only returns the document
|
@@ -977,7 +1125,7 @@ describe 'Blacklight::SolrHelper' do
|
|
977
1125
|
end
|
978
1126
|
|
979
1127
|
it "should limit search result by facets when supplied" do
|
980
|
-
doc2 = get_single_doc_via_search(@doc_row , :q => @all_docs_query, :f => @multi_facets)
|
1128
|
+
doc2 = subject.get_single_doc_via_search(@doc_row , :q => @all_docs_query, :f => @multi_facets)
|
981
1129
|
expect(doc2[:id]).not_to be_nil
|
982
1130
|
end
|
983
1131
|
|
@@ -986,13 +1134,13 @@ describe 'Blacklight::SolrHelper' do
|
|
986
1134
|
# SPECS FOR SPELLING SUGGESTIONS VIA SEARCH
|
987
1135
|
describe "Searches should return spelling suggestions", :integration => true do
|
988
1136
|
it 'search results for just-poor-enough-query term should have (multiple) spelling suggestions' do
|
989
|
-
(solr_response, document_list) = get_search_results({:q => 'boo'})
|
1137
|
+
(solr_response, document_list) = subject.get_search_results({:q => 'boo'})
|
990
1138
|
expect(solr_response.spelling.words).to include('bon')
|
991
1139
|
expect(solr_response.spelling.words).to include('bod') #for multiple suggestions
|
992
1140
|
end
|
993
1141
|
|
994
1142
|
it 'search results for just-poor-enough-query term should have multiple spelling suggestions' do
|
995
|
-
(solr_response, document_list) = get_search_results({:q => 'politica'})
|
1143
|
+
(solr_response, document_list) = subject.get_search_results({:q => 'politica'})
|
996
1144
|
expect(solr_response.spelling.words).to include('policy') # less freq
|
997
1145
|
expect(solr_response.spelling.words).to include('politics') # more freq
|
998
1146
|
expect(solr_response.spelling.words).to include('political') # more freq
|
@@ -1005,17 +1153,17 @@ describe 'Blacklight::SolrHelper' do
|
|
1005
1153
|
end
|
1006
1154
|
|
1007
1155
|
it "title search results for just-poor-enough query term should have spelling suggestions" do
|
1008
|
-
(solr_response, document_list) = get_search_results({:q => 'yehudiyam', :qt => 'search', :"spellcheck.dictionary" => "title"})
|
1156
|
+
(solr_response, document_list) = subject.get_search_results({:q => 'yehudiyam', :qt => 'search', :"spellcheck.dictionary" => "title"})
|
1009
1157
|
expect(solr_response.spelling.words).to include('yehudiyim')
|
1010
1158
|
end
|
1011
1159
|
|
1012
1160
|
it "author search results for just-poor-enough-query term should have spelling suggestions" do
|
1013
|
-
(solr_response, document_list) = get_search_results({:q => 'shirma', :qt => 'search', :"spellcheck.dictionary" => "author"})
|
1161
|
+
(solr_response, document_list) = subject.get_search_results({:q => 'shirma', :qt => 'search', :"spellcheck.dictionary" => "author"})
|
1014
1162
|
expect(solr_response.spelling.words).to include('sharma')
|
1015
1163
|
end
|
1016
1164
|
|
1017
1165
|
it "subject search results for just-poor-enough-query term should have spelling suggestions" do
|
1018
|
-
(solr_response, document_list) = get_search_results({:q => 'wome', :qt => 'search', :"spellcheck.dictionary" => "subject"})
|
1166
|
+
(solr_response, document_list) = subject.get_search_results({:q => 'wome', :qt => 'search', :"spellcheck.dictionary" => "subject"})
|
1019
1167
|
expect(solr_response.spelling.words).to include('women')
|
1020
1168
|
end
|
1021
1169
|
|
@@ -1027,52 +1175,56 @@ describe 'Blacklight::SolrHelper' do
|
|
1027
1175
|
end
|
1028
1176
|
|
1029
1177
|
describe "facet_limit_for" do
|
1178
|
+
let(:blacklight_config) { copy_of_catalog_config }
|
1030
1179
|
|
1031
1180
|
it "should return specified value for facet_field specified" do
|
1032
|
-
expect(facet_limit_for("subject_topic_facet")).to eq blacklight_config.facet_fields["subject_topic_facet"].limit
|
1181
|
+
expect(subject.facet_limit_for("subject_topic_facet")).to eq blacklight_config.facet_fields["subject_topic_facet"].limit
|
1033
1182
|
end
|
1034
1183
|
it "should generate proper solr param" do
|
1035
|
-
expect(solr_search_params[:"f.subject_topic_facet.facet.limit"]).to eq 21
|
1184
|
+
expect(subject.solr_search_params[:"f.subject_topic_facet.facet.limit"]).to eq 21
|
1036
1185
|
end
|
1037
1186
|
|
1038
1187
|
it "facet_limit_hash should return hash with key being facet_field and value being configured limit" do
|
1039
1188
|
# facet_limit_hash has been removed from solrhelper in refactor. should it go back?
|
1040
1189
|
pending "facet_limit_hash has been removed from solrhelper in refactor. should it go back?"
|
1041
|
-
expect(facet_limit_hash).to eq blacklight_config[:facet][:limits]
|
1190
|
+
expect(subject.facet_limit_hash).to eq blacklight_config[:facet][:limits]
|
1042
1191
|
end
|
1043
1192
|
it "should handle no facet_limits in config" do
|
1044
|
-
|
1045
|
-
config = Blacklight::Configuration.new
|
1046
|
-
config.facet_fields = {}
|
1047
|
-
return config
|
1048
|
-
end
|
1193
|
+
blacklight_config.facet_fields = {}
|
1049
1194
|
|
1050
|
-
expect(facet_limit_for("subject_topic_facet")).to be_nil
|
1195
|
+
expect(subject.facet_limit_for("subject_topic_facet")).to be_nil
|
1051
1196
|
|
1052
|
-
expect(solr_search_params).not_to have_key(:"f.subject_topic_facet.facet.limit")
|
1197
|
+
expect(subject.solr_search_params).not_to have_key(:"f.subject_topic_facet.facet.limit")
|
1053
1198
|
|
1054
1199
|
end
|
1055
1200
|
|
1056
1201
|
describe "for 'true' configured values" do
|
1202
|
+
let(:blacklight_config) do
|
1203
|
+
config = Blacklight::Configuration.new
|
1204
|
+
config.add_facet_field "language_facet", limit: true
|
1205
|
+
config
|
1206
|
+
end
|
1057
1207
|
it "should return nil if no @response available" do
|
1058
|
-
expect(facet_limit_for("some_unknown_field")).to be_nil
|
1208
|
+
expect(subject.facet_limit_for("some_unknown_field")).to be_nil
|
1059
1209
|
end
|
1060
1210
|
it "should get from @response facet.limit if available" do
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
expect(facet_limit_for("language_facet")).to eq 10
|
1211
|
+
@response = double()
|
1212
|
+
@response.stub(:facet_by_field_name).with("language_facet").and_return(double(limit: nil))
|
1213
|
+
subject.instance_variable_set(:@response, @response)
|
1214
|
+
blacklight_config.facet_fields['language_facet'].limit = 10
|
1215
|
+
expect(subject.facet_limit_for("language_facet")).to eq 10
|
1066
1216
|
end
|
1067
|
-
it "should get from
|
1068
|
-
@response = double(
|
1069
|
-
|
1217
|
+
it "should get the limit from the facet field in @response" do
|
1218
|
+
@response = double()
|
1219
|
+
@response.stub(:facet_by_field_name).with("language_facet").and_return(double(limit: 16))
|
1220
|
+
subject.instance_variable_set(:@response, @response)
|
1221
|
+
expect(subject.facet_limit_for("language_facet")).to eq 15
|
1070
1222
|
end
|
1071
1223
|
end
|
1072
1224
|
end
|
1073
1225
|
|
1074
1226
|
describe "with max per page enforced" do
|
1075
|
-
|
1227
|
+
let(:blacklight_config) do
|
1076
1228
|
config = Blacklight::Configuration.new
|
1077
1229
|
config.max_per_page = 123
|
1078
1230
|
return config
|
@@ -1080,7 +1232,7 @@ describe 'Blacklight::SolrHelper' do
|
|
1080
1232
|
|
1081
1233
|
it "should enforce max_per_page against all parameters" do
|
1082
1234
|
expect(blacklight_config.max_per_page).to eq 123
|
1083
|
-
expect(solr_search_params(:per_page => 98765)[:rows]).to eq 123
|
1235
|
+
expect(subject.solr_search_params(:per_page => 98765)[:rows]).to eq 123
|
1084
1236
|
end
|
1085
1237
|
end
|
1086
1238
|
|
@@ -1090,18 +1242,18 @@ describe 'Blacklight::SolrHelper' do
|
|
1090
1242
|
@mock_response.stub(:docs => [])
|
1091
1243
|
end
|
1092
1244
|
it "should contruct a solr query based on the field and value pair" do
|
1093
|
-
|
1094
|
-
get_solr_response_for_field_values('field_name', 'value')
|
1245
|
+
subject.should_receive(:find).with(hash_including(:q => "field_name:(value)")).and_return(@mock_response)
|
1246
|
+
subject.get_solr_response_for_field_values('field_name', 'value')
|
1095
1247
|
end
|
1096
1248
|
|
1097
1249
|
it "should OR multiple values together" do
|
1098
|
-
|
1099
|
-
get_solr_response_for_field_values('field_name', ['a', 'b'])
|
1250
|
+
subject.should_receive(:find).with(hash_including(:q => "field_name:(a OR b)")).and_return(@mock_response)
|
1251
|
+
subject.get_solr_response_for_field_values('field_name', ['a', 'b'])
|
1100
1252
|
end
|
1101
1253
|
|
1102
1254
|
it "should escape crazy identifiers" do
|
1103
|
-
|
1104
|
-
get_solr_response_for_field_values('field_name', 'h://"\'')
|
1255
|
+
subject.should_receive(:find).with(hash_including(:q => "field_name:(\"h://\\\"\\\'\")")).and_return(@mock_response)
|
1256
|
+
subject.get_solr_response_for_field_values('field_name', 'h://"\'')
|
1105
1257
|
end
|
1106
1258
|
end
|
1107
1259
|
|
@@ -1113,100 +1265,59 @@ describe 'Blacklight::SolrHelper' do
|
|
1113
1265
|
# more like this
|
1114
1266
|
# nearby on shelf
|
1115
1267
|
it "should raise a Blacklight exception if RSolr can't connect to the Solr instance" do
|
1116
|
-
blacklight_solr.stub(:
|
1117
|
-
expect { find(:a => 123) }.to raise_exception(/Unable to connect to Solr instance/)
|
1268
|
+
blacklight_solr.stub(:send_and_receive).and_raise(Errno::ECONNREFUSED)
|
1269
|
+
expect { subject.find(:a => 123) }.to raise_exception(/Unable to connect to Solr instance/)
|
1118
1270
|
end
|
1119
1271
|
|
1120
1272
|
describe "grouped_key_for_results" do
|
1121
|
-
let :blacklight_config do
|
1122
|
-
Blacklight::Configuration.new
|
1123
|
-
end
|
1124
|
-
|
1125
1273
|
it "should pull the grouped key out of the config" do
|
1126
1274
|
blacklight_config.index.group = 'xyz'
|
1127
|
-
expect(
|
1275
|
+
expect(subject.grouped_key_for_results).to eq('xyz')
|
1128
1276
|
end
|
1129
1277
|
end
|
1130
1278
|
|
1131
1279
|
describe "#with_tag_ex" do
|
1132
1280
|
it "should add an !ex local parameter if the facet configuration requests it" do
|
1133
|
-
expect(
|
1281
|
+
expect(subject.with_ex_local_param("xyz", "some-value")).to eq "{!ex=xyz}some-value"
|
1134
1282
|
end
|
1135
1283
|
|
1136
1284
|
it "should not add an !ex local parameter if it isn't configured" do
|
1137
1285
|
mock_field = double()
|
1138
|
-
expect(
|
1286
|
+
expect(subject.with_ex_local_param(nil, "some-value")).to eq "some-value"
|
1139
1287
|
end
|
1140
1288
|
|
1141
1289
|
|
1142
1290
|
end
|
1143
1291
|
|
1144
1292
|
describe "#get_previous_and_next_documents_for_search" do
|
1145
|
-
before
|
1146
|
-
@full_response, @all_docs = get_search_results({:q => ''}, :rows => 1000)
|
1293
|
+
before do
|
1294
|
+
@full_response, @all_docs = subject.get_search_results({:q => ''}, :rows => 1000)
|
1147
1295
|
end
|
1148
1296
|
|
1149
1297
|
it "should return the previous and next documents for a search" do
|
1150
|
-
response, docs = get_previous_and_next_documents_for_search(4, :q => '')
|
1298
|
+
response, docs = subject.get_previous_and_next_documents_for_search(4, :q => '')
|
1151
1299
|
|
1152
1300
|
expect(docs.first.id).to eq @all_docs[3].id
|
1153
1301
|
expect(docs.last.id).to eq @all_docs[5].id
|
1154
1302
|
end
|
1155
1303
|
|
1156
1304
|
it "should return only the next document if the counter is 0" do
|
1157
|
-
response, docs = get_previous_and_next_documents_for_search(0, :q => '')
|
1305
|
+
response, docs = subject.get_previous_and_next_documents_for_search(0, :q => '')
|
1158
1306
|
|
1159
1307
|
expect(docs.first).to be_nil
|
1160
1308
|
expect(docs.last.id).to eq @all_docs[1].id
|
1161
1309
|
end
|
1162
1310
|
|
1163
1311
|
it "should return only the previous document if the counter is the total number of documents" do
|
1164
|
-
response, docs = get_previous_and_next_documents_for_search(@full_response.total - 1, :q => '')
|
1312
|
+
response, docs = subject.get_previous_and_next_documents_for_search(@full_response.total - 1, :q => '')
|
1165
1313
|
expect(docs.first.id).to eq @all_docs.slice(-2).id
|
1166
1314
|
expect(docs.last).to be_nil
|
1167
1315
|
end
|
1168
1316
|
|
1169
1317
|
it "should return an array of nil values if there is only one result" do
|
1170
|
-
response, docs = get_previous_and_next_documents_for_search(0, :q => 'id:2007020969')
|
1318
|
+
response, docs = subject.get_previous_and_next_documents_for_search(0, :q => 'id:2007020969')
|
1171
1319
|
expect(docs.last).to be_nil
|
1172
1320
|
expect(docs.first).to be_nil
|
1173
1321
|
end
|
1174
1322
|
end
|
1175
|
-
|
1176
|
-
describe "http_method configuration" do
|
1177
|
-
describe "using default" do
|
1178
|
-
let (:blacklight_config) {Blacklight::Configuration.new}
|
1179
|
-
|
1180
|
-
it "defaults to get" do
|
1181
|
-
expect(blacklight_config.http_method).to eq :get
|
1182
|
-
blacklight_solr.should_receive(:send_and_receive) do |path, params|
|
1183
|
-
expect(path).to eq 'select'
|
1184
|
-
expect(params[:method]).to eq :get
|
1185
|
-
expect(params[:params]).to include(:q)
|
1186
|
-
end.and_return({'response'=>{'docs'=>[]}})
|
1187
|
-
get_search_results(:q => @all_docs_query)
|
1188
|
-
end
|
1189
|
-
end
|
1190
|
-
|
1191
|
-
describe "setting to post" do
|
1192
|
-
let (:blacklight_config) {config = Blacklight::Configuration.new; config.http_method=:post; config}
|
1193
|
-
|
1194
|
-
it "keep value set to post" do
|
1195
|
-
expect(blacklight_config.http_method).to eq :post
|
1196
|
-
blacklight_solr.should_receive(:send_and_receive) do |path, params|
|
1197
|
-
expect(path).to eq 'select'
|
1198
|
-
expect(params[:method]).to eq :post
|
1199
|
-
expect(params[:data]).to include(:q)
|
1200
|
-
end.and_return({'response'=>{'docs'=>[]}})
|
1201
|
-
get_search_results(:q => @all_docs_query)
|
1202
|
-
end
|
1203
|
-
|
1204
|
-
it "should send a post request to solr", :integration => true do
|
1205
|
-
response, docs = get_search_results(:q => @all_docs_query)
|
1206
|
-
expect(docs.length).to be >= 1
|
1207
|
-
end
|
1208
|
-
end
|
1209
|
-
end
|
1210
|
-
|
1211
1323
|
end
|
1212
|
-
|