blacklight 5.9.4 → 5.10.0

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