spotlight-dor-resources 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -2
- data/.rubocop_todo.yml +1 -186
- data/app/models/spotlight/resources/dor_resource.rb +1 -0
- data/app/models/spotlight/resources/purl.rb +4 -4
- data/app/models/spotlight/resources/searchworks.rb +4 -5
- data/lib/spotlight/dor/indexer.rb +187 -125
- data/lib/spotlight/dor/resources.rb +19 -7
- data/lib/spotlight/dor/resources/engine.rb +3 -2
- data/lib/spotlight/dor/resources/version.rb +2 -1
- data/spec/integration/gdor_integration_spec.rb +9 -9
- data/spec/{unit → lib}/spotlight/dor/indexer_spec.rb +209 -10
- data/spec/models/spotlight/resources/purl_spec.rb +45 -39
- data/spec/models/spotlight/resources/searchworks_spec.rb +47 -44
- data/spec/vcr_cassettes/gdor_indexing_integration_test/{should_have_a_doc_id.yml → has_a_doc_id.yml} +60 -40
- data/spec/vcr_cassettes/gdor_indexing_integration_test/{should_have_spotlight_data.yml → has_exhibit-specific_indexing.yml} +48 -32
- data/spec/vcr_cassettes/gdor_indexing_integration_test/{should_have_the_gdor_data.yml → has_spotlight_data.yml} +48 -32
- data/spec/vcr_cassettes/gdor_indexing_integration_test/{should_have_exhibit-specific_indexing.yml → has_the_gdor_data.yml} +48 -32
- data/spotlight-dor-resources.gemspec +22 -22
- metadata +11 -21
- data/spec/integration/indexer_integration_spec.rb +0 -28
- data/spec/vcr_cassettes/indexer_integration_tests/donor_tags/no_donor_tags_ssim_field_in_solr_doc_when_note_displayLabel_Donor_tags_not_in_MODS.yml +0 -1382
- data/spec/vcr_cassettes/indexer_integration_tests/donor_tags/solr_doc_has_donor_tags_ssim_field_when_note_displayLabel_Donor_tags_is_in_MODS.yml +0 -1602
- data/spec/vcr_cassettes/indexer_integration_tests/genre/no_genre_ssim_field_when_genre_not_in_MODS.yml +0 -6822
- data/spec/vcr_cassettes/indexer_integration_tests/genre/solr_doc_has_genre_ssim_field_when_genre_in_MODS.yml +0 -1390
@@ -1,15 +1,27 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'harvestdor-indexer'
|
2
|
+
require 'spotlight/dor/resources/version'
|
3
3
|
|
4
4
|
module Spotlight
|
5
5
|
module Dor
|
6
|
+
# Spotlight::Dor::Resources provides a Rails engine
|
7
|
+
# that is capable of harvesting and indexing resources
|
8
|
+
# from Searchworks and PURL endpoints
|
6
9
|
module Resources
|
10
|
+
require 'spotlight/dor/indexer'
|
11
|
+
require 'spotlight/dor/resources/engine'
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
class <<self
|
14
|
+
def indexer
|
15
|
+
@indexer ||= Spotlight::Dor::Indexer.new gdor_config_path, solr: solr_config
|
16
|
+
end
|
17
|
+
|
18
|
+
def gdor_config_path
|
19
|
+
File.join(Rails.root, 'config', 'gdor.yml')
|
20
|
+
end
|
21
|
+
|
22
|
+
def solr_config
|
23
|
+
Blacklight.solr_config
|
24
|
+
end
|
13
25
|
end
|
14
26
|
end
|
15
27
|
end
|
@@ -2,12 +2,13 @@ require 'spotlight/engine'
|
|
2
2
|
require 'spotlight/dor/resources'
|
3
3
|
|
4
4
|
module Spotlight::Dor::Resources
|
5
|
+
# :nodoc:
|
5
6
|
class Engine < ::Rails::Engine
|
6
|
-
|
7
|
-
initializer "spotlight.dor.initialize" do
|
7
|
+
initializer 'spotlight.dor.initialize' do
|
8
8
|
Spotlight::Engine.config.resource_providers << Spotlight::Resources::Searchworks
|
9
9
|
Spotlight::Engine.config.resource_providers << Spotlight::Resources::Purl
|
10
10
|
Spotlight::Dor::Resources::Engine.config.parallel_options = { in_threads: 1 }
|
11
|
+
Spotlight::Dor::Resources::Engine.config.stacks_iiif_url = 'https://stacks.stanford.edu/image/iiif'
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
@@ -1,30 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'gdor indexing integration test', :vcr do
|
4
4
|
let :exhibit do
|
5
|
-
double(solr_data: {
|
5
|
+
double(solr_data: {}, blacklight_config: Blacklight::Configuration.new)
|
6
6
|
end
|
7
7
|
|
8
8
|
subject do
|
9
|
-
r = Spotlight::Resources::Purl.new(url:
|
9
|
+
r = Spotlight::Resources::Purl.new(url: 'https://purl.stanford.edu/xf680rd3068')
|
10
10
|
allow(r).to receive(:to_global_id).and_return('x')
|
11
11
|
allow(r).to receive(:exhibit).and_return(exhibit)
|
12
12
|
r.to_solr.first
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
expect(subject[:id]).to eq
|
15
|
+
it 'has a doc id' do
|
16
|
+
expect(subject[:id]).to eq 'xf680rd3068'
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
19
|
+
it 'has the gdor data' do
|
20
20
|
expect(subject).to include :collection, :modsxml, :url_fulltext
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'has spotlight data' do
|
24
24
|
expect(subject).to include :spotlight_resource_id_ssim
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
expect(subject).to include
|
27
|
+
it 'has exhibit-specific indexing' do
|
28
|
+
expect(subject).to include 'full_image_url_ssm'
|
29
29
|
end
|
30
30
|
end
|
@@ -40,13 +40,151 @@ describe Spotlight::Dor::Indexer do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
before do
|
43
|
-
#
|
43
|
+
# reduce log noise
|
44
44
|
allow(r).to receive(:harvestdor_client)
|
45
45
|
i = Harvestdor::Indexer.new
|
46
46
|
i.logger.level = Logger::WARN
|
47
47
|
allow(r).to receive(:indexer).and_return i
|
48
48
|
end
|
49
49
|
|
50
|
+
describe '#add_content_metadata_fields' do
|
51
|
+
before do
|
52
|
+
allow(r).to receive(:public_xml).and_return(public_xml)
|
53
|
+
|
54
|
+
# stacks url calculations require the druid
|
55
|
+
solr_doc[:id] = fake_druid
|
56
|
+
|
57
|
+
subject.send(:add_content_metadata_fields, sdb, solr_doc)
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with a record without contentMetadata' do
|
61
|
+
let(:public_xml) do
|
62
|
+
Nokogiri::XML <<-EOF
|
63
|
+
<publicObject></publicObject>
|
64
|
+
EOF
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'is blank, except for the document id' do
|
68
|
+
expect(solr_doc.except(:id)).to be_blank
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'with a record with contentMetadata' do
|
73
|
+
let(:public_xml) do
|
74
|
+
Nokogiri::XML <<-EOF
|
75
|
+
<publicObject>
|
76
|
+
<contentMetadata type="image">
|
77
|
+
<resource id="bj356mh7176_1" sequence="1" type="image">
|
78
|
+
<label>Image 1</label>
|
79
|
+
<file id="bj356mh7176_00_0001.jp2" mimetype="image/jp2" size="56108727">
|
80
|
+
<imageData width="12967" height="22970"/>
|
81
|
+
</file>
|
82
|
+
</resource>
|
83
|
+
</contentMetadata>
|
84
|
+
</publicObject>
|
85
|
+
EOF
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'indexes the declared content metadata type' do
|
89
|
+
expect(solr_doc['content_metadata_type_ssim']).to contain_exactly 'image'
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'indexes the thumbnail information' do
|
93
|
+
expect(solr_doc['content_metadata_first_image_file_name_ssm']).to contain_exactly 'bj356mh7176_00_0001'
|
94
|
+
expect(solr_doc['content_metadata_first_image_width_ssm']).to contain_exactly '12967'
|
95
|
+
expect(solr_doc['content_metadata_first_image_height_ssm']).to contain_exactly '22970'
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'indexes the images' do
|
99
|
+
stacks_base_url = 'https://stacks.stanford.edu/image/iiif/oo000oo0000%2Fbj356mh7176_00_0001'
|
100
|
+
expect(solr_doc['content_metadata_image_iiif_info_ssm']).to include "#{stacks_base_url}/info.json"
|
101
|
+
expect(solr_doc['thumbnail_square_url_ssm']).to include "#{stacks_base_url}/square/100,100/0/default.jpg"
|
102
|
+
expect(solr_doc['thumbnail_url_ssm']).to include "#{stacks_base_url}/full/!400,400/0/default.jpg"
|
103
|
+
expect(solr_doc['large_image_url_ssm']).to include "#{stacks_base_url}/full/pct:25/0/default.jpg"
|
104
|
+
expect(solr_doc['full_image_url_ssm']).to include "#{stacks_base_url}/full/full/0/default.jpg"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#add_donor_tags' do
|
110
|
+
before do
|
111
|
+
allow(r).to receive(:mods).and_return(mods)
|
112
|
+
subject.send(:add_donor_tags, sdb, solr_doc)
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'with a record without donor tags' do
|
116
|
+
let(:mods) do
|
117
|
+
Nokogiri::XML <<-EOF
|
118
|
+
<mods xmlns="#{Mods::MODS_NS}">
|
119
|
+
<note displayLabel="preferred citation">(not a donor tag)</note>
|
120
|
+
</mods>
|
121
|
+
EOF
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'is blank' do
|
125
|
+
expect(solr_doc['donor_tags_ssim']).to be_blank
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'with a record with donor tags' do
|
130
|
+
let(:mods) do
|
131
|
+
# e.g. from https://purl.stanford.edu/vw282gv1740
|
132
|
+
Nokogiri::XML <<-EOF
|
133
|
+
<mods xmlns="#{Mods::MODS_NS}">
|
134
|
+
<note displayLabel="Donor tags">Knowledge Systems Laboratory</note>
|
135
|
+
<note displayLabel="Donor tags">medical applications</note>
|
136
|
+
<note displayLabel="Donor tags">Publishing</note>
|
137
|
+
<note displayLabel="Donor tags">Stanford</note>
|
138
|
+
<note displayLabel="Donor tags">Stanford Computer Science Department</note>
|
139
|
+
</mods>
|
140
|
+
EOF
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'extracts the donor tags' do
|
144
|
+
expect(solr_doc['donor_tags_ssim']).to contain_exactly 'Knowledge Systems Laboratory',
|
145
|
+
'medical applications',
|
146
|
+
'Publishing',
|
147
|
+
'Stanford',
|
148
|
+
'Stanford Computer Science Department'
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe '#add_genre' do
|
154
|
+
before do
|
155
|
+
allow(r).to receive(:mods).and_return(mods)
|
156
|
+
subject.send(:add_genre, sdb, solr_doc)
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'with a record without a genre' do
|
160
|
+
let(:mods) do
|
161
|
+
Nokogiri::XML <<-EOF
|
162
|
+
<mods xmlns="#{Mods::MODS_NS}">
|
163
|
+
</mods>
|
164
|
+
EOF
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'is blank' do
|
168
|
+
expect(solr_doc['genre_ssim']).to be_blank
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'with a record with a genre' do
|
173
|
+
let(:mods) do
|
174
|
+
# e.g. from https://purl.stanford.edu/vw282gv1740
|
175
|
+
Nokogiri::XML <<-EOF
|
176
|
+
<mods xmlns="#{Mods::MODS_NS}">
|
177
|
+
<genre authority="aat" valueURI="http://vocab.getty.edu/aat/300028579">manuscripts for publication</genre>
|
178
|
+
</mods>
|
179
|
+
EOF
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'extracts the genre' do
|
183
|
+
expect(solr_doc['genre_ssim']).to contain_exactly 'manuscripts for publication'
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
50
188
|
describe '#add_series' do
|
51
189
|
# example string as key, expected series name as value
|
52
190
|
{
|
@@ -110,7 +248,7 @@ describe Spotlight::Dor::Indexer do
|
|
110
248
|
end # each
|
111
249
|
end # add_series
|
112
250
|
|
113
|
-
describe
|
251
|
+
describe '#add_box' do
|
114
252
|
# example string as key, expected box name as value
|
115
253
|
{
|
116
254
|
# feigenbaum
|
@@ -147,7 +285,7 @@ describe Spotlight::Dor::Indexer do
|
|
147
285
|
allow(r).to receive(:mods).and_return(mods_loc_phys_loc)
|
148
286
|
subject.send(:add_box, sdb, solr_doc)
|
149
287
|
end
|
150
|
-
it "has the expected box
|
288
|
+
it "has the expected box label '#{expected}'" do
|
151
289
|
expect(solr_doc['box_ssi']).to eq expected
|
152
290
|
end
|
153
291
|
end
|
@@ -156,7 +294,7 @@ describe Spotlight::Dor::Indexer do
|
|
156
294
|
allow(r).to receive(:mods).and_return(mods_rel_item_loc_phys_loc)
|
157
295
|
subject.send(:add_box, sdb, solr_doc)
|
158
296
|
end
|
159
|
-
it "has the expected box
|
297
|
+
it "has the expected box label '#{expected}'" do
|
160
298
|
expect(solr_doc['box_ssi']).to eq expected
|
161
299
|
end
|
162
300
|
end
|
@@ -166,7 +304,7 @@ describe Spotlight::Dor::Indexer do
|
|
166
304
|
allow(r).to receive(:mods).and_return(mods_loc_multiple_phys_loc)
|
167
305
|
subject.send(:add_box, sdb, solr_doc)
|
168
306
|
end
|
169
|
-
it "has the expected
|
307
|
+
it "has the expected box label '#{expected}'" do
|
170
308
|
expect(solr_doc['box_ssi']).to eq expected
|
171
309
|
end
|
172
310
|
end
|
@@ -213,7 +351,7 @@ describe Spotlight::Dor::Indexer do
|
|
213
351
|
allow(r).to receive(:mods).and_return(mods_loc_phys_loc)
|
214
352
|
subject.send(:add_folder, sdb, solr_doc)
|
215
353
|
end
|
216
|
-
it "has the expected folder
|
354
|
+
it "has the expected folder label '#{expected}'" do
|
217
355
|
expect(solr_doc['folder_ssi']).to eq expected
|
218
356
|
end
|
219
357
|
end
|
@@ -222,7 +360,7 @@ describe Spotlight::Dor::Indexer do
|
|
222
360
|
allow(r).to receive(:mods).and_return(mods_rel_item_loc_phys_loc)
|
223
361
|
subject.send(:add_folder, sdb, solr_doc)
|
224
362
|
end
|
225
|
-
it "has the expected folder
|
363
|
+
it "has the expected folder label '#{expected}'" do
|
226
364
|
expect(solr_doc['folder_ssi']).to eq expected
|
227
365
|
end
|
228
366
|
end
|
@@ -232,7 +370,7 @@ describe Spotlight::Dor::Indexer do
|
|
232
370
|
allow(r).to receive(:mods).and_return(mods_loc_multiple_phys_loc)
|
233
371
|
subject.send(:add_folder, sdb, solr_doc)
|
234
372
|
end
|
235
|
-
it "has the expected
|
373
|
+
it "has the expected folder label '#{expected}'" do
|
236
374
|
expect(solr_doc['folder_ssi']).to eq expected
|
237
375
|
end
|
238
376
|
end
|
@@ -240,6 +378,64 @@ describe Spotlight::Dor::Indexer do
|
|
240
378
|
end # each
|
241
379
|
end # add_folder
|
242
380
|
|
381
|
+
# rubocop:disable Metrics/LineLength
|
382
|
+
describe '#add_location' do
|
383
|
+
# example string as key, expected box name as value
|
384
|
+
{
|
385
|
+
# feigenbaum
|
386
|
+
'Call Number: SC0340, Accession 2005-101, Box : 1, Folder: 1': 'Call Number: SC0340, Accession 2005-101, Box : 1, Folder: 1',
|
387
|
+
'Call Number: SC0340, Accession 2005-101': 'Call Number: SC0340, Accession 2005-101',
|
388
|
+
'SC0340, 1986-052, Box 18': 'SC0340, 1986-052, Box 18',
|
389
|
+
'SC0340, Accession 2005-101, Box 18': 'SC0340, Accession 2005-101, Box 18',
|
390
|
+
'SC0340': nil,
|
391
|
+
'SC0340, Accession 1986-052': 'SC0340, Accession 1986-052',
|
392
|
+
'Stanford University. Libraries. Department of Special Collections and University Archives': nil,
|
393
|
+
# shpc (actually in <relatedItem><location><physicalLocation>)
|
394
|
+
'Series Biographical Photographs | Box 42 | Folder Abbot, Nathan': 'Series Biographical Photographs | Box 42 | Folder Abbot, Nathan',
|
395
|
+
'Series General Photographs | Box 42 | Folder Administration building--Outer Quad': 'Series General Photographs | Box 42 | Folder Administration building--Outer Quad',
|
396
|
+
# menuez
|
397
|
+
'MSS Photo 451, Series 1, Box 32, Folder 11, Sleeve 32-11-2, Frame B32-F11-S2-6': 'MSS Photo 451, Series 1, Box 32, Folder 11, Sleeve 32-11-2, Frame B32-F11-S2-6',
|
398
|
+
'Series 1, Box 10, Folder 8': 'Series 1, Box 10, Folder 8',
|
399
|
+
# fuller
|
400
|
+
'Collection: M1090 , Series: 1 , Box: 5 , Folder: 42': 'Collection: M1090 , Series: 1 , Box: 5 , Folder: 42',
|
401
|
+
# hummel (actually in <relatedItem><location><physicalLocation>)
|
402
|
+
'Box 42 | Folder 3': 'Box 42 | Folder 3',
|
403
|
+
'Flat-box 228 | Volume 1': 'Flat-box 228 | Volume 1'
|
404
|
+
}.each do |example, expected|
|
405
|
+
describe "for example '#{example}'" do
|
406
|
+
let(:example) { example }
|
407
|
+
context 'in /location/physicalLocation' do
|
408
|
+
before do
|
409
|
+
allow(r).to receive(:mods).and_return(mods_loc_phys_loc)
|
410
|
+
subject.send(:add_location, sdb, solr_doc)
|
411
|
+
end
|
412
|
+
it "has the expected location '#{expected}'" do
|
413
|
+
expect(solr_doc['location_ssi']).to eq expected
|
414
|
+
end
|
415
|
+
end
|
416
|
+
context 'in /relatedItem/location/physicalLocation' do
|
417
|
+
before do
|
418
|
+
allow(r).to receive(:mods).and_return(mods_rel_item_loc_phys_loc)
|
419
|
+
subject.send(:add_location, sdb, solr_doc)
|
420
|
+
end
|
421
|
+
it "has the expected location '#{expected}'" do
|
422
|
+
expect(solr_doc['location_ssi']).to eq expected
|
423
|
+
end
|
424
|
+
end
|
425
|
+
context 'with multiple physicalLocation elements' do
|
426
|
+
before do
|
427
|
+
allow(r).to receive(:mods).and_return(mods_loc_multiple_phys_loc)
|
428
|
+
subject.send(:add_location, sdb, solr_doc)
|
429
|
+
end
|
430
|
+
it "has the expected location '#{expected}'" do
|
431
|
+
expect(solr_doc['location_ssi']).to eq expected
|
432
|
+
end
|
433
|
+
end
|
434
|
+
end # for example
|
435
|
+
end # each
|
436
|
+
end # add_location
|
437
|
+
# rubocop:enable Metrics/LineLength
|
438
|
+
|
243
439
|
let(:mods_note_plain) do
|
244
440
|
Nokogiri::XML <<-EOF
|
245
441
|
<mods xmlns="#{Mods::MODS_NS}">
|
@@ -254,9 +450,11 @@ describe Spotlight::Dor::Indexer do
|
|
254
450
|
</mods>
|
255
451
|
EOF
|
256
452
|
end
|
257
|
-
|
453
|
+
|
454
|
+
# rubocop:disable Metrics/LineLength
|
455
|
+
describe '#add_folder_name' do
|
258
456
|
# example string as key, expected folder name as value
|
259
|
-
# all from feigenbaum (or based on feigenbaum), as that is only coll
|
457
|
+
# all from feigenbaum (or based on feigenbaum), as that is only coll with this data
|
260
458
|
{
|
261
459
|
'Call Number: SC0340, Accession: 1986-052, Box: 20, Folder: 40, Title: S': 'S',
|
262
460
|
'Call Number: SC0340, Accession: 1986-052, Box: 54, Folder: 25, Title: Balzer': 'Balzer',
|
@@ -299,4 +497,5 @@ describe Spotlight::Dor::Indexer do
|
|
299
497
|
end # for example
|
300
498
|
end # each
|
301
499
|
end # add_folder_name
|
500
|
+
# rubocop:enable Metrics/LineLength
|
302
501
|
end
|
@@ -2,13 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Spotlight::Resources::Purl do
|
4
4
|
let :exhibit do
|
5
|
-
double(solr_data: {
|
5
|
+
double(solr_data: {}, blacklight_config: Blacklight::Configuration.new)
|
6
6
|
end
|
7
7
|
let :blacklight_solr do
|
8
8
|
double
|
9
9
|
end
|
10
10
|
|
11
|
-
subject {
|
11
|
+
subject { described_class.new url: 'http://purl.stanford.edu/xf680rd3068' }
|
12
12
|
|
13
13
|
before do
|
14
14
|
allow(subject).to receive(:exhibit).and_return(exhibit)
|
@@ -16,98 +16,104 @@ describe Spotlight::Resources::Purl do
|
|
16
16
|
allow(subject).to receive(:to_global_id).and_return('x')
|
17
17
|
end
|
18
18
|
|
19
|
-
describe
|
20
|
-
subject {
|
21
|
-
it
|
22
|
-
expect(subject.can_provide?(double(url:
|
23
|
-
expect(subject.can_provide?(double(url:
|
19
|
+
describe '.can_provide?' do
|
20
|
+
subject { described_class }
|
21
|
+
it 'is true for a PURL URL' do
|
22
|
+
expect(subject.can_provide?(double(url: 'https://purl.stanford.edu/xyz'))).to eq true
|
23
|
+
expect(subject.can_provide?(double(url: 'http://purl.stanford.edu/xyz'))).to eq true
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'is false other URLs' do
|
27
|
+
expect(subject.can_provide?(double(url: 'https://example.com/xyz'))).to eq false
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
27
|
-
describe
|
28
|
-
it
|
29
|
-
subject.url =
|
30
|
-
expect(subject.doc_id).to eq
|
31
|
+
describe '#doc_id' do
|
32
|
+
it 'extracts DRUIDs from a PURL url' do
|
33
|
+
subject.url = 'http://purl.stanford.edu/xyz'
|
34
|
+
expect(subject.doc_id).to eq 'xyz'
|
31
35
|
end
|
32
36
|
|
33
|
-
it
|
34
|
-
subject.url =
|
35
|
-
expect(subject.doc_id).to eq
|
37
|
+
it 'extracts DRUIDs from a PURL format url' do
|
38
|
+
subject.url = 'http://purl.stanford.edu/xf680rd3068.xml'
|
39
|
+
expect(subject.doc_id).to eq 'xf680rd3068'
|
36
40
|
end
|
37
41
|
|
38
|
-
it "
|
39
|
-
subject.url =
|
40
|
-
expect(subject.doc_id).to eq
|
42
|
+
it "extracts DRUIDs from a PURL's viewer url" do
|
43
|
+
subject.url = 'http://purl.stanford.edu/xf680rd3068#image/1/small'
|
44
|
+
expect(subject.doc_id).to eq 'xf680rd3068'
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
44
|
-
describe
|
45
|
-
it
|
48
|
+
describe '#resource' do
|
49
|
+
it 'is a Harvestdor::Indexer resource' do
|
46
50
|
expect(subject.resource).to be_a_kind_of Harvestdor::Indexer::Resource
|
47
51
|
end
|
48
52
|
|
49
|
-
it
|
50
|
-
expect(subject.resource.druid).to eq
|
53
|
+
it 'has the correct druid' do
|
54
|
+
expect(subject.resource.druid).to eq 'xf680rd3068'
|
51
55
|
end
|
52
56
|
|
53
|
-
it
|
57
|
+
it 'has the correct indexer' do
|
54
58
|
expect(subject.resource.indexer).to eq Spotlight::Dor::Resources.indexer.harvestdor
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
58
|
-
describe
|
62
|
+
describe '#reindex' do
|
59
63
|
before do
|
60
|
-
allow(Spotlight::Dor::Resources.indexer).to receive(:solr_document).and_return(
|
64
|
+
allow(Spotlight::Dor::Resources.indexer).to receive(:solr_document).and_return(upstream: true)
|
61
65
|
allow(subject.resource).to receive(:collection?).and_return(false)
|
62
66
|
end
|
63
67
|
|
64
|
-
it
|
65
|
-
solr_data = [{spotlight_resource_id_ssim: nil, spotlight_resource_type_ssim:
|
66
|
-
expect(blacklight_solr).to receive(:update).with(
|
68
|
+
it 'adds a document to solr' do
|
69
|
+
solr_data = [{ spotlight_resource_id_ssim: nil, spotlight_resource_type_ssim: 'spotlight/resources/purls', upstream: true }]
|
70
|
+
expect(blacklight_solr).to receive(:update).with(params: { commitWithin: 500 },
|
71
|
+
data: solr_data.to_json,
|
72
|
+
headers: { 'Content-Type' => 'application/json' })
|
67
73
|
expect(subject).to receive(:update_index_time!)
|
68
74
|
subject.reindex
|
69
75
|
end
|
70
76
|
end
|
71
77
|
|
72
|
-
describe
|
78
|
+
describe '#to_solr' do
|
73
79
|
before do
|
74
80
|
allow(Spotlight::Dor::Resources.indexer).to receive(:solr_document)
|
75
81
|
end
|
76
|
-
context
|
82
|
+
context 'with a collection' do
|
77
83
|
before do
|
78
84
|
allow(subject.resource).to receive(:collection?).and_return(true)
|
79
85
|
end
|
80
86
|
|
81
|
-
it
|
87
|
+
it 'provides a solr document for the collection' do
|
82
88
|
allow(subject.resource).to receive(:items).and_return([])
|
83
|
-
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(
|
89
|
+
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(upstream: true)
|
84
90
|
expect(subject.to_solr.first).to include :upstream, :spotlight_resource_id_ssim, :spotlight_resource_type_ssim
|
85
91
|
end
|
86
92
|
|
87
|
-
it
|
93
|
+
it 'provides a solr document for the items too' do
|
88
94
|
item = double
|
89
95
|
allow(subject.resource).to receive(:items).and_return([item])
|
90
|
-
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(
|
91
|
-
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(item).and_return(
|
96
|
+
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(collection: true)
|
97
|
+
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(item).and_return(item: true)
|
92
98
|
solr_doc = subject.to_solr.to_a
|
93
99
|
expect(solr_doc.first).to include :collection
|
94
100
|
expect(solr_doc.last).to include :item
|
95
101
|
end
|
96
102
|
end
|
97
103
|
|
98
|
-
context
|
104
|
+
context 'with a single item' do
|
99
105
|
before do
|
100
106
|
allow(subject.resource).to receive(:collection?).and_return(false)
|
101
107
|
end
|
102
108
|
|
103
|
-
it
|
104
|
-
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(
|
109
|
+
it 'provides a solr document for the resource' do
|
110
|
+
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(upstream: true)
|
105
111
|
expect(subject.to_solr.first).to include :upstream, :spotlight_resource_id_ssim, :spotlight_resource_type_ssim
|
106
112
|
end
|
107
113
|
|
108
|
-
it
|
114
|
+
it 'indexs outside the context of an exhibit' do
|
109
115
|
allow(subject).to receive(:exhibit).and_return(nil)
|
110
|
-
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(
|
116
|
+
expect(Spotlight::Dor::Resources.indexer).to receive(:solr_document).with(subject.resource).and_return(upstream: true)
|
111
117
|
expect(subject.to_solr.first).to include :upstream, :spotlight_resource_id_ssim, :spotlight_resource_type_ssim
|
112
118
|
end
|
113
119
|
end
|