Skip to content

Commit

Permalink
Add an index status field to the sidecars for resource harvesters to …
Browse files Browse the repository at this point in the history
…inject arbitrary information
  • Loading branch information
cbeer committed Aug 16, 2016
1 parent ac5479a commit cdb67af
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/concerns/spotlight/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module SolrDocument
##
# Class-level methods
module ClassMethods
def build_for_exhibit(id, exhibit)
def build_for_exhibit(id, exhibit, attributes = {})
new(unique_key => id) do |doc|
doc.sidecar(exhibit).save! # save is a nop if the sidecar isn't modified.
doc.sidecar(exhibit).tap { |x| x.assign_attributes(attributes) }.save! # save is a nop if the sidecar isn't modified.
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/models/spotlight/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Resource < ActiveRecord::Base
class_attribute :weight

belongs_to :exhibit
has_many :solr_document_sidecars

serialize :data, Hash
store :metadata, accessors: [
:enqueued_at,
Expand Down
3 changes: 3 additions & 0 deletions app/models/spotlight/solr_document_sidecar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module Spotlight
# Exhibit-specific metadata for indexed documents
class SolrDocumentSidecar < ActiveRecord::Base
belongs_to :exhibit, required: true
belongs_to :resource
belongs_to :document, required: true, polymorphic: true
serialize :data, Hash

store :data, accessors: [:index_status]

delegate :has_key?, :key?, to: :data

def to_solr
Expand Down
2 changes: 1 addition & 1 deletion app/services/spotlight/solr_document_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def self.to_solr
# @returns [#to_solr] something that responds to `to_solr'
def exhibit_solr_doc(id)
return NilSolrDocument unless document_model || id.present?
document_model.build_for_exhibit(id, exhibit)
document_model.build_for_exhibit(id, exhibit, resource: resource)
end

def unique_key
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddResourceToSolrDocumentSidecar < ActiveRecord::Migration
def change
add_column :spotlight_solr_document_sidecars, :resource_id, :integer
add_column :spotlight_solr_document_sidecars, :resource_type, :string

add_index :spotlight_solr_document_sidecars, [:resource_type, :resource_id], name: 'spotlight_solr_document_sidecars_resource'
end
end
9 changes: 9 additions & 0 deletions spec/services/spotlight/solr_document_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
expect(result).to include "spotlight_exhibit_slug_#{resource.exhibit.slug}_bsi"
expect(result).to include "spotlight_exhibit_slug_#{resource_alt.exhibit.slug}_bsi"
end

it 'creates a sidecar resource for the document' do
resource.document_builder.documents_to_index.first

expect(Spotlight::SolrDocumentSidecar.where(document_id: 'abc123', document_type: SolrDocument).size).to eq 2
sidecar = resource.solr_document_sidecars.find_by(document_id: 'abc123', document_type: SolrDocument)
expect(sidecar.exhibit).to eq resource.exhibit
expect(sidecar.resource).to eq resource
end
end
end
end

0 comments on commit cdb67af

Please sign in to comment.