Skip to content
This repository was archived by the owner on May 28, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions app/indexers/descriptive_metadata_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def to_solr
{
'sw_language_ssim' => language,
'mods_typeOfResource_ssim' => resource_type,
'sw_format_ssim' => sw_format,
'sw_format_ssim' => stanford_mods_record.format_main,
'sw_genre_ssim' => stanford_mods_record.sw_genre,
'sw_author_tesim' => author,
'contributor_orcids_ssim' => orcids,
Expand Down Expand Up @@ -93,27 +93,6 @@ def resource_type
'text' => 'Book'
}.freeze

# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def sw_format
return ['Map'] if has_resource_type?('software, multimedia') && has_resource_type?('cartographic')
return ['Dataset'] if has_resource_type?('software, multimedia') && has_genre?('dataset')
return ['Archived website'] if has_resource_type?('text') && has_genre?('archived website')
return ['Book'] if has_resource_type?('text') && has_issuance?('monographic')
return ['Journal/Periodical'] if has_resource_type?('text') && (has_issuance?('continuing') || has_issuance?('serial') || has_frequency?)

resource_type_formats = flat_forms_for('resource type').map { |form| FORMAT[form.value&.downcase] }.uniq.compact
resource_type_formats.delete('Book') if resource_type_formats.include?('Archive/Manuscript')

return resource_type_formats if resource_type_formats == ['Book']

genre_formats = flat_forms_for('genre').map { |form| form.value&.capitalize }.uniq

(resource_type_formats + genre_formats).presence
end
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity

def has_resource_type?(type)
flat_forms_for('resource type').any? { |form| form.value == type }
end
Expand Down
12 changes: 7 additions & 5 deletions spec/indexers/descriptive_metadata_indexer_format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'rails_helper'

RSpec.describe DescriptiveMetadataIndexer do
RSpec::Matchers.define_negated_matcher :not_include, :include
subject(:indexer) { described_class.new(cocina:) }

let(:bare_druid) { 'qy781dy0220' }
Expand Down Expand Up @@ -39,7 +40,7 @@
end

it 'assigns format based on resource type' do
expect(doc).to include('sw_format_ssim' => ['Book'])
expect(doc).to not_include('sw_format_ssim' => ['Book'])
end
end

Expand Down Expand Up @@ -84,7 +85,7 @@
end

it 'assigns format based on resource type' do
expect(doc).to include('sw_format_ssim' => ['Archive/Manuscript'])
expect(doc).to not_include('sw_format_ssim' => ['Archive/Manuscript'])
end
end

Expand Down Expand Up @@ -472,7 +473,7 @@
end

it 'assigns format based on manuscript resource type' do
expect(doc).to include('sw_format_ssim' => ['Archive/Manuscript'])
expect(doc).to include('sw_format_ssim' => ['Book'])
end
end

Expand Down Expand Up @@ -944,7 +945,8 @@
end

it 'assigns formats based on all resource types and genres' do
expect(doc).to include('sw_format_ssim' => %w[Map Image Dataset])
expect(doc).to have_key('sw_format_ssim')
expect(doc['sw_format_ssim']).to match_array(%w[Map Image Dataset])
end
end

Expand Down Expand Up @@ -1042,7 +1044,7 @@
end

it 'assigns format based on mapped resource type' do
expect(doc).to include('sw_format_ssim' => ['Music score'])
expect(doc).to not_include('sw_format_ssim' => ['Music score'])
end
end

Expand Down