blacklight-spotlight 0.26.1 → 0.27.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/spotlight/solr_document.rb +2 -2
- data/app/models/spotlight/blacklight_configuration.rb +2 -2
- data/app/models/spotlight/resource.rb +2 -0
- data/app/models/spotlight/solr_document_sidecar.rb +3 -0
- data/app/services/spotlight/solr_document_builder.rb +1 -1
- data/app/views/spotlight/search_configurations/_facets.html.erb +1 -0
- data/db/migrate/20160815165432_add_resource_to_solr_document_sidecar.rb +8 -0
- data/lib/spotlight/version.rb +1 -1
- data/spec/models/spotlight/blacklight_configuration_spec.rb +15 -0
- data/spec/services/spotlight/solr_document_builder_spec.rb +9 -0
- data/spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb +40 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14ae1aa0767b7c480a27e35a4a6331075b1f3702
|
4
|
+
data.tar.gz: dfa1d2438093e6b83410ec483848062973583516
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7af943f098a05fa6f82edc569cf681d9729801506ac917799ea3a09bda594800ed1b7a22db24b5bcdc0e2a2eebd191091b915b35c0aceae2914b241954fa1396
|
7
|
+
data.tar.gz: f64bf52002e9bf0c3f6ced2c1fac718368a8f6a3bd18916c4a09ffec164212fb4d54e252f06af00dc59fe5da72b930a90956a3ec7395c4e93ed57a7ee8b64cb7
|
@@ -24,9 +24,9 @@ module Spotlight
|
|
24
24
|
##
|
25
25
|
# Class-level methods
|
26
26
|
module ClassMethods
|
27
|
-
def build_for_exhibit(id, exhibit)
|
27
|
+
def build_for_exhibit(id, exhibit, attributes = {})
|
28
28
|
new(unique_key => id) do |doc|
|
29
|
-
doc.sidecar(exhibit).save! # save is a nop if the sidecar isn't modified.
|
29
|
+
doc.sidecar(exhibit).tap { |x| x.assign_attributes(attributes) }.save! # save is a nop if the sidecar isn't modified.
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -193,7 +193,7 @@ module Spotlight
|
|
193
193
|
def custom_index_fields
|
194
194
|
Hash[exhibit.custom_fields.map do |x|
|
195
195
|
field = Blacklight::Configuration::IndexField.new x.configuration.merge(
|
196
|
-
key: x.field, field: x.solr_field
|
196
|
+
key: x.field, field: x.solr_field, custom_field: true
|
197
197
|
)
|
198
198
|
[x.field, field]
|
199
199
|
end]
|
@@ -202,7 +202,7 @@ module Spotlight
|
|
202
202
|
def custom_facet_fields
|
203
203
|
Hash[exhibit.custom_fields.vocab.map do |x|
|
204
204
|
field = Blacklight::Configuration::FacetField.new x.configuration.merge(
|
205
|
-
key: x.field, field: x.solr_field, show: false
|
205
|
+
key: x.field, field: x.solr_field, show: false, custom_field: true
|
206
206
|
)
|
207
207
|
[x.field, field]
|
208
208
|
end]
|
@@ -3,9 +3,12 @@ module Spotlight
|
|
3
3
|
# Exhibit-specific metadata for indexed documents
|
4
4
|
class SolrDocumentSidecar < ActiveRecord::Base
|
5
5
|
belongs_to :exhibit, required: true
|
6
|
+
belongs_to :resource
|
6
7
|
belongs_to :document, required: true, polymorphic: true
|
7
8
|
serialize :data, Hash
|
8
9
|
|
10
|
+
store :data, accessors: [:index_status]
|
11
|
+
|
9
12
|
delegate :has_key?, :key?, to: :data
|
10
13
|
|
11
14
|
def to_solr
|
@@ -51,7 +51,7 @@ module Spotlight
|
|
51
51
|
# @returns [#to_solr] something that responds to `to_solr'
|
52
52
|
def exhibit_solr_doc(id)
|
53
53
|
return NilSolrDocument unless document_model || id.present?
|
54
|
-
document_model.build_for_exhibit(id, exhibit)
|
54
|
+
document_model.build_for_exhibit(id, exhibit, resource: resource)
|
55
55
|
end
|
56
56
|
|
57
57
|
def unique_key
|
@@ -4,6 +4,7 @@
|
|
4
4
|
<%= f.fields_for :facet_fields do |idxf| %>
|
5
5
|
<% @blacklight_configuration.blacklight_config.facet_fields.each do |key, config| %>
|
6
6
|
<% metadata = @field_metadata.field(key) %>
|
7
|
+
<% next unless metadata[:document_count] > 0 || config.custom_field %>
|
7
8
|
<li class="dd-item" data-id="<%= key.parameterize %>">
|
8
9
|
<div class="dd-handle dd3-handle"><%= t :drag %></div>
|
9
10
|
<%= idxf.fields_for key do |facet| %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class AddResourceToSolrDocumentSidecar < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :spotlight_solr_document_sidecars, :resource_id, :integer
|
4
|
+
add_column :spotlight_solr_document_sidecars, :resource_type, :string
|
5
|
+
|
6
|
+
add_index :spotlight_solr_document_sidecars, [:resource_type, :resource_id], name: 'spotlight_solr_document_sidecars_resource'
|
7
|
+
end
|
8
|
+
end
|
data/lib/spotlight/version.rb
CHANGED
@@ -457,6 +457,20 @@ describe Spotlight::BlacklightConfiguration, type: :model do
|
|
457
457
|
end
|
458
458
|
end
|
459
459
|
|
460
|
+
describe '#custom_facet_fields' do
|
461
|
+
it 'converts exhibit-specific fields to Blacklight configurations' do
|
462
|
+
allow(subject.exhibit).to receive_message_chain(:custom_fields, vocab: [
|
463
|
+
stub_model(Spotlight::CustomField, field: 'abc', configuration: { a: 1 }, exhibit: subject.exhibit),
|
464
|
+
stub_model(Spotlight::CustomField, field: 'xyz', configuration: { x: 2 }, exhibit: subject.exhibit)
|
465
|
+
])
|
466
|
+
|
467
|
+
expect(subject.custom_facet_fields).to include 'abc', 'xyz'
|
468
|
+
expect(subject.custom_facet_fields['abc']).to be_a_kind_of Blacklight::Configuration::Field
|
469
|
+
expect(subject.custom_facet_fields['abc'].a).to eq 1
|
470
|
+
expect(subject.custom_facet_fields['abc'].custom_field).to eq true
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
460
474
|
describe '#custom_index_fields' do
|
461
475
|
it 'converts exhibit-specific fields to Blacklight configurations' do
|
462
476
|
allow(subject.exhibit).to receive_messages(custom_fields: [
|
@@ -467,6 +481,7 @@ describe Spotlight::BlacklightConfiguration, type: :model do
|
|
467
481
|
expect(subject.custom_index_fields).to include 'abc', 'xyz'
|
468
482
|
expect(subject.custom_index_fields['abc']).to be_a_kind_of Blacklight::Configuration::Field
|
469
483
|
expect(subject.custom_index_fields['abc'].a).to eq 1
|
484
|
+
expect(subject.custom_index_fields['abc'].custom_field).to eq true
|
470
485
|
end
|
471
486
|
end
|
472
487
|
|
@@ -34,6 +34,15 @@ describe Spotlight::SolrDocumentBuilder do
|
|
34
34
|
expect(result).to include "spotlight_exhibit_slug_#{resource.exhibit.slug}_bsi"
|
35
35
|
expect(result).to include "spotlight_exhibit_slug_#{resource_alt.exhibit.slug}_bsi"
|
36
36
|
end
|
37
|
+
|
38
|
+
it 'creates a sidecar resource for the document' do
|
39
|
+
resource.document_builder.documents_to_index.first
|
40
|
+
|
41
|
+
expect(Spotlight::SolrDocumentSidecar.where(document_id: 'abc123', document_type: SolrDocument).size).to eq 2
|
42
|
+
sidecar = resource.solr_document_sidecars.find_by(document_id: 'abc123', document_type: SolrDocument)
|
43
|
+
expect(sidecar.exhibit).to eq resource.exhibit
|
44
|
+
expect(sidecar.resource).to eq resource
|
45
|
+
end
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
describe 'spotlight/search_configurations/_facets', type: :view do
|
2
|
+
let(:exhibit) { FactoryGirl.create(:exhibit) }
|
3
|
+
let!(:custom_field) { FactoryGirl.create(:custom_field, exhibit: exhibit, label: 'Foobar', field_type: 'vocab') }
|
4
|
+
let(:config) do
|
5
|
+
exhibit.blacklight_configuration
|
6
|
+
end
|
7
|
+
let(:field_metadata) { double('field_metadata') }
|
8
|
+
let(:empty_facet) { { document_count: 0, value_count: 0, terms: [] } }
|
9
|
+
let(:nonempty_facet) { { document_count: 1, value_count: 3, terms: %w(a b c) } }
|
10
|
+
let(:f) do
|
11
|
+
form_helper = nil
|
12
|
+
controller.view_context.bootstrap_form_for(config, url: '/update') do |f|
|
13
|
+
form_helper = f
|
14
|
+
end
|
15
|
+
form_helper
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
assign(:blacklight_configuration, config)
|
20
|
+
allow(view).to receive_messages(current_exhibit: exhibit,
|
21
|
+
blacklight_config: config.blacklight_config)
|
22
|
+
allow(field_metadata).to receive(:field).with(any_args).and_return(nonempty_facet)
|
23
|
+
allow(field_metadata).to receive(:field).with('genre_ssim').and_return(empty_facet)
|
24
|
+
allow(field_metadata).to receive(:field).with(custom_field.field).and_return(empty_facet)
|
25
|
+
assign(:field_metadata, field_metadata)
|
26
|
+
render partial: 'spotlight/search_configurations/facets', locals: { f: f }
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'shows the config for the non-empty personal name facet' do
|
30
|
+
expect(rendered).to have_content 'Personal Names'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'shows the config for the empty custom facet' do
|
34
|
+
expect(rendered).to have_content 'Foobar'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'hides the config for the empty genre facet' do
|
38
|
+
expect(rendered).not_to have_content 'Genre'
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blacklight-spotlight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.27.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Beer
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-08-
|
14
|
+
date: 2016-08-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -1121,6 +1121,7 @@ files:
|
|
1121
1121
|
- db/migrate/20151217211019_create_spotlight_exhibit_filters.rb
|
1122
1122
|
- db/migrate/20160329215014_add_readonly_to_custom_fields.rb
|
1123
1123
|
- db/migrate/20160711121314_add_default_view_to_spotlight_searches.rb
|
1124
|
+
- db/migrate/20160815165432_add_resource_to_solr_document_sidecar.rb
|
1124
1125
|
- lib/blacklight/spotlight.rb
|
1125
1126
|
- lib/generators/spotlight/install_generator.rb
|
1126
1127
|
- lib/generators/spotlight/scaffold_resource_generator.rb
|
@@ -1340,6 +1341,7 @@ files:
|
|
1340
1341
|
- spec/views/spotlight/resources/new.html.erb_spec.rb
|
1341
1342
|
- spec/views/spotlight/roles/index.html.erb_spec.rb
|
1342
1343
|
- spec/views/spotlight/search_configurations/_facet_metadata.html.erb_spec.rb
|
1344
|
+
- spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
|
1343
1345
|
- spec/views/spotlight/search_configurations/_search_fields.html.erb_spec.rb
|
1344
1346
|
- spec/views/spotlight/search_configurations/_sort.html.erb_spec.rb
|
1345
1347
|
- spec/views/spotlight/searches/_search.html.erb_spec.rb
|
@@ -1610,6 +1612,7 @@ test_files:
|
|
1610
1612
|
- spec/views/spotlight/resources/new.html.erb_spec.rb
|
1611
1613
|
- spec/views/spotlight/roles/index.html.erb_spec.rb
|
1612
1614
|
- spec/views/spotlight/search_configurations/_facet_metadata.html.erb_spec.rb
|
1615
|
+
- spec/views/spotlight/search_configurations/_facets.html.erb_spec.rb
|
1613
1616
|
- spec/views/spotlight/search_configurations/_search_fields.html.erb_spec.rb
|
1614
1617
|
- spec/views/spotlight/search_configurations/_sort.html.erb_spec.rb
|
1615
1618
|
- spec/views/spotlight/searches/_search.html.erb_spec.rb
|