blacklight 5.11.3 → 5.12.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/VERSION +1 -1
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +2 -2
- data/app/helpers/blacklight/catalog_helper_behavior.rb +2 -4
- data/app/helpers/blacklight/facets_helper_behavior.rb +10 -6
- data/app/helpers/blacklight/url_helper_behavior.rb +1 -1
- data/app/views/bookmarks/_clear_bookmarks_widget.html.erb +1 -0
- data/app/views/bookmarks/index.html.erb +0 -1
- data/blacklight.gemspec +1 -1
- data/config/locales/blacklight.en.yml +1 -0
- data/lib/blacklight.rb +2 -1
- data/lib/blacklight/bookmarks.rb +2 -0
- data/lib/blacklight/catalog.rb +1 -1
- data/lib/blacklight/configuration.rb +8 -1
- data/lib/blacklight/configuration/fields.rb +20 -10
- data/lib/blacklight/document.rb +43 -13
- data/lib/blacklight/document_presenter.rb +8 -4
- data/lib/blacklight/facet.rb +6 -54
- data/lib/blacklight/request_builders.rb +2 -2
- data/lib/blacklight/search_builder.rb +48 -18
- data/lib/blacklight/search_helper.rb +10 -10
- data/lib/blacklight/solr.rb +1 -1
- data/lib/blacklight/solr/search_builder.rb +2 -265
- data/lib/blacklight/solr/search_builder_behavior.rb +274 -0
- data/lib/blacklight/solr_repository.rb +1 -1
- data/lib/blacklight/solr_response.rb +8 -16
- data/lib/blacklight/solr_response/facets.rb +133 -25
- data/lib/blacklight/solr_response/group_response.rb +1 -1
- data/lib/blacklight/solr_response/pagination_methods.rb +0 -17
- data/lib/generators/blacklight/install_generator.rb +6 -1
- data/lib/generators/blacklight/search_builder_generator.rb +20 -0
- data/lib/generators/blacklight/templates/search_builder.rb +3 -0
- data/lib/railties/blacklight.rake +1 -1
- data/spec/controllers/catalog_controller_spec.rb +9 -9
- data/spec/helpers/blacklight_helper_spec.rb +29 -179
- data/spec/helpers/facets_helper_spec.rb +37 -75
- data/spec/helpers/url_helper_spec.rb +1 -1
- data/spec/lib/blacklight/configuration_spec.rb +18 -1
- data/spec/lib/blacklight/document_spec.rb +62 -0
- data/spec/lib/blacklight/search_builder_spec.rb +15 -13
- data/spec/lib/blacklight/search_helper_spec.rb +15 -16
- data/spec/lib/blacklight/solr/document_spec.rb +5 -3
- data/spec/lib/blacklight/solr/search_builder_spec.rb +0 -5
- data/spec/lib/blacklight/solr_response/facets_spec.rb +144 -10
- data/spec/lib/blacklight/solr_response_spec.rb +5 -13
- data/spec/lib/document_presenter_spec.rb +23 -27
- data/spec/views/catalog/_facets.html.erb_spec.rb +1 -1
- data/spec/views/catalog/_index_default.erb_spec.rb +2 -13
- data/spec/views/catalog/_show_default.erb_spec.rb +1 -13
- metadata +10 -4
@@ -107,88 +107,15 @@ describe FacetsHelper do
|
|
107
107
|
|
108
108
|
describe "facet_by_field_name" do
|
109
109
|
it "should retrieve the facet from the response given a string" do
|
110
|
-
facet_config = double(:query => nil, field: 'a')
|
110
|
+
facet_config = double(:query => nil, field: 'a', key: 'a')
|
111
111
|
facet_field = double()
|
112
112
|
allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
113
113
|
|
114
114
|
@response = double()
|
115
|
-
allow(@response).to receive(:
|
115
|
+
allow(@response).to receive(:aggregations).and_return('a' => facet_field)
|
116
116
|
|
117
117
|
expect(helper.facet_by_field_name('a')).to eq facet_field
|
118
118
|
end
|
119
|
-
|
120
|
-
it "should also work for facet query fields" do
|
121
|
-
facet_config = double(:query => {}, key: 'a_query_facet_field')
|
122
|
-
allow(helper).to receive(:facet_configuration_for_field).with('a_query_facet_field').and_return(facet_config)
|
123
|
-
allow(helper).to receive(:create_facet_field_response_for_query_facet_field).with('a_query_facet_field', facet_config)
|
124
|
-
|
125
|
-
helper.facet_by_field_name 'a_query_facet_field'
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "query facets" do
|
129
|
-
let(:facet_config) {
|
130
|
-
double(
|
131
|
-
key: 'my_query_facet_field',
|
132
|
-
:query => {
|
133
|
-
'a_simple_query' => { :fq => 'field:search', :label => 'A Human Readable label'},
|
134
|
-
'another_query' => { :fq => 'field:different_search', :label => 'Label'},
|
135
|
-
'without_results' => { :fq => 'field:without_results', :label => 'No results for this facet'}
|
136
|
-
}
|
137
|
-
)
|
138
|
-
}
|
139
|
-
|
140
|
-
before(:each) do
|
141
|
-
allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
142
|
-
|
143
|
-
@response = double(:facet_queries => {
|
144
|
-
'field:search' => 10,
|
145
|
-
'field:different_search' => 2,
|
146
|
-
'field:not_appearing_in_the_config' => 50,
|
147
|
-
'field:without_results' => 0
|
148
|
-
})
|
149
|
-
end
|
150
|
-
|
151
|
-
it"should convert the query facets into a double RSolr FacetField" do
|
152
|
-
field = helper.facet_by_field_name('my_query_facet_field')
|
153
|
-
expect(field).to be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
154
|
-
|
155
|
-
expect(field.name).to eq'my_query_facet_field'
|
156
|
-
expect(field.items.size).to eq 2
|
157
|
-
expect(field.items.map { |x| x.value }).to_not include 'field:not_appearing_in_the_config'
|
158
|
-
|
159
|
-
facet_item = field.items.select { |x| x.value == 'a_simple_query' }.first
|
160
|
-
|
161
|
-
expect(facet_item.value).to eq 'a_simple_query'
|
162
|
-
expect(facet_item.hits).to eq 10
|
163
|
-
expect(facet_item.label).to eq 'A Human Readable label'
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "pivot facets" do
|
168
|
-
let(:facet_config) {
|
169
|
-
double(key: 'my_pivot_facet_field', pivot: ['field_a', 'field_b'])
|
170
|
-
}
|
171
|
-
|
172
|
-
before(:each) do
|
173
|
-
allow(helper).to receive(:facet_configuration_for_field).with(anything()).and_return(facet_config)
|
174
|
-
|
175
|
-
@response = double(:facet_pivot => { 'field_a,field_b' => [{:field => 'field_a', :value => 'a', :count => 10, :pivot => [{:field => 'field_b', :value => 'b', :count => 2}]}]})
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should convert the pivot facet into a double RSolr FacetField" do
|
179
|
-
field = helper.facet_by_field_name('my_pivot_facet_field')
|
180
|
-
expect(field).to be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
181
|
-
|
182
|
-
expect(field.name).to eq 'my_pivot_facet_field'
|
183
|
-
|
184
|
-
expect(field.items.size).to eq 1
|
185
|
-
|
186
|
-
expect(field.items.first).to respond_to(:items)
|
187
|
-
|
188
|
-
expect(field.items.first.items.size).to eq 1
|
189
|
-
expect(field.items.first.items.first.fq).to eq({ 'field_a' => 'a' })
|
190
|
-
end
|
191
|
-
end
|
192
119
|
end
|
193
120
|
|
194
121
|
|
@@ -320,8 +247,43 @@ describe FacetsHelper do
|
|
320
247
|
end
|
321
248
|
end
|
322
249
|
|
250
|
+
describe "facet_params" do
|
251
|
+
it "should extract the facet parameters for a field" do
|
252
|
+
allow(helper).to receive_messages(params: { f: { "some-field" => ["x"] }})
|
253
|
+
expect(helper.facet_params("some-field")).to match_array ["x"]
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should use the blacklight key to extract the right fields" do
|
257
|
+
blacklight_config.add_facet_field "some-key", field: "some-field"
|
258
|
+
allow(helper).to receive_messages(params: { f: { "some-key" => ["x"] }})
|
259
|
+
expect(helper.facet_params("some-key")).to match_array ["x"]
|
260
|
+
expect(helper.facet_params("some-field")).to match_array ["x"]
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe "facet_field_in_params?" do
|
265
|
+
it "should check if any value is selected for a given facet" do
|
266
|
+
allow(helper).to receive_messages(facet_params: ["x"])
|
267
|
+
expect(helper.facet_field_in_params?("some-facet")).to eq true
|
268
|
+
end
|
269
|
+
|
270
|
+
it "should be false if no value for facet is selected" do
|
271
|
+
allow(helper).to receive_messages(facet_params: nil)
|
272
|
+
expect(helper.facet_field_in_params?("some-facet")).to eq false
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
323
276
|
describe "facet_in_params?" do
|
277
|
+
it "should check if a particular value is set in the facet params" do
|
278
|
+
allow(helper).to receive_messages(facet_params: ["x"])
|
279
|
+
expect(helper.facet_in_params?("some-facet", "x")).to eq true
|
280
|
+
expect(helper.facet_in_params?("some-facet", "y")).to eq false
|
281
|
+
end
|
324
282
|
|
283
|
+
it "should be false if no value for facet is selected" do
|
284
|
+
allow(helper).to receive_messages(facet_params: nil)
|
285
|
+
expect(helper.facet_in_params?("some-facet", "x")).to eq false
|
286
|
+
end
|
325
287
|
end
|
326
288
|
|
327
289
|
describe "render_facet_value" do
|
@@ -273,7 +273,7 @@ describe BlacklightUrlHelper do
|
|
273
273
|
it "should accept and return a Proc" do
|
274
274
|
data = {'id'=>'123456','title_display'=>['654321'] }
|
275
275
|
@document = SolrDocument.new(data)
|
276
|
-
expect(helper.link_to_document(@document, Proc.new { |doc, opts| doc
|
276
|
+
expect(helper.link_to_document(@document, Proc.new { |doc, opts| doc[:id] + ": " + doc.first(:title_display) })).to have_selector("a", :text => '123456: 654321', :count => 1)
|
277
277
|
end
|
278
278
|
|
279
279
|
it "should return id when label is missing" do
|
@@ -207,13 +207,25 @@ describe "Blacklight::Configuration" do
|
|
207
207
|
expect { @config.add_facet_field(nil) }.to raise_error ArgumentError
|
208
208
|
end
|
209
209
|
|
210
|
-
it "should
|
210
|
+
it "should look up and match field names" do
|
211
211
|
allow(@config).to receive_messages(luke_fields: {
|
212
212
|
"some_field_facet" => {},
|
213
213
|
"another_field_facet" => {},
|
214
214
|
"a_facet_field" => {},
|
215
215
|
})
|
216
|
+
expect { |b| @config.add_facet_field match: /_facet$/, &b }.to yield_control.twice
|
217
|
+
|
218
|
+
expect(@config.facet_fields.keys).to eq ["some_field_facet", "another_field_facet"]
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should take wild-carded field names and dereference them to solr fields" do
|
222
|
+
allow(@config).to receive_messages(luke_fields: {
|
223
|
+
"some_field_facet" => {},
|
224
|
+
"another_field_facet" => {},
|
225
|
+
"a_facet_field" => {},
|
226
|
+
})
|
216
227
|
expect { |b| @config.add_facet_field "*_facet", &b }.to yield_control.twice
|
228
|
+
|
217
229
|
expect(@config.facet_fields.keys).to eq ["some_field_facet", "another_field_facet"]
|
218
230
|
end
|
219
231
|
|
@@ -275,6 +287,11 @@ describe "Blacklight::Configuration" do
|
|
275
287
|
|
276
288
|
expect(@config.index_fields.keys).to eq ["some_field_display", "another_field_display"]
|
277
289
|
end
|
290
|
+
|
291
|
+
it "should query solr and get live values for match fields", integration: true do
|
292
|
+
@config.add_index_field match: /title.+display/
|
293
|
+
expect(@config.index_fields.keys).to include "subtitle_display", "subtitle_vern_display", "title_display", "title_vern_display"
|
294
|
+
end
|
278
295
|
end
|
279
296
|
|
280
297
|
describe "add_show_field" do
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Blacklight::Document do
|
4
|
+
let(:data) { {} }
|
5
|
+
subject do
|
6
|
+
Class.new do
|
7
|
+
include Blacklight::Document
|
8
|
+
end.new(data)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#has?" do
|
12
|
+
context "without value constraints" do
|
13
|
+
it "should have the field if the field is in the data" do
|
14
|
+
data[:x] = true
|
15
|
+
expect(subject).to have_field(:x)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not have the field if the field is not in the data" do
|
19
|
+
expect(subject).not_to have_field(:x)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with regular value constraints" do
|
24
|
+
it "should have the field if the data has that value" do
|
25
|
+
data[:x] = true
|
26
|
+
expect(subject).to have_field(:x, true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not have the field if the data does not have that value" do
|
30
|
+
data[:x] = false
|
31
|
+
expect(subject).not_to have_field(:x, true)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should allow multiple value constraints" do
|
35
|
+
data[:x] = false
|
36
|
+
expect(subject).to have_field(:x, true, false)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should support multivalued fields" do
|
40
|
+
data[:x] = ["a", "b", "c"]
|
41
|
+
expect(subject).to have_field(:x, "a")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should support multivalued fields with an array of value constraints" do
|
45
|
+
data[:x] = ["a", "b", "c"]
|
46
|
+
expect(subject).to have_field(:x, "a", "d")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "with regexp value constraints" do
|
51
|
+
it "should check if the data matches the constraint" do
|
52
|
+
data[:x] = "the quick brown fox"
|
53
|
+
expect(subject).to have_field(:x, /fox/)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should support multivalued fields" do
|
57
|
+
data[:x] = ["the quick brown fox", "and the lazy dog"]
|
58
|
+
expect(subject).to have_field(:x, /fox/)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -100,31 +100,33 @@ describe Blacklight::SearchBuilder do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
describe "#rows" do
|
103
|
-
|
104
|
-
|
103
|
+
|
104
|
+
it "should be nil if no value is set" do
|
105
|
+
blacklight_config.default_per_page = nil
|
106
|
+
blacklight_config.per_page = []
|
107
|
+
expect(subject.rows).to be_nil
|
105
108
|
end
|
106
109
|
|
107
|
-
it "should
|
108
|
-
expect(subject.
|
110
|
+
it "should set the number of rows" do
|
111
|
+
expect(subject.rows(17).rows).to eq 17
|
109
112
|
end
|
110
113
|
|
111
|
-
it "should
|
112
|
-
expect(subject.
|
114
|
+
it "should be the per_page parameter" do
|
115
|
+
expect(subject.with(per_page: 5).rows).to eq 5
|
113
116
|
end
|
114
117
|
|
115
|
-
it "should
|
116
|
-
|
117
|
-
expect(subject.send(:rows)).to eq 42
|
118
|
+
it "should support the legacy 'rows' parameter" do
|
119
|
+
expect(subject.with(rows: 10).rows).to eq 10
|
118
120
|
end
|
119
121
|
|
120
|
-
it "should
|
121
|
-
blacklight_config.default_per_page =
|
122
|
-
expect(subject.
|
122
|
+
it "should be set to the configured default" do
|
123
|
+
blacklight_config.default_per_page = 42
|
124
|
+
expect(subject.rows).to eq 42
|
123
125
|
end
|
124
126
|
|
125
127
|
it "should limit the number of rows to the configured maximum" do
|
126
128
|
blacklight_config.max_per_page = 1000
|
127
|
-
expect(subject.
|
129
|
+
expect(subject.rows(1001).rows).to eq 1000
|
128
130
|
end
|
129
131
|
end
|
130
132
|
|
@@ -138,6 +138,7 @@ describe Blacklight::SearchHelper do
|
|
138
138
|
|
139
139
|
describe "get_facet_pagination", :integration => true do
|
140
140
|
before do
|
141
|
+
@facet_field = 'format'
|
141
142
|
Deprecation.silence(Blacklight::SearchHelper) do
|
142
143
|
@facet_paginator = subject.get_facet_pagination(@facet_field)
|
143
144
|
end
|
@@ -195,8 +196,8 @@ describe Blacklight::SearchHelper do
|
|
195
196
|
(solr_response, document_list) = subject.get_search_results(q: @all_docs_query)
|
196
197
|
result_docs = document_list
|
197
198
|
document = result_docs.first
|
198
|
-
expect(document.
|
199
|
-
expect(document.
|
199
|
+
expect(document.fetch(blacklight_config.index.title_field)).not_to be_nil
|
200
|
+
expect(document.fetch(blacklight_config.index.display_type_field)).not_to be_nil
|
200
201
|
end
|
201
202
|
end
|
202
203
|
|
@@ -252,8 +253,8 @@ describe Blacklight::SearchHelper do
|
|
252
253
|
(solr_response, document_list) = subject.search_results({ q: @all_docs_query }, default_method_chain)
|
253
254
|
result_docs = document_list
|
254
255
|
document = result_docs.first
|
255
|
-
expect(document.
|
256
|
-
expect(document.
|
256
|
+
expect(document.fetch(blacklight_config.index.title_field)).not_to be_nil
|
257
|
+
expect(document.fetch(blacklight_config.index.display_type_field)).not_to be_nil
|
257
258
|
end
|
258
259
|
end
|
259
260
|
|
@@ -357,27 +358,25 @@ describe Blacklight::SearchHelper do
|
|
357
358
|
|
358
359
|
before do
|
359
360
|
(solr_response, document_list) = subject.search_results({ q: @all_docs_query}, default_method_chain)
|
360
|
-
@facets = solr_response.
|
361
|
+
@facets = solr_response.aggregations
|
361
362
|
end
|
362
363
|
|
363
364
|
it 'should have more than one facet' do
|
364
365
|
expect(@facets).to have_at_least(1).facet
|
365
366
|
end
|
366
367
|
it 'should have all facets specified in initializer' do
|
367
|
-
|
368
|
-
expect(@facets.
|
369
|
-
fields.each do |key, field|
|
370
|
-
expect(@facets.find {|f| f.name == field.field}).not_to be_nil
|
371
|
-
end
|
368
|
+
expect(@facets.keys).to include *blacklight_config.facet_fields.keys
|
369
|
+
expect(@facets.none? { |k, v| v.nil? }).to eq true
|
372
370
|
end
|
371
|
+
|
373
372
|
it 'should have at least one value for each facet' do
|
374
|
-
@facets.each do |facet|
|
373
|
+
@facets.each do |key, facet|
|
375
374
|
expect(facet.items).to have_at_least(1).hit
|
376
375
|
end
|
377
376
|
end
|
378
377
|
it 'should have multiple values for at least one facet' do
|
379
378
|
has_mult_values = false
|
380
|
-
@facets.each do |facet|
|
379
|
+
@facets.each do |key, facet|
|
381
380
|
if facet.items.size > 1
|
382
381
|
has_mult_values = true
|
383
382
|
break
|
@@ -386,7 +385,7 @@ describe Blacklight::SearchHelper do
|
|
386
385
|
expect(has_mult_values).to eq true
|
387
386
|
end
|
388
387
|
it 'should have all value counts > 0' do
|
389
|
-
@facets.each do |facet|
|
388
|
+
@facets.each do |key, facet|
|
390
389
|
facet.items.each do |facet_vals|
|
391
390
|
expect(facet_vals.hits).to be > 0
|
392
391
|
end
|
@@ -503,7 +502,7 @@ describe Blacklight::SearchHelper do
|
|
503
502
|
expect(@document.id).to eq @doc_id
|
504
503
|
end
|
505
504
|
it 'should have non-nil values for required fields set in initializer' do
|
506
|
-
expect(@document.
|
505
|
+
expect(@document.fetch(blacklight_config.view_config(:show).display_type_field)).not_to be_nil
|
507
506
|
end
|
508
507
|
end
|
509
508
|
|
@@ -676,14 +675,14 @@ describe Blacklight::SearchHelper do
|
|
676
675
|
end
|
677
676
|
it "should get from @response facet.limit if available" do
|
678
677
|
@response = double()
|
679
|
-
allow(@response).to receive(:
|
678
|
+
allow(@response).to receive(:aggregations).and_return("language_facet" => double(limit: nil))
|
680
679
|
subject.instance_variable_set(:@response, @response)
|
681
680
|
blacklight_config.facet_fields['language_facet'].limit = 10
|
682
681
|
expect(subject.facet_limit_for("language_facet")).to eq 10
|
683
682
|
end
|
684
683
|
it "should get the limit from the facet field in @response" do
|
685
684
|
@response = double()
|
686
|
-
allow(@response).to receive(:
|
685
|
+
allow(@response).to receive(:aggregations).and_return("language_facet" => double(limit: 16))
|
687
686
|
subject.instance_variable_set(:@response, @response)
|
688
687
|
expect(subject.facet_limit_for("language_facet")).to eq 15
|
689
688
|
end
|
@@ -25,9 +25,11 @@ describe "Blacklight::Solr::Document" do
|
|
25
25
|
expect(doc.has?(:cat, 'elec')).not_to eq true
|
26
26
|
expect(doc.has?(:cat, 'electronics')).to eq true
|
27
27
|
|
28
|
-
expect(doc.
|
29
|
-
expect(doc.
|
30
|
-
expect(doc.
|
28
|
+
expect(doc.fetch(:cat)).to eq ['electronics', 'hard drive']
|
29
|
+
expect(doc.fetch(:xyz, nil)).to be_nil
|
30
|
+
expect(doc.fetch(:xyz, 'def')).to eq 'def'
|
31
|
+
expect(doc.fetch(:xyz) { |el| 'def' }).to eq 'def'
|
32
|
+
expect { doc.fetch(:xyz) }.to raise_exception(KeyError)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
@@ -40,7 +40,6 @@ describe Blacklight::Solr::SearchBuilder do
|
|
40
40
|
:qf => "fieldOne^2.3 fieldTwo fieldThree^0.4",
|
41
41
|
:pf => "",
|
42
42
|
:spellcheck => 'false',
|
43
|
-
:rows => "55",
|
44
43
|
:sort => "request_params_sort" }
|
45
44
|
)
|
46
45
|
end
|
@@ -62,10 +61,6 @@ describe Blacklight::Solr::SearchBuilder do
|
|
62
61
|
expect(subject[:qt]).to eq blacklight_config[:default_solr_params][:qt]
|
63
62
|
end
|
64
63
|
|
65
|
-
it "should take rows from search field definition where specified" do
|
66
|
-
expect(subject[:rows]).to eq "55"
|
67
|
-
end
|
68
|
-
|
69
64
|
it "should take q from request params" do
|
70
65
|
expect(subject[:q]).to eq "test query"
|
71
66
|
end
|
@@ -22,7 +22,32 @@ describe Blacklight::SolrResponse::Facets do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
describe "#facets" do
|
26
|
+
subject { Blacklight::SolrResponse.new({}, {}) }
|
27
|
+
let(:aggregations) { { x: 1, y: 2 } }
|
28
|
+
it "should get the aggregation values" do
|
29
|
+
allow(subject).to receive(:aggregations).and_return aggregations
|
30
|
+
|
31
|
+
Deprecation.silence(described_class) do
|
32
|
+
expect(subject.facets).to eq aggregations.values
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
25
37
|
describe "#facet_by_field_name" do
|
38
|
+
subject { Blacklight::SolrResponse.new({}, {}) }
|
39
|
+
let(:aggregations) { { x: double } }
|
40
|
+
|
41
|
+
it "should pull facets out of the aggregations" do
|
42
|
+
allow(subject).to receive(:aggregations).and_return aggregations
|
43
|
+
|
44
|
+
Deprecation.silence(described_class) do
|
45
|
+
expect(subject.facet_by_field_name(:x)).to eq aggregations[:x]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#aggregations" do
|
26
51
|
let(:facet_field) { ['my_field', []] }
|
27
52
|
let(:response_header) { { params: request_params }}
|
28
53
|
let(:request_params) { Hash.new }
|
@@ -32,16 +57,16 @@ describe Blacklight::SolrResponse::Facets do
|
|
32
57
|
it "should extract a field-specific limit value" do
|
33
58
|
request_params['f.my_field.facet.limit'] = "10"
|
34
59
|
request_params['facet.limit'] = "15"
|
35
|
-
expect(subject.
|
60
|
+
expect(subject.aggregations['my_field'].limit).to eq 10
|
36
61
|
end
|
37
62
|
|
38
63
|
it "should extract a global limit value" do
|
39
64
|
request_params['facet.limit'] = "15"
|
40
|
-
expect(subject.
|
65
|
+
expect(subject.aggregations['my_field'].limit).to eq 15
|
41
66
|
end
|
42
67
|
|
43
68
|
it "should be the solr default limit if no value is found" do
|
44
|
-
expect(subject.
|
69
|
+
expect(subject.aggregations['my_field'].limit).to eq 100
|
45
70
|
end
|
46
71
|
end
|
47
72
|
|
@@ -49,16 +74,16 @@ describe Blacklight::SolrResponse::Facets do
|
|
49
74
|
it "should extract a field-specific offset value" do
|
50
75
|
request_params['f.my_field.facet.offset'] = "10"
|
51
76
|
request_params['facet.offset'] = "15"
|
52
|
-
expect(subject.
|
77
|
+
expect(subject.aggregations['my_field'].offset).to eq 10
|
53
78
|
end
|
54
79
|
|
55
80
|
it "should extract a global offset value" do
|
56
81
|
request_params['facet.offset'] = "15"
|
57
|
-
expect(subject.
|
82
|
+
expect(subject.aggregations['my_field'].offset).to eq 15
|
58
83
|
end
|
59
84
|
|
60
85
|
it "should be nil if no value is found" do
|
61
|
-
expect(subject.
|
86
|
+
expect(subject.aggregations['my_field'].offset).to eq 0
|
62
87
|
end
|
63
88
|
end
|
64
89
|
|
@@ -66,22 +91,131 @@ describe Blacklight::SolrResponse::Facets do
|
|
66
91
|
it "should extract a field-specific sort value" do
|
67
92
|
request_params['f.my_field.facet.sort'] = "alpha"
|
68
93
|
request_params['facet.sort'] = "index"
|
69
|
-
expect(subject.
|
94
|
+
expect(subject.aggregations['my_field'].sort).to eq 'alpha'
|
70
95
|
end
|
71
96
|
|
72
97
|
it "should extract a global sort value" do
|
73
98
|
request_params['facet.sort'] = "alpha"
|
74
|
-
expect(subject.
|
99
|
+
expect(subject.aggregations['my_field'].sort).to eq 'alpha'
|
75
100
|
end
|
76
101
|
|
77
102
|
it "should default to count if no value is found and the default limit is used" do
|
78
|
-
expect(subject.
|
103
|
+
expect(subject.aggregations['my_field'].sort).to eq 'count'
|
79
104
|
end
|
80
105
|
|
81
106
|
it "should default to index if no value is found and the limit is unlimited" do
|
82
107
|
request_params['facet.limit'] = -1
|
83
|
-
expect(subject.
|
108
|
+
expect(subject.aggregations['my_field'].sort).to eq 'index'
|
84
109
|
end
|
85
110
|
end
|
86
111
|
end
|
112
|
+
|
113
|
+
context "facet.missing" do
|
114
|
+
let(:response) do
|
115
|
+
{
|
116
|
+
facet_counts: {
|
117
|
+
facet_fields: {
|
118
|
+
some_field: ['a', 1, nil, 2]
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
end
|
123
|
+
|
124
|
+
subject { Blacklight::SolrResponse.new(response, {}) }
|
125
|
+
|
126
|
+
it "should mark the facet.missing field with a human-readable label and fq" do
|
127
|
+
missing = subject.aggregations["some_field"].items.select { |i| i.value.nil? }.first
|
128
|
+
|
129
|
+
expect(missing.label).to eq "[Missing]"
|
130
|
+
expect(missing.fq).to eq "-some_field:[* TO *]"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "query facets" do
|
135
|
+
let(:facet_config) {
|
136
|
+
double(
|
137
|
+
key: 'my_query_facet_field',
|
138
|
+
:query => {
|
139
|
+
'a_simple_query' => { :fq => 'field:search', :label => 'A Human Readable label'},
|
140
|
+
'another_query' => { :fq => 'field:different_search', :label => 'Label'},
|
141
|
+
'without_results' => { :fq => 'field:without_results', :label => 'No results for this facet'}
|
142
|
+
}
|
143
|
+
)
|
144
|
+
}
|
145
|
+
|
146
|
+
let(:blacklight_config) { double(facet_fields: { 'my_query_facet_field' => facet_config } )}
|
147
|
+
|
148
|
+
let(:response) do
|
149
|
+
{
|
150
|
+
facet_counts: {
|
151
|
+
facet_queries: {
|
152
|
+
'field:search' => 10,
|
153
|
+
'field:different_search' => 2,
|
154
|
+
'field:not_appearing_in_the_config' => 50,
|
155
|
+
'field:without_results' => 0
|
156
|
+
}
|
157
|
+
}
|
158
|
+
}
|
159
|
+
end
|
160
|
+
|
161
|
+
subject { Blacklight::SolrResponse.new(response, {}, blacklight_config: blacklight_config) }
|
162
|
+
|
163
|
+
it"should convert the query facets into a double RSolr FacetField" do
|
164
|
+
field = subject.aggregations['my_query_facet_field']
|
165
|
+
|
166
|
+
expect(field).to be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
167
|
+
|
168
|
+
expect(field.name).to eq'my_query_facet_field'
|
169
|
+
expect(field.items.size).to eq 2
|
170
|
+
expect(field.items.map { |x| x.value }).to_not include 'field:not_appearing_in_the_config'
|
171
|
+
|
172
|
+
facet_item = field.items.select { |x| x.value == 'a_simple_query' }.first
|
173
|
+
|
174
|
+
expect(facet_item.value).to eq 'a_simple_query'
|
175
|
+
expect(facet_item.hits).to eq 10
|
176
|
+
expect(facet_item.label).to eq 'A Human Readable label'
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "pivot facets" do
|
181
|
+
let(:facet_config) {
|
182
|
+
double(key: 'my_pivot_facet_field', query: nil, pivot: ['field_a', 'field_b'])
|
183
|
+
}
|
184
|
+
|
185
|
+
let(:blacklight_config) { double(facet_fields: { 'my_pivot_facet_field' => facet_config } )}
|
186
|
+
|
187
|
+
let(:response) do
|
188
|
+
{
|
189
|
+
facet_counts: {
|
190
|
+
facet_pivot: {
|
191
|
+
'field_a,field_b' => [
|
192
|
+
{
|
193
|
+
field: 'field_a',
|
194
|
+
value: 'a',
|
195
|
+
count: 10,
|
196
|
+
pivot: [{field: 'field_b', value: 'b', count: 2}]
|
197
|
+
}]
|
198
|
+
}
|
199
|
+
}
|
200
|
+
}
|
201
|
+
end
|
202
|
+
|
203
|
+
subject { Blacklight::SolrResponse.new(response, {}, blacklight_config: blacklight_config) }
|
204
|
+
|
205
|
+
it "should convert the pivot facet into a double RSolr FacetField" do
|
206
|
+
field = subject.aggregations['my_pivot_facet_field']
|
207
|
+
|
208
|
+
expect(field).to be_a_kind_of Blacklight::SolrResponse::Facets::FacetField
|
209
|
+
|
210
|
+
expect(field.name).to eq 'my_pivot_facet_field'
|
211
|
+
|
212
|
+
expect(field.items.size).to eq 1
|
213
|
+
|
214
|
+
expect(field.items.first).to respond_to(:items)
|
215
|
+
|
216
|
+
expect(field.items.first.items.size).to eq 1
|
217
|
+
expect(field.items.first.items.first.fq).to eq({ 'field_a' => 'a' })
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
87
221
|
end
|