blacklight-spotlight 0.19.2 → 0.20.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/Rakefile +1 -1
- data/app/controllers/spotlight/exhibits_controller.rb +1 -1
- data/app/models/concerns/spotlight/ar_light.rb +1 -0
- data/app/models/concerns/spotlight/solr_document.rb +6 -0
- data/app/models/spotlight/exhibit.rb +1 -2
- data/app/models/spotlight/resource.rb +4 -1
- data/app/models/spotlight/site.rb +1 -1
- data/app/models/spotlight/solr_document_sidecar.rb +6 -3
- data/app/services/spotlight/solr_document_builder.rb +13 -8
- data/lib/spotlight/version.rb +1 -1
- data/spec/controllers/spotlight/sites_controller_spec.rb +1 -1
- data/spec/models/solr_document_spec.rb +12 -1
- data/spec/services/spotlight/solr_document_builder_spec.rb +20 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27f15696fa8fa3ff1b57d0fbdeb5ac72e46e0dd9
|
4
|
+
data.tar.gz: a2187ef8f724bf5e79d56b03068ccbedfd3e24cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbcea53ab6c6ea3b79857aa243332f041cf7aa50a88f0d3aaf9d96b9b99383058bce9c387b7728a6af8087b6c8de0775916bd5ce4e06af9827dc300051458f29
|
7
|
+
data.tar.gz: e82d5776c0494429db93f78508fc150c69e0dae0bd13f32740689e440d662107c9a84d55ad9010d8c1da33fb4dd39d4ef80b82b97dd805c2e17df221210eb0c9
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ module Spotlight
|
|
8
8
|
load_and_authorize_resource
|
9
9
|
|
10
10
|
def index
|
11
|
-
@published_exhibits = @exhibits.published.page(params[:page])
|
11
|
+
@published_exhibits = @exhibits.published.ordered_by_weight.page(params[:page])
|
12
12
|
@published_exhibits = @published_exhibits.tagged_with(params[:tag]) if params[:tag]
|
13
13
|
|
14
14
|
if @exhibits.one?
|
@@ -25,6 +25,12 @@ module Spotlight
|
|
25
25
|
##
|
26
26
|
# Class-level methods
|
27
27
|
module ClassMethods
|
28
|
+
def build_for_exhibit(id, exhibit)
|
29
|
+
new(unique_key => id) do |doc|
|
30
|
+
doc.sidecar(exhibit).save! # save is a nop if the sidecar isn't modified.
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
28
34
|
def reindex(id)
|
29
35
|
find(id).reindex
|
30
36
|
rescue Blacklight::Exceptions::InvalidSolrID => e
|
@@ -9,6 +9,7 @@ module Spotlight
|
|
9
9
|
|
10
10
|
scope :published, -> { where(published: true) }
|
11
11
|
scope :unpublished, -> { where(published: false) }
|
12
|
+
scope :ordered_by_weight, -> { order('weight ASC') }
|
12
13
|
|
13
14
|
paginates_per 50
|
14
15
|
|
@@ -17,8 +18,6 @@ module Spotlight
|
|
17
18
|
validates :title, presence: true
|
18
19
|
validates :slug, uniqueness: true
|
19
20
|
|
20
|
-
default_scope { order('weight ASC') }
|
21
|
-
|
22
21
|
acts_as_tagger
|
23
22
|
acts_as_taggable
|
24
23
|
delegate :blacklight_config, to: :blacklight_configuration
|
@@ -2,7 +2,6 @@ module Spotlight
|
|
2
2
|
##
|
3
3
|
# Exhibit resources
|
4
4
|
class Resource < ActiveRecord::Base
|
5
|
-
include Spotlight::SolrDocument::AtomicUpdates
|
6
5
|
include ActiveSupport::Benchmarkable
|
7
6
|
|
8
7
|
class_attribute :document_builder_class
|
@@ -116,6 +115,10 @@ module Spotlight
|
|
116
115
|
rescue => e
|
117
116
|
Rails.logger.warn "Unable to commit to solr: #{e}"
|
118
117
|
end
|
118
|
+
|
119
|
+
def write?
|
120
|
+
Spotlight::Engine.config.writable_index
|
121
|
+
end
|
119
122
|
end
|
120
123
|
end
|
121
124
|
end
|
@@ -2,14 +2,17 @@ module Spotlight
|
|
2
2
|
##
|
3
3
|
# Exhibit-specific metadata for indexed documents
|
4
4
|
class SolrDocumentSidecar < ActiveRecord::Base
|
5
|
-
belongs_to :exhibit
|
6
|
-
belongs_to :document, polymorphic: true
|
5
|
+
belongs_to :exhibit, required: true
|
6
|
+
belongs_to :document, required: true, polymorphic: true
|
7
7
|
serialize :data, Hash
|
8
8
|
|
9
9
|
delegate :has_key?, :key?, to: :data
|
10
10
|
|
11
11
|
def to_solr
|
12
|
-
{ document.class.unique_key.to_sym => document.id,
|
12
|
+
{ document.class.unique_key.to_sym => document.id,
|
13
|
+
visibility_field => public? }
|
14
|
+
.merge(data_to_solr)
|
15
|
+
.merge(exhibit.solr_data)
|
13
16
|
end
|
14
17
|
|
15
18
|
def private!
|
@@ -18,7 +18,7 @@ module Spotlight
|
|
18
18
|
return to_enum(:documents_to_index) { data.size } unless block_given?
|
19
19
|
|
20
20
|
data.lazy.reject(&:blank?).each do |doc|
|
21
|
-
yield doc.reverse_merge(
|
21
|
+
yield doc.reverse_merge(exhibit_solr_doc(doc[unique_key]).to_solr)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -33,16 +33,25 @@ module Spotlight
|
|
33
33
|
# @return [Enumerator<Hash>] multiple solr document hashes. This can be a
|
34
34
|
# simple array, or an lazy enumerator
|
35
35
|
def to_solr
|
36
|
-
|
36
|
+
spotlight_resource_metadata_for_solr
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
+
# Null object for SolrDocument
|
42
|
+
module NilSolrDocument
|
43
|
+
def self.to_solr
|
44
|
+
{}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
41
48
|
##
|
42
49
|
# Get any exhibit-specific metadata stored in e.g. sidecars, tags, etc
|
43
50
|
# This needs the generated solr document
|
44
|
-
|
45
|
-
|
51
|
+
# @returns [#to_solr] something that responds to `to_solr'
|
52
|
+
def exhibit_solr_doc(id)
|
53
|
+
return NilSolrDocument unless document_model || id.present?
|
54
|
+
document_model.build_for_exhibit(id, exhibit)
|
46
55
|
end
|
47
56
|
|
48
57
|
def unique_key
|
@@ -53,10 +62,6 @@ module Spotlight
|
|
53
62
|
end
|
54
63
|
end
|
55
64
|
|
56
|
-
def exhibit_specific_solr_data
|
57
|
-
exhibit.solr_data if exhibit
|
58
|
-
end
|
59
|
-
|
60
65
|
def spotlight_resource_metadata_for_solr
|
61
66
|
{
|
62
67
|
Spotlight::Engine.config.resource_global_id_field => (resource.to_global_id.to_s if resource.persisted?),
|
data/lib/spotlight/version.rb
CHANGED
@@ -38,7 +38,7 @@ describe Spotlight::SitesController, type: :controller do
|
|
38
38
|
|
39
39
|
expect(response).to redirect_to(exhibits_path)
|
40
40
|
|
41
|
-
expect(Spotlight::Exhibit.
|
41
|
+
expect(Spotlight::Exhibit.ordered_by_weight.first).to eq exhibit_b
|
42
42
|
expect(exhibit_a.reload.weight).to eq 5
|
43
43
|
end
|
44
44
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
describe SolrDocument, type: :model do
|
2
|
-
|
2
|
+
let(:document) { described_class.new(id: 'abcd123') }
|
3
|
+
subject { document }
|
3
4
|
its(:to_key) { should == ['abcd123'] }
|
4
5
|
its(:persisted?) { should be_truthy }
|
5
6
|
before do
|
@@ -9,6 +10,16 @@ describe SolrDocument, type: :model do
|
|
9
10
|
let(:exhibit) { FactoryGirl.create(:exhibit) }
|
10
11
|
let(:exhibit_alt) { FactoryGirl.create(:exhibit) }
|
11
12
|
|
13
|
+
describe '.build_for_exhibit' do
|
14
|
+
let(:id) { '123abc' }
|
15
|
+
subject { described_class.build_for_exhibit(id, exhibit) }
|
16
|
+
|
17
|
+
it 'has a persisted sidecar' do
|
18
|
+
expect(subject.sidecars.first).to be_persisted
|
19
|
+
expect(subject.sidecars.first.exhibit).to eq exhibit
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
12
23
|
it 'has tags on the exhibit' do
|
13
24
|
expect(subject.tags_from(exhibit)).to be_empty
|
14
25
|
end
|
@@ -13,10 +13,27 @@ describe Spotlight::SolrDocumentBuilder do
|
|
13
13
|
it 'includes a reference to the resource' do
|
14
14
|
expect(subject).to include spotlight_resource_id_ssim: resource.to_global_id.to_s
|
15
15
|
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#documents_to_index' do
|
19
|
+
context 'when the document belongs to more than one exhibit' do
|
20
|
+
let(:doc) { SolrDocument.new(id: 'abc123') }
|
21
|
+
let(:resource) { FactoryGirl.create(:resource) }
|
22
|
+
let(:resource_alt) { FactoryGirl.create(:resource) }
|
23
|
+
subject { resource.document_builder }
|
24
|
+
|
25
|
+
before do
|
26
|
+
allow(Spotlight::Engine.config).to receive(:filter_resources_by_exhibit).and_return(true)
|
27
|
+
allow(resource.document_builder).to receive(:to_solr).and_return(id: 'abc123')
|
28
|
+
allow(resource_alt.document_builder).to receive(:to_solr).and_return(id: 'abc123')
|
29
|
+
resource_alt.document_builder.documents_to_index.first
|
30
|
+
end
|
16
31
|
|
17
|
-
|
18
|
-
|
19
|
-
|
32
|
+
it 'has filter data for both exhibits' do
|
33
|
+
result = resource.document_builder.documents_to_index.first
|
34
|
+
expect(result).to include "spotlight_exhibit_slug_#{resource.exhibit.slug}_bsi"
|
35
|
+
expect(result).to include "spotlight_exhibit_slug_#{resource_alt.exhibit.slug}_bsi"
|
36
|
+
end
|
20
37
|
end
|
21
38
|
end
|
22
39
|
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.20.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-07-
|
14
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -1385,7 +1385,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1385
1385
|
version: '0'
|
1386
1386
|
requirements: []
|
1387
1387
|
rubyforge_project:
|
1388
|
-
rubygems_version: 2.
|
1388
|
+
rubygems_version: 2.5.1
|
1389
1389
|
signing_key:
|
1390
1390
|
specification_version: 4
|
1391
1391
|
summary: Enable librarians, curators, and others who are responsible for digital collections
|