From 1146523a745b41f9b790992a25f30e3ef2859fe5 Mon Sep 17 00:00:00 2001 From: Trey Pendragon Date: Wed, 25 Apr 2018 14:38:51 -0700 Subject: [PATCH 1/2] Revert "Revert "Add sort fields for title, date, and author; fixes #307"" This reverts commit ad9434bc65f4271bdd69c83a07c6ee566c869722. --- .rubocop.yml | 3 + app/controllers/catalog_controller.rb | 3 + app/services/iiif_manifest.rb | 19 +++++++ spec/controllers/catalog_controller_spec.rb | 2 +- spec/fixtures/iiif_responses.rb | 57 +++++++++++++++++++ spec/models/iiif_resource_spec.rb | 4 +- .../friendly_id_repository_spec.rb | 2 +- spec/services/iiif_manifest_spec.rb | 35 ++++++++++++ spec/support/stub_iiif_response.rb | 19 +++++++ 9 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 spec/fixtures/iiif_responses.rb create mode 100644 spec/services/iiif_manifest_spec.rb create mode 100644 spec/support/stub_iiif_response.rb diff --git a/.rubocop.yml b/.rubocop.yml index 07b7e995..c7f8d6cb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -141,3 +141,6 @@ Naming/FileName: Exclude: - 'Capfile' - 'Gemfile' +RSpec/AnyInstance: + Exclude: + - 'spec/support/stub_iiif_response.rb' diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 23c8d497..e730689b 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -53,6 +53,9 @@ def unique_custom_fields config.add_search_field 'all_fields', label: 'Everything' config.add_sort_field 'relevance', sort: 'score desc', label: 'Relevance' + config.add_sort_field 'sort_title', sort: 'sort_title_ssi asc, sort_date_ssi desc', label: 'Title' + config.add_sort_field 'sort_date', sort: 'sort_date_ssi desc, sort_title_ssi asc', label: 'Date' + config.add_sort_field 'sort_author', sort: 'sort_author_ssi asc, sort_title_ssi asc', label: 'Author' config.add_facet_field 'spotlight_resource_type_ssim' config.index.thumbnail_field = 'thumbnail_ssim' diff --git a/app/services/iiif_manifest.rb b/app/services/iiif_manifest.rb index ab4c69c4..39e54f65 100644 --- a/app/services/iiif_manifest.rb +++ b/app/services/iiif_manifest.rb @@ -1,6 +1,11 @@ class IiifManifest < ::Spotlight::Resources::IiifManifest def to_solr add_noid + # this is called in super, but idempotent so safe to call here also; we need the metadata + add_metadata + add_sort_title + add_sort_date + add_sort_author super end @@ -8,6 +13,20 @@ def add_noid solr_hash["access_identifier_ssim"] = [noid] end + def add_sort_title + # Once we upgrade we should probably use this json_ld_value? + # solr_hash['sort_title_ssi'] = Array.wrap(json_ld_value(manifest.label)).first + solr_hash['sort_title_ssi'] = Array.wrap(manifest.label).first + end + + def add_sort_date + solr_hash['sort_date_ssi'] = Array.wrap(solr_hash['readonly_date_ssim']).first + end + + def add_sort_author + solr_hash['sort_author_ssi'] = Array.wrap(solr_hash['readonly_author_ssim']).first + end + def full_image_url return super unless manifest['thumbnail'] && manifest['thumbnail']['service'] && manifest['thumbnail']['service']['@id'] "#{manifest['thumbnail']['service']['@id']}/full/!600,600/0/default.jpg" diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb index 632d29e2..156f57e5 100644 --- a/spec/controllers/catalog_controller_spec.rb +++ b/spec/controllers/catalog_controller_spec.rb @@ -2,7 +2,7 @@ RSpec.describe CatalogController do let(:user) { nil } - context "with mvw", vcr: { cassette_name: 'mvw' } do + context "with mvw", vcr: { cassette_name: 'mvw', allow_playback_repeats: true } do let(:url) { "https://hydra-dev.princeton.edu/concern/multi_volume_works/f4752g76q/manifest" } it "hides scanned resources with parents" do exhibit = Spotlight::Exhibit.create title: 'Exhibit A', published: true diff --git a/spec/fixtures/iiif_responses.rb b/spec/fixtures/iiif_responses.rb new file mode 100644 index 00000000..f60bebc6 --- /dev/null +++ b/spec/fixtures/iiif_responses.rb @@ -0,0 +1,57 @@ +# pulled and pared down from spotlight +# https://github.com/projectblacklight/spotlight/blob/b4608610ed0405f1d8ed4d6c9c17a02b06b9bcf6/spec/fixtures/iiif_responses.rb +module IiifResponses + def test_manifest1 + { + "@id": 'uri://for-manifest1/manifest', + "@type": 'sc:Manifest', + "label": 'Test Manifest 1', + "attribution": 'Attribution Data', + "description": 'A test IIIF manifest', + "license": 'http://www.example.org/license.html', + "metadata": [ + { + "label": 'Author', + "value": 'John Doe' + }, + { + "label": 'Author', + "value": 'Jane Doe' + }, + { + "label": 'Another Field', + "value": 'Some data' + }, + { + "label": 'Date', + "value": '1929' + } + ], + "thumbnail": { + "@id": 'uri://to-thumbnail' + }, + "sequences": [ + { + "@type": 'sc:Sequence', + "canvases": [ + { + "@type": 'sc:Canvas', + "images": [ + { + "@type": 'oa:Annotation', + "resource": { + "@type": 'dcterms:Image', + "@id": 'uri://full-image', + "service": { + "@id": 'uri://to-image-service' + } + } + } + ] + } + ] + } + ] + }.to_json + end +end diff --git a/spec/models/iiif_resource_spec.rb b/spec/models/iiif_resource_spec.rb index cd51e279..8ba6170a 100644 --- a/spec/models/iiif_resource_spec.rb +++ b/spec/models/iiif_resource_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe IIIFResource do - context 'with recorded http interactions', vcr: { cassette_name: 'all_collections' } do + context 'with recorded http interactions', vcr: { cassette_name: 'all_collections', allow_playback_repeats: true } do let(:url) { 'https://hydra-dev.princeton.edu/concern/scanned_resources/1r66j1149/manifest' } it 'ingests a iiif manifest' do exhibit = Spotlight::Exhibit.create title: 'Exhibit A' @@ -49,7 +49,7 @@ expect(scanned_resource_doc["full_image_url_ssm"]).to eq ["https://libimages1.princeton.edu/loris/plum/hq%2F37%2Fvn%2F61%2F6-intermediate_file.jp2/full/!600,600/0/default.jpg"] end end - context "when given an unreachable seeAlso url", vcr: { cassette_name: 'see_also_connection_failed' } do + context "when given an unreachable seeAlso url", vcr: { cassette_name: 'see_also_connection_failed', allow_playback_repeats: true } do let(:url) { "https://hydra-dev.princeton.edu/concern/scanned_resources/s9w032300r/manifest" } it "ingests a iiif manifest using the metadata pool, excludes range labels when missing" do exhibit = Spotlight::Exhibit.create title: 'Exhibit A' diff --git a/spec/repositories/friendly_id_repository_spec.rb b/spec/repositories/friendly_id_repository_spec.rb index f5ad511f..8a7f10e6 100644 --- a/spec/repositories/friendly_id_repository_spec.rb +++ b/spec/repositories/friendly_id_repository_spec.rb @@ -1,6 +1,6 @@ require 'rails_helper' -RSpec.describe FriendlyIdRepository, vcr: { cassette_name: "all_collections" } do +RSpec.describe FriendlyIdRepository, vcr: { cassette_name: "all_collections", allow_playback_repeats: true } do let(:repository) { described_class.new(CatalogController.new.blacklight_config) } let(:url) { 'https://hydra-dev.princeton.edu/concern/scanned_resources/1r66j1149/manifest' } let(:exhibit) { Spotlight::Exhibit.create title: 'Exhibit A' } diff --git a/spec/services/iiif_manifest_spec.rb b/spec/services/iiif_manifest_spec.rb new file mode 100644 index 00000000..4fcaf719 --- /dev/null +++ b/spec/services/iiif_manifest_spec.rb @@ -0,0 +1,35 @@ +require 'rails_helper' + +RSpec.describe IiifManifest do + let(:manifest_service) { described_class.new(url: url, manifest: manifest, collection: collection) } + let(:url) { 'uri://some_id/manifest' } + let(:collection) { instance_double(Spotlight::Resources::IiifManifest) } + let(:manifest_fixture) { test_manifest1 } + before do + allow(collection).to receive(:compound_id).and_return('1') + stub_iiif_response_for_url(url, manifest_fixture) + manifest_service.with_exhibit(exhibit) + end + + describe '#to_solr' do + let(:manifest) { IiifService.new(url).send(:object) } + let(:exhibit) { FactoryBot.create(:exhibit) } + describe 'sort_title' do + it 'is a single-value text field' do + expect(manifest_service.to_solr["sort_title_ssi"]).to eq "Test Manifest 1" + end + end + + describe 'sort_date' do + it 'is a single-value text field' do + expect(manifest_service.to_solr["sort_date_ssi"]).to eq "1929" + end + end + + describe 'sort_author' do + it 'is a single-value text field' do + expect(manifest_service.to_solr["sort_author_ssi"]).to eq "John Doe" + end + end + end +end diff --git a/spec/support/stub_iiif_response.rb b/spec/support/stub_iiif_response.rb new file mode 100644 index 00000000..ab824a28 --- /dev/null +++ b/spec/support/stub_iiif_response.rb @@ -0,0 +1,19 @@ +# pulled and pared down from spotlight +# https://github.com/projectblacklight/spotlight/blob/b4608610ed0405f1d8ed4d6c9c17a02b06b9bcf6/spec/support/stub_iiif_response.rb +require 'fixtures/iiif_responses' +module StubIiifResponse + def stub_iiif_response_for_url(url, response) + allow(IiifService).to receive(:iiif_response).with(url).and_return(response) + end + + def stub_default_collection + allow_any_instance_of(Spotlight::Resources::IiifHarvester).to receive_messages(url_is_iiif?: true) + + stub_iiif_response_for_url('uri://for-manifest1/manifest', test_manifest1) + end +end + +RSpec.configure do |config| + config.include IiifResponses + config.include StubIiifResponse +end From df7d7559b6d5bdfcffebffbc6829aa62051f7fbf Mon Sep 17 00:00:00 2001 From: Trey Pendragon Date: Wed, 25 Apr 2018 14:46:51 -0700 Subject: [PATCH 2/2] Fix rubocop. --- spec/services/iiif_manifest_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/services/iiif_manifest_spec.rb b/spec/services/iiif_manifest_spec.rb index 4fcaf719..84958244 100644 --- a/spec/services/iiif_manifest_spec.rb +++ b/spec/services/iiif_manifest_spec.rb @@ -5,6 +5,7 @@ let(:url) { 'uri://some_id/manifest' } let(:collection) { instance_double(Spotlight::Resources::IiifManifest) } let(:manifest_fixture) { test_manifest1 } + before do allow(collection).to receive(:compound_id).and_return('1') stub_iiif_response_for_url(url, manifest_fixture) @@ -14,6 +15,7 @@ describe '#to_solr' do let(:manifest) { IiifService.new(url).send(:object) } let(:exhibit) { FactoryBot.create(:exhibit) } + describe 'sort_title' do it 'is a single-value text field' do expect(manifest_service.to_solr["sort_title_ssi"]).to eq "Test Manifest 1"