blacklight-spotlight 0.19.2 → 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38fb99b5c2366b2cf6ac5a264e215ed7b0611c43
4
- data.tar.gz: 72ba109b5f3c5d257de360f0faf3b8a6eee1b24b
3
+ metadata.gz: 27f15696fa8fa3ff1b57d0fbdeb5ac72e46e0dd9
4
+ data.tar.gz: a2187ef8f724bf5e79d56b03068ccbedfd3e24cf
5
5
  SHA512:
6
- metadata.gz: 029fc6b6a22f5e5b12c71d50a2721a6f638a808988dbfdc2e3fafa614fb670d11eedd62fe45a15da36aa1262b1c8098efa16bb659594a65998065605520da1ad
7
- data.tar.gz: dfccd052193692da330ee70c0bc9b728961fd36ab8855884d7a9ff7cdd2a495370a99ebc66a4574904f6092f90edc5c5349c0aa7b87eb6554b75108d606db50b
6
+ metadata.gz: cbcea53ab6c6ea3b79857aa243332f041cf7aa50a88f0d3aaf9d96b9b99383058bce9c387b7728a6af8087b6c8de0775916bd5ce4e06af9827dc300051458f29
7
+ data.tar.gz: e82d5776c0494429db93f78508fc150c69e0dae0bd13f32740689e440d662107c9a84d55ad9010d8c1da33fb4dd39d4ef80b82b97dd805c2e17df221210eb0c9
data/Rakefile CHANGED
@@ -89,7 +89,7 @@ namespace :spotlight do
89
89
 
90
90
  _, exit_status = Process.wait2(io.pid)
91
91
 
92
- raise 'Failed to generate spotlight' if exit_status != 0
92
+ raise 'Failed to generate spotlight' if exit_status.nonzero?
93
93
  end
94
94
  end
95
95
 
@@ -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?
@@ -66,6 +66,7 @@ module Spotlight
66
66
  def initialize(source_doc = {}, solr_response = nil)
67
67
  @association_cache = {}
68
68
  super
69
+ yield self if block_given?
69
70
  end
70
71
 
71
72
  # Returns true if +comparison_object+ is the same exact object, or +comparison_object+
@@ -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,7 +2,7 @@ module Spotlight
2
2
  ##
3
3
  # Global spotlight configuration
4
4
  class Site < ActiveRecord::Base
5
- has_many :exhibits
5
+ has_many :exhibits, -> { ordered_by_weight }
6
6
  has_many :roles, as: :resource
7
7
 
8
8
  belongs_to :masthead, dependent: :destroy
@@ -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, visibility_field => public? }.merge(data_to_solr)
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(existing_solr_doc_hash(doc[unique_key]) || {})
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
- (exhibit_specific_solr_data || {}).merge(spotlight_resource_metadata_for_solr || {})
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
- def existing_solr_doc_hash(id)
45
- document_model.new(unique_key => id).to_solr if document_model && id.present?
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?),
@@ -1,3 +1,3 @@
1
1
  module Spotlight
2
- VERSION = '0.19.2'.freeze
2
+ VERSION = '0.20.0'.freeze
3
3
  end
@@ -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.all.first).to eq exhibit_b
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
- subject { described_class.new(id: 'abcd123') }
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
- it 'includes exhibit-specific data' do
18
- allow(exhibit).to receive(:solr_data).and_return(exhibit_data: true)
19
- expect(subject).to include exhibit_data: true
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.19.2
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-25 00:00:00.000000000 Z
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.6.4
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