Skip to content

Commit

Permalink
fix rights_statement indexing issue?
Browse files Browse the repository at this point in the history
  • Loading branch information
rococodogs committed Jan 15, 2025
1 parent 93ff219 commit 2b0ad79
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
16 changes: 9 additions & 7 deletions app/indexers/concerns/indexes_rights_statements_and_labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
module IndexesRightsStatementsAndLabels
def to_solr
super.tap do |document|
document['rights_statement_ssim'] ||= []
document['rights_statement_label_ssim'] ||= []
document['rights_statement_shortcode_ssim'] ||= []
document['rights_statement_ssim'] = []
document['rights_statement_label_ssim'] = []
document['rights_statement_shortcode_ssim'] = []

resource.rights_statement.each do |original_uri|
value = original_uri.is_a?(ActiveTriples::Resource) ? original_uri.id : original_uri
Array.wrap(resource.rights_statement).each do |original_uri|
value = original_uri.to_s
label = rights_service.label(value) { value }
shortcode = rights_service.shortcode(value) { nil }

document['rights_statement_ssim'] << value
document['rights_statement_label_ssim'] << rights_service.label(value) { value }
document['rights_statement_shortcode_ssim'] << rights_service.shortcode(value) { nil }
document['rights_statement_label_ssim'] << label
document['rights_statement_shortcode_ssim'] << shortcode
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/support/shared_contexts/resource_indexing_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
RSpec.shared_context 'resource indexing' do
subject(:indexer) { described_class.for(resource: resource) }

let(:resource_factory) { described_class.name.split('::').last.gsub(/Indexer$/, '').underscore.to_sym }
let(:resource) { build(resource_factory, **metadata) }
let(:metadata) { {} }
let(:solr_document) { indexer.to_solr }
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true
RSpec.shared_examples 'a BaseResourceIndexer' do
include_context 'resource indexing'

describe 'base_metadata fields' do
# base metadata
it_behaves_like 'it indexes', :bibliographic_citation, to: ['bibliographic_citation_tesim']
Expand All @@ -24,13 +26,6 @@
end

describe 'field indexing' do
subject(:indexer) { described_class.for(resource: resource) }

let(:resource_factory) { described_class.name.split('::').last.gsub(/Indexer$/, '').underscore.to_sym }
let(:resource) { build(resource_factory, **metadata) }
let(:metadata) { {} }
let(:solr_document) { indexer.to_solr }

describe 'permalink_urls' do
subject(:permalink_url) { solr_document['permalink_ss'] }

Expand Down
7 changes: 2 additions & 5 deletions spec/support/shared_examples/indexing/indexes_a_field.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true
RSpec.shared_examples 'it indexes' do |field, opts|
include_context 'resource indexing'

suffixes = opts[:to_suffixes]

raise 'Pass a field to the "it indexes" shared_example' unless field
Expand All @@ -13,11 +15,6 @@
end
end

let(:indexer) { described_class.for(resource: resource) }
let(:resource_type) { described_class.name.split('::').last.gsub(/Indexer$/, '').underscore.to_sym }
let(:resource) { build(resource_type) }
let(:solr_document) { indexer.to_solr }

to_fields.each do |solr_field|
it "#{field} to #{solr_field}" do
if solr_field[-1] == 'm'
Expand Down

0 comments on commit 2b0ad79

Please sign in to comment.