Skip to content

Commit

Permalink
Merge pull request #127 from pulibrary/range_label
Browse files Browse the repository at this point in the history
index range labels
  • Loading branch information
eliotjordan committed Oct 24, 2016
2 parents c77d13b + 5b30df8 commit 95f9f22
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
16 changes: 15 additions & 1 deletion app/values/manifest_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def jsonld_metadata_hash
end

def process_values(input_hash)
Hash[input_hash.map do |key, values|
h = Hash[input_hash.map do |key, values|
values = Array.wrap(values)
values.map! do |value|
if value["@value"]
Expand All @@ -39,6 +39,8 @@ def process_values(input_hash)
end
[key, values]
end]
range_labels(h)
h
end

def metadata_hash
Expand All @@ -48,4 +50,16 @@ def metadata_hash
process_values(super)
end
end

private

def range_labels(h)
values = []
(@manifest['structures'] || []).each do |s|
(s['ranges'] || []).each do |r|
values << r['label']
end
end
h['Range label'] = values unless values.empty?
end
end
6 changes: 5 additions & 1 deletion spec/cassettes/all_collections.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions spec/cassettes/mvw.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions spec/cassettes/see_also_connection_failed.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion spec/models/iiif_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
resource.document_builder.to_solr { |x| solr_doc = x }
expect(solr_doc["full_title_ssim"]).to eq 'Christopher and his kind, 1929-1939'
expect(solr_doc["readonly_created_tesim"]).to eq ["1976-01-01T00:00:00Z"]
expect(solr_doc["readonly_range-label_tesim"]).to eq ["Chapter 1", "Chapter 2"]
end
context "when given a MVW", vcr: { cassette_name: 'mvw' } do
let(:url) { "https://hydra-dev.princeton.edu/concern/multi_volume_works/f4752g76q/manifest" }
Expand All @@ -30,13 +31,14 @@
end
context "when given an unreachable seeAlso url", vcr: { cassette_name: 'see_also_connection_failed' } do
let(:url) { "https://hydra-dev.princeton.edu/concern/scanned_resources/s9w032300r/manifest" }
it "ingests ingests a iiif manifest using the metadata pool" do
it "ingests a iiif manifest using the metadata pool, excludes range labels when missing" do
exhibit = Spotlight::Exhibit.create title: 'Exhibit A'
resource = described_class.new manifest_url: url, exhibit: exhibit
expect(resource.save_and_index).to be_truthy
docs = Blacklight.default_index.connection.get("select", params: { q: "*:*" })["response"]["docs"]
scanned_resource_doc = docs.find { |x| x["full_title_ssim"] == ["Christopher and his kind, 1929-1939"] }
expect(scanned_resource_doc["readonly_date-created_tesim"]).to eq ['1976-01-01T00:00:00Z']
expect(scanned_resource_doc["readonly_range-label_tesim"]).to eq nil
end
end
end
Expand Down

0 comments on commit 95f9f22

Please sign in to comment.