hydra-pbcore 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/custom_mapper.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  class Solrizer::FieldMapper::Default
2
2
 
3
3
  id_field 'id'
4
- index_as :searchable, :default => true do |t|
4
+ index_as :searchable do |t|
5
5
  t.default :suffix => '_t'
6
- t.date :suffix => '_dt' do |value|
7
- DateTime.parse(pbcore_date(value)).to_time.utc.iso8601
8
- end
6
+ t.date :suffix => '_dt'
9
7
  t.string :suffix => '_t'
10
8
  t.text :suffix => '_t'
11
9
  t.symbol :suffix => '_s'
@@ -19,6 +17,11 @@ class Solrizer::FieldMapper::Default
19
17
  index_as :facetable, :suffix => '_facet'
20
18
  index_as :sortable, :suffix => '_sort'
21
19
  index_as :unstemmed_searchable, :suffix => '_unstem_search'
20
+ index_as :converted_date do |t|
21
+ t.default :suffix => '_dt' do |value|
22
+ pbcore_date(value)
23
+ end
24
+ end
22
25
 
23
26
  # We assume that all dates are in ISO 8601 format, but sometimes users may only
24
27
  # specify a year or a year and month. This method adds a -01-01 or -01 respectively
@@ -27,6 +30,7 @@ class Solrizer::FieldMapper::Default
27
30
  # NOTE: This only applies to the date as it is stored in solr. The original value
28
31
  # as entered by the user is still maintained in the xml.
29
32
  def self.pbcore_date(date, value = String.new)
33
+ return date if date.empty?
30
34
  if date.match(/^[0-9]{4,4}$/)
31
35
  value = date + "-01-01"
32
36
  elsif date.match(/^[0-9]{4,4}-[0-9]{2,2}$/)
@@ -34,7 +38,7 @@ class Solrizer::FieldMapper::Default
34
38
  else
35
39
  value = date
36
40
  end
37
- return value
41
+ return DateTime.parse(value).to_time.utc.iso8601
38
42
  end
39
43
 
40
44
  end
@@ -108,8 +108,7 @@ class Document < ActiveFedora::NokogiriDatastream
108
108
  )
109
109
  t.event_date(:path=>"pbcoreCoverage/coverage",
110
110
  :attributes => {:annotation=>"Event Date"},
111
- :type => :date,
112
- :index_as => [:searchable]
111
+ :index_as => [:not_searchable, :converted_date, :displayable]
113
112
  )
114
113
 
115
114
  # Contributor names and roles
@@ -174,7 +173,7 @@ class Document < ActiveFedora::NokogiriDatastream
174
173
  )
175
174
  end
176
175
  # Individual field names:
177
- t.creation_date(:ref=>[:pbcoreInstantiation, :instantiationDate], :type => :date, :index_as => [:searchable])
176
+ t.creation_date(:ref=>[:pbcoreInstantiation, :instantiationDate], :index_as => [:not_searchable, :converted_date, :displayable])
178
177
  t.barcode(:ref=>[:pbcoreInstantiation, :instantiationIdentifier], :index_as => [:searchable, :displayable])
179
178
  t.repository(:ref=>[:pbcoreInstantiation, :instantiationLocation], :index_as => [:searchable, :displayable])
180
179
  t.format(:ref=>[:pbcoreInstantiation, :instantiationPhysical], :index_as => [:searchable, :facetable])
@@ -18,7 +18,7 @@ class Instantiation < ActiveFedora::NokogiriDatastream
18
18
  :index_as => [:displayable]
19
19
  )
20
20
  t.instantiationDate(:attributes=>{ :dateType=>"created" },
21
- :index_as => [:displayable, :searchable]
21
+ :index_as => [:not_searchable, :converted_date, :displayable]
22
22
  )
23
23
  t.instantiationDigital(:attributes=>{ :source=>"EBU file formats" },
24
24
  :index_as => [:searchable, :facetable]
@@ -1,3 +1,3 @@
1
1
  module HydraPbcore
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -5,8 +5,12 @@ describe Solrizer::FieldMapper::Default do
5
5
  describe "#pbcore_date" do
6
6
 
7
7
  it "should return valid dates from only partial ones" do
8
- Solrizer::FieldMapper::Default.pbcore_date('2003').should == "2003-01-01"
9
- Solrizer::FieldMapper::Default.pbcore_date('2009-07').should == "2009-07-01"
8
+ Solrizer::FieldMapper::Default.pbcore_date('2003').should == "2003-01-01T00:00:00Z"
9
+ Solrizer::FieldMapper::Default.pbcore_date('2009-07').should == "2009-07-01T00:00:00Z"
10
+ end
11
+
12
+ it "should return empty strings and not dates" do
13
+ Solrizer::FieldMapper::Default.pbcore_date('').should be_empty
10
14
  end
11
15
 
12
16
  end
@@ -245,6 +245,17 @@ describe HydraPbcore::Datastream::DigitalDocument do
245
245
  EquivalentXml.equivalent?(ref_node, sample_node, opts = { :element_order => false, :normalize_whitespace => true }).should be_true
246
246
  end
247
247
 
248
+ it "should display dates as they were entered" do
249
+ @object_ds.to_solr["event_date_display"].should == ["2012-11-11"]
250
+ end
251
+
252
+ it "should have dates converted to ISO 8601" do
253
+ @object_ds.to_solr["event_date_dt"].should == ["2012-11-11T00:00:00Z"]
254
+ end
255
+
256
+ it "should not index dates as text" do
257
+ @object_ds.to_solr["event_date_t"].should be_nil
258
+ end
248
259
 
249
260
  end
250
261
 
@@ -257,7 +257,7 @@ describe HydraPbcore::Datastream::Document do
257
257
 
258
258
  # Use ISO 8601 dates
259
259
  @object_ds.event_date = "2012-11-11"
260
- @object_ds.creation_date = "2012-11-11"
260
+ @object_ds.creation_date = "2012"
261
261
  end
262
262
 
263
263
  it "should match an exmplar" do
@@ -277,11 +277,20 @@ describe HydraPbcore::Datastream::Document do
277
277
  EquivalentXml.equivalent?(ref_node, sample_node, opts = { :element_order => false, :normalize_whitespace => true }).should be_true
278
278
  end
279
279
 
280
- it "should use specific solr fields based on type" do
281
- @object_ds.to_solr["creation_date_dt"].should == ["2012-11-11T00:00:00Z"]
282
- @object_ds.to_solr["event_date_dt"].should == ["2012-11-11T00:00:00Z"]
280
+ it "should display dates as they were entered" do
281
+ @object_ds.to_solr["creation_date_display"].should == ["2012"]
282
+ @object_ds.to_solr["event_date_display"].should == ["2012-11-11"]
283
283
  end
284
284
 
285
+ it "should have dates converted to ISO 8601" do
286
+ @object_ds.to_solr["creation_date_dt"].should == ["2012-01-01T00:00:00Z"]
287
+ @object_ds.to_solr["event_date_dt"].should == ["2012-11-11T00:00:00Z"]
288
+ end
289
+
290
+ it "should not index dates as text" do
291
+ @object_ds.to_solr["creation_date_t"].should be_nil
292
+ @object_ds.to_solr["event_date_t"].should be_nil
293
+ end
285
294
 
286
295
  end
287
296
 
@@ -259,9 +259,15 @@
259
259
  <pbcoreDescriptionDocument-event-date-dt type="array">
260
260
  <pbcoreDescriptionDocument-event-date-dt>2012-11-11T00:00:00Z</pbcoreDescriptionDocument-event-date-dt>
261
261
  </pbcoreDescriptionDocument-event-date-dt>
262
+ <pbcoreDescriptionDocument-event-date-display type="array">
263
+ <pbcoreDescriptionDocument-event-date-display>2012-11-11</pbcoreDescriptionDocument-event-date-display>
264
+ </pbcoreDescriptionDocument-event-date-display>
262
265
  <pbcoreDescriptionDocument-0-event-date-dt type="array">
263
266
  <pbcoreDescriptionDocument-0-event-date-dt>2012-11-11T00:00:00Z</pbcoreDescriptionDocument-0-event-date-dt>
264
267
  </pbcoreDescriptionDocument-0-event-date-dt>
268
+ <pbcoreDescriptionDocument-0-event-date-display type="array">
269
+ <pbcoreDescriptionDocument-0-event-date-display>2012-11-11</pbcoreDescriptionDocument-0-event-date-display>
270
+ </pbcoreDescriptionDocument-0-event-date-display>
265
271
  <pbcoreDescriptionDocument-contributor-name-t type="array">
266
272
  <pbcoreDescriptionDocument-contributor-name-t>contributor_name</pbcoreDescriptionDocument-contributor-name-t>
267
273
  <pbcoreDescriptionDocument-contributor-name-t>contributor_name</pbcoreDescriptionDocument-contributor-name-t>
@@ -529,6 +535,9 @@
529
535
  <event-date-dt type="array">
530
536
  <event-date-dt>2012-11-11T00:00:00Z</event-date-dt>
531
537
  </event-date-dt>
538
+ <event-date-display type="array">
539
+ <event-date-display>2012-11-11</event-date-display>
540
+ </event-date-display>
532
541
  <contributor-name-t type="array">
533
542
  <contributor-name-t>contributor_name</contributor-name-t>
534
543
  <contributor-name-t>contributor_name</contributor-name-t>
@@ -259,9 +259,15 @@
259
259
  <pbcoreDescriptionDocument-event-date-dt type="array">
260
260
  <pbcoreDescriptionDocument-event-date-dt>2012-11-11T00:00:00Z</pbcoreDescriptionDocument-event-date-dt>
261
261
  </pbcoreDescriptionDocument-event-date-dt>
262
+ <pbcoreDescriptionDocument-event-date-display type="array">
263
+ <pbcoreDescriptionDocument-event-date-display>2012-11-11</pbcoreDescriptionDocument-event-date-display>
264
+ </pbcoreDescriptionDocument-event-date-display>
262
265
  <pbcoreDescriptionDocument-0-event-date-dt type="array">
263
266
  <pbcoreDescriptionDocument-0-event-date-dt>2012-11-11T00:00:00Z</pbcoreDescriptionDocument-0-event-date-dt>
264
267
  </pbcoreDescriptionDocument-0-event-date-dt>
268
+ <pbcoreDescriptionDocument-0-event-date-display type="array">
269
+ <pbcoreDescriptionDocument-0-event-date-display>2012-11-11</pbcoreDescriptionDocument-0-event-date-display>
270
+ </pbcoreDescriptionDocument-0-event-date-display>
265
271
  <pbcoreDescriptionDocument-contributor-name-t type="array">
266
272
  <pbcoreDescriptionDocument-contributor-name-t>contributor_name</pbcoreDescriptionDocument-contributor-name-t>
267
273
  <pbcoreDescriptionDocument-contributor-name-t>contributor_name</pbcoreDescriptionDocument-contributor-name-t>
@@ -529,6 +535,9 @@
529
535
  <event-date-dt type="array">
530
536
  <event-date-dt>2012-11-11T00:00:00Z</event-date-dt>
531
537
  </event-date-dt>
538
+ <event-date-display type="array">
539
+ <event-date-display>2012-11-11</event-date-display>
540
+ </event-date-display>
532
541
  <contributor-name-t type="array">
533
542
  <contributor-name-t>contributor_name</contributor-name-t>
534
543
  <contributor-name-t>contributor_name</contributor-name-t>
@@ -597,8 +606,11 @@
597
606
  <pbcoreInstantiation-0-inst-clean-note-display>inserted</pbcoreInstantiation-0-inst-clean-note-display>
598
607
  </pbcoreInstantiation-0-inst-clean-note-display>
599
608
  <creation-date-dt type="array">
600
- <creation-date-dt>2012-11-11T00:00:00Z</creation-date-dt>
609
+ <creation-date-dt>2012-01-01T00:00:00Z</creation-date-dt>
601
610
  </creation-date-dt>
611
+ <creation-date-display type="array">
612
+ <creation-date-display>2012</creation-date-display>
613
+ </creation-date-display>
602
614
  <barcode-t type="array">
603
615
  <barcode-t>barcode</barcode-t>
604
616
  </barcode-t>
@@ -12,18 +12,18 @@
12
12
  <pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationIdentifier-t type="array">
13
13
  <pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationIdentifier-t>name</pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationIdentifier-t>
14
14
  </pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationIdentifier-t>
15
+ <pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-dt type="array">
16
+ <pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-dt>2012-11-01T00:00:00Z</pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-dt>
17
+ </pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-dt>
15
18
  <pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-display type="array">
16
- <pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-display>date</pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-display>
19
+ <pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-display>2012-11</pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-display>
17
20
  </pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-display>
18
- <pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-t type="array">
19
- <pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-t>date</pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-t>
20
- </pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDate-t>
21
+ <pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-dt type="array">
22
+ <pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-dt>2012-11-01T00:00:00Z</pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-dt>
23
+ </pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-dt>
21
24
  <pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-display type="array">
22
- <pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-display>date</pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-display>
25
+ <pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-display>2012-11</pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-display>
23
26
  </pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-display>
24
- <pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-t type="array">
25
- <pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-t>date</pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-t>
26
- </pbcoreDescriptionDocument-0-pbcoreInstantiation-0-instantiationDate-t>
27
27
  <pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDigital-t type="array">
28
28
  <pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDigital-t>file_format</pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDigital-t>
29
29
  </pbcoreDescriptionDocument-pbcoreInstantiation-instantiationDigital-t>
@@ -520,18 +520,18 @@
520
520
  <pbcoreDescriptionDocument-0-location-t type="array">
521
521
  <pbcoreDescriptionDocument-0-location-t>location</pbcoreDescriptionDocument-0-location-t>
522
522
  </pbcoreDescriptionDocument-0-location-t>
523
+ <pbcoreDescriptionDocument-date-dt type="array">
524
+ <pbcoreDescriptionDocument-date-dt>2012-11-01T00:00:00Z</pbcoreDescriptionDocument-date-dt>
525
+ </pbcoreDescriptionDocument-date-dt>
523
526
  <pbcoreDescriptionDocument-date-display type="array">
524
- <pbcoreDescriptionDocument-date-display>date</pbcoreDescriptionDocument-date-display>
527
+ <pbcoreDescriptionDocument-date-display>2012-11</pbcoreDescriptionDocument-date-display>
525
528
  </pbcoreDescriptionDocument-date-display>
526
- <pbcoreDescriptionDocument-date-t type="array">
527
- <pbcoreDescriptionDocument-date-t>date</pbcoreDescriptionDocument-date-t>
528
- </pbcoreDescriptionDocument-date-t>
529
+ <pbcoreDescriptionDocument-0-date-dt type="array">
530
+ <pbcoreDescriptionDocument-0-date-dt>2012-11-01T00:00:00Z</pbcoreDescriptionDocument-0-date-dt>
531
+ </pbcoreDescriptionDocument-0-date-dt>
529
532
  <pbcoreDescriptionDocument-0-date-display type="array">
530
- <pbcoreDescriptionDocument-0-date-display>date</pbcoreDescriptionDocument-0-date-display>
533
+ <pbcoreDescriptionDocument-0-date-display>2012-11</pbcoreDescriptionDocument-0-date-display>
531
534
  </pbcoreDescriptionDocument-0-date-display>
532
- <pbcoreDescriptionDocument-0-date-t type="array">
533
- <pbcoreDescriptionDocument-0-date-t>date</pbcoreDescriptionDocument-0-date-t>
534
- </pbcoreDescriptionDocument-0-date-t>
535
535
  <pbcoreDescriptionDocument-generation-display type="array">
536
536
  <pbcoreDescriptionDocument-generation-display>generation</pbcoreDescriptionDocument-generation-display>
537
537
  </pbcoreDescriptionDocument-generation-display>
@@ -832,18 +832,18 @@
832
832
  <pbcoreInstantiation-0-instantiationIdentifier-t type="array">
833
833
  <pbcoreInstantiation-0-instantiationIdentifier-t>name</pbcoreInstantiation-0-instantiationIdentifier-t>
834
834
  </pbcoreInstantiation-0-instantiationIdentifier-t>
835
+ <pbcoreInstantiation-instantiationDate-dt type="array">
836
+ <pbcoreInstantiation-instantiationDate-dt>2012-11-01T00:00:00Z</pbcoreInstantiation-instantiationDate-dt>
837
+ </pbcoreInstantiation-instantiationDate-dt>
835
838
  <pbcoreInstantiation-instantiationDate-display type="array">
836
- <pbcoreInstantiation-instantiationDate-display>date</pbcoreInstantiation-instantiationDate-display>
839
+ <pbcoreInstantiation-instantiationDate-display>2012-11</pbcoreInstantiation-instantiationDate-display>
837
840
  </pbcoreInstantiation-instantiationDate-display>
838
- <pbcoreInstantiation-instantiationDate-t type="array">
839
- <pbcoreInstantiation-instantiationDate-t>date</pbcoreInstantiation-instantiationDate-t>
840
- </pbcoreInstantiation-instantiationDate-t>
841
+ <pbcoreInstantiation-0-instantiationDate-dt type="array">
842
+ <pbcoreInstantiation-0-instantiationDate-dt>2012-11-01T00:00:00Z</pbcoreInstantiation-0-instantiationDate-dt>
843
+ </pbcoreInstantiation-0-instantiationDate-dt>
841
844
  <pbcoreInstantiation-0-instantiationDate-display type="array">
842
- <pbcoreInstantiation-0-instantiationDate-display>date</pbcoreInstantiation-0-instantiationDate-display>
845
+ <pbcoreInstantiation-0-instantiationDate-display>2012-11</pbcoreInstantiation-0-instantiationDate-display>
843
846
  </pbcoreInstantiation-0-instantiationDate-display>
844
- <pbcoreInstantiation-0-instantiationDate-t type="array">
845
- <pbcoreInstantiation-0-instantiationDate-t>date</pbcoreInstantiation-0-instantiationDate-t>
846
- </pbcoreInstantiation-0-instantiationDate-t>
847
847
  <pbcoreInstantiation-instantiationDigital-t type="array">
848
848
  <pbcoreInstantiation-instantiationDigital-t>file_format</pbcoreInstantiation-instantiationDigital-t>
849
849
  </pbcoreInstantiation-instantiationDigital-t>
@@ -1328,12 +1328,12 @@
1328
1328
  <location-t type="array">
1329
1329
  <location-t>location</location-t>
1330
1330
  </location-t>
1331
+ <date-dt type="array">
1332
+ <date-dt>2012-11-01T00:00:00Z</date-dt>
1333
+ </date-dt>
1331
1334
  <date-display type="array">
1332
- <date-display>date</date-display>
1335
+ <date-display>2012-11</date-display>
1333
1336
  </date-display>
1334
- <date-t type="array">
1335
- <date-t>date</date-t>
1336
- </date-t>
1337
1337
  <generation-display type="array">
1338
1338
  <generation-display>generation</generation-display>
1339
1339
  </generation-display>
@@ -135,7 +135,6 @@ describe HydraPbcore::Datastream::Instantiation do
135
135
  [
136
136
  "name",
137
137
  "location",
138
- "date",
139
138
  "generation",
140
139
  "media_type",
141
140
  "file_format",
@@ -176,6 +175,9 @@ describe HydraPbcore::Datastream::Instantiation do
176
175
  ].each do |field|
177
176
  @object_ds.send("#{field}=".to_sym, field)
178
177
  end
178
+
179
+ # Use a real date
180
+ @object_ds.date = "2012-11"
179
181
  end
180
182
 
181
183
  it "should match an exmplar" do
@@ -195,8 +197,18 @@ describe HydraPbcore::Datastream::Instantiation do
195
197
  EquivalentXml.equivalent?(ref_node, sample_node, opts = { :element_order => false, :normalize_whitespace => true }).should be_true
196
198
  end
197
199
 
200
+ it "should display dates as they were entered" do
201
+ @object_ds.to_solr["date_display"].should == ["2012-11"]
202
+ end
198
203
 
199
- end
204
+ it "should have dates converted to ISO 8601" do
205
+ @object_ds.to_solr["date_dt"].should == ["2012-11-01T00:00:00Z"]
206
+ end
200
207
 
208
+ it "should not index dates as text" do
209
+ @object_ds.to_solr["date_t"].should be_nil
210
+ end
211
+
212
+ end
201
213
 
202
214
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-pbcore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: