gdor-indexer 0.4.1 → 0.5.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b01625bc9ae63bd07de7edbee92754e2d5c3ce82
4
- data.tar.gz: 9586786a5f096aeaf9a7cacac5aa4d07a846ac38
3
+ metadata.gz: 4724a7e6363dc6d287c4bf1bf6033e000930bf90
4
+ data.tar.gz: 72fbd1746a114c918ebc9dd838f9674f7fddb8b0
5
5
  SHA512:
6
- metadata.gz: c82da4f86166c0864a0ad5ed969304b8ee8a357d07efa71738d7a7ce50976cb509568ff812b9ca3b28a44d514237a37ff69eb43a8a617cd28e6aadf2e6794378
7
- data.tar.gz: 9bc2a66dbf0652206ca609b5658eebf0d80d32695c0ccf03cace3bf58506650dc212f7b49e09bf6ecfb50c2f6f1c5a5389a913345318e1bf3b212f74b0dcdad9
6
+ metadata.gz: 88b7024e0faf8b01d0091b6f53e1683d9f9fc9ba6602d4905d2078e682d7cdb284c95e63d362698ef22709961f313f002ec483dcad43f5f4e224149e6269d339
7
+ data.tar.gz: 8b9b76607dabc0f1409a66b37efb1fd0e07c8afc29a4c36d65a3f144b60b6b531afb3251512a97cd75a47164ce8b599cdf79a0d12fd795e2f85c8385983fbb21
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2016-01-07 14:25:59 -0800 using RuboCop version 0.34.2.
3
+ # on 2016-01-13 15:12:03 -0800 using RuboCop version 0.34.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -24,7 +24,7 @@ Lint/UselessAssignment:
24
24
  - 'spec/unit/indexer_spec.rb'
25
25
  - 'spec/unit/solr_doc_builder_spec.rb'
26
26
 
27
- # Offense count: 22
27
+ # Offense count: 21
28
28
  Metrics/AbcSize:
29
29
  Max: 82
30
30
 
@@ -37,12 +37,12 @@ Metrics/ClassLength:
37
37
  Metrics/CyclomaticComplexity:
38
38
  Max: 9
39
39
 
40
- # Offense count: 309
40
+ # Offense count: 318
41
41
  # Configuration parameters: AllowURI, URISchemes.
42
42
  Metrics/LineLength:
43
43
  Max: 258
44
44
 
45
- # Offense count: 16
45
+ # Offense count: 15
46
46
  # Configuration parameters: CountComments.
47
47
  Metrics/MethodLength:
48
48
  Max: 43
@@ -70,12 +70,6 @@ RSpec/InstanceVariable:
70
70
  - 'spec/unit/public_xml_fields_spec.rb'
71
71
  - 'spec/unit/solr_doc_builder_spec.rb'
72
72
 
73
- # Offense count: 6
74
- # Cop supports --auto-correct.
75
- Style/AlignArray:
76
- Exclude:
77
- - 'lib/gdor/indexer/mods_fields.rb'
78
-
79
73
  # Offense count: 7
80
74
  # Cop supports --auto-correct.
81
75
  # Configuration parameters: EnforcedStyle, SupportedStyles.
@@ -106,7 +100,7 @@ Style/DoubleNegation:
106
100
  Exclude:
107
101
  - 'lib/gdor/indexer/solr_doc_hash.rb'
108
102
 
109
- # Offense count: 2
103
+ # Offense count: 1
110
104
  # Cop supports --auto-correct.
111
105
  # Configuration parameters: EnforcedStyle, SupportedStyles.
112
106
  Style/EmptyLinesAroundBlockBody:
@@ -119,7 +113,7 @@ Style/GuardClause:
119
113
  Exclude:
120
114
  - 'lib/gdor/indexer.rb'
121
115
 
122
- # Offense count: 14
116
+ # Offense count: 21
123
117
  # Cop supports --auto-correct.
124
118
  # Configuration parameters: EnforcedStyle, SupportedStyles.
125
119
  Style/MultilineOperationIndentation:
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ['lib']
19
19
 
20
20
  spec.add_dependency 'harvestdor-indexer'
21
- spec.add_dependency 'stanford-mods', '>= 1.3.4' # for new pub date methods
21
+ spec.add_dependency 'stanford-mods', '>= 1.4.0' # for new pub date methods
22
22
  spec.add_dependency 'nokogiri'
23
23
  spec.add_dependency 'rsolr'
24
24
  spec.add_dependency 'activesupport'
@@ -4,7 +4,7 @@ module GDor::Indexer::ModsFields
4
4
  # Create a Hash representing a Solr doc, with all MODS related fields populated.
5
5
  # @return [Hash] Hash representing the Solr document
6
6
  def doc_hash_from_mods
7
- sort_str_w_approx_dates = smods_rec.pub_date_sortable_string(false)
7
+ pub_year_w_approx_dates = smods_rec.pub_year_int(false)
8
8
  doc_hash = {
9
9
  # title fields
10
10
  title_245a_search: smods_rec.sw_short_title,
@@ -46,22 +46,22 @@ module GDor::Indexer::ModsFields
46
46
 
47
47
  # publication fields
48
48
  pub_search: smods_rec.place,
49
- pub_date_sort: sort_str_w_approx_dates,
50
- # these are for single value facet display (in leiu of date slider (pub_year_tisim) and deprecated pub_date)
51
- pub_year_no_approx_isi: smods_rec.pub_date_sortable_string(true),
52
- pub_year_w_approx_isi: sort_str_w_approx_dates,
53
- # TODO: remove pub_date after reindexing existing colls; deprecated in favor of pub_year_xxx_approx_isi ...
54
- pub_date: smods_rec.pub_date_facet,
55
- # display fields
49
+ pub_year_isi: pub_year_w_approx_dates, # for sorting
50
+ # TODO: remove pub_date_sort after reindexing existing colls; deprecated in favor of pub_year_isi ...
51
+ pub_date_sort: smods_rec.pub_year_sort_str(false),
52
+ # these are for single value facet display (in leiu of date slider (pub_year_tisim) )
53
+ pub_year_no_approx_isi: smods_rec.pub_year_int(true),
54
+ pub_year_w_approx_isi: pub_year_w_approx_dates,
55
+ # display fields TODO: pub_date_display is deprecated; need better implementation of imprint_display
56
56
  imprint_display: smods_rec.pub_date_display,
57
57
  # pub_date_best_sort_str_value is protected ...
58
- creation_year_isi: smods_rec.send(:pub_date_best_sort_str_value, smods_rec.date_created_elements(false)),
59
- publication_year_isi: smods_rec.send(:pub_date_best_sort_str_value, smods_rec.date_issued_elements(false)),
58
+ creation_year_isi: smods_rec.year_int(smods_rec.date_created_elements(false)),
59
+ publication_year_isi: smods_rec.year_int(smods_rec.date_issued_elements(false)),
60
60
 
61
61
  all_search: smods_rec.text.gsub(/\s+/, ' ')
62
62
  }
63
63
 
64
- more_pub_date_goodness(doc_hash)
64
+ add_pub_year_tisim(doc_hash)
65
65
  end
66
66
 
67
67
  private
@@ -76,30 +76,13 @@ module GDor::Indexer::ModsFields
76
76
  vals
77
77
  end
78
78
 
79
- # additional pub date field processing for Solr doc hash
79
+ # add pub_year_tisim (for Date Slider; positive values only) to doc_hash
80
80
  # @param [Hash] Hash representing the Solr document
81
81
  # @return [Hash] updated Hash representing the Solr document
82
- def more_pub_date_goodness(doc_hash)
83
- pub_date_sort_val = doc_hash[:pub_date_sort]
82
+ def add_pub_year_tisim(doc_hash)
83
+ pub_date_sort_val = doc_hash[:pub_year_isi]
84
84
  if is_positive_int? pub_date_sort_val
85
85
  doc_hash[:pub_year_tisim] = pub_date_sort_val # for date slider
86
- # remove leading zeros
87
- [:pub_year_no_approx_isi,
88
- :pub_year_w_approx_isi,
89
- :creation_year_isi,
90
- :publication_year_isi
91
- ].each do |field_sym|
92
- doc_hash[field_sym] = remove_leading_zeros(doc_hash[field_sym]) if doc_hash[field_sym]
93
- end
94
- else
95
- # turn B.C. into -yyy for facet/display fields
96
- [:pub_year_no_approx_isi,
97
- :pub_year_w_approx_isi,
98
- :creation_year_isi,
99
- :publication_year_isi
100
- ].each do |field_sym|
101
- doc_hash[field_sym] = '-' + (1000 + doc_hash[field_sym].to_i).to_s if doc_hash[field_sym]
102
- end
103
86
  end
104
87
  doc_hash
105
88
  end
@@ -110,10 +93,4 @@ module GDor::Indexer::ModsFields
110
93
  rescue
111
94
  false
112
95
  end
113
-
114
- def remove_leading_zeros(year_sort_str)
115
- return '0' if year_sort_str == '0000'
116
- return year_sort_str.sub(/^[0:]*/, '') if year_sort_str.start_with?('0')
117
- year_sort_str
118
- end
119
96
  end
@@ -1,5 +1,5 @@
1
1
  module GDor
2
2
  class Indexer
3
- VERSION = '0.4.1'
3
+ VERSION = '0.5.0'
4
4
  end
5
5
  end
@@ -23,7 +23,7 @@ describe GDor::Indexer::ModsFields do
23
23
 
24
24
  context 'publication date fields' do
25
25
 
26
- RSpec.shared_examples 'expected' do |solr_field_sym, mods_field_val, exp_val|
26
+ RSpec.shared_examples 'expected (dateIssued)' do |solr_field_sym, mods_field_val, exp_val|
27
27
  it "#{exp_val} for #{mods_field_val}" do
28
28
  m = mods_origin_info_start_str +
29
29
  "<dateIssued>#{mods_field_val}</dateIssued>" +
@@ -33,51 +33,57 @@ describe GDor::Indexer::ModsFields do
33
33
  end
34
34
  end
35
35
 
36
- context 'pub_date (to know current behavior)' do
37
- it 'calls Stanford::Mods::Record instance pub_date_sortable_string(false)' do
38
- expect(sdb.smods_rec).to receive(:pub_date_facet)
39
- sdb.doc_hash_from_mods[:pub_date]
36
+ RSpec.shared_examples 'pub year int (dateIssued)' do |solr_field_sym|
37
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '1945', 1945
38
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '945', 945
39
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '66', 66
40
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '5', 5
41
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '0', 0
42
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, 'blah blah 1945 blah blah', 1945
43
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '16--', 1600
44
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '9--', 900
45
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '19th century', 1800
46
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '9th century', 800
47
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, 'blah June 4, 1594; blah 1596', 1594
48
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, 'Aug. 3rd, 1886', 1886
49
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, 'Aug. 3rd, [18]86? foo bar', 1886
50
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, 'early 1890s', 1890
51
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '1865-6', 1865
52
+ end
53
+ RSpec.shared_examples 'pub year int (dateIssued) for B.C. years' do |solr_field_sym|
54
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '-4', -4
55
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '-15', -15
56
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '-666', -666
57
+ it_behaves_like 'expected (dateIssued)', solr_field_sym, '300 B.C.', -300
58
+ end
59
+
60
+ context 'pub_year_isi' do
61
+ it 'calls Stanford::Mods::Record instance pub_year_int(false)' do
62
+ expect(sdb.smods_rec).to receive(:pub_year_int).with(false)
63
+ allow(sdb.smods_rec).to receive(:pub_year_int).with(true) # pub_year_no_approx_isi
64
+ sdb.doc_hash_from_mods[:pub_year_isi]
40
65
  end
41
66
  it 'includes approx dates' do
42
67
  m = mods_origin_info_start_str +
43
68
  "<dateIssued qualifier='approximate'>1945</dateIssued>" +
44
69
  mods_origin_info_end_str
45
70
  sdb = sdb_for_mods(m)
46
- expect(sdb.doc_hash_from_mods[:pub_date]).to eq('1945')
71
+ expect(sdb.doc_hash_from_mods[:pub_year_isi]).to eq 1945
47
72
  end
48
- it 'takes single dateCreated' do
73
+ it 'will use dateCreated' do
49
74
  m = mods_origin_info_start_str +
50
75
  "<dateCreated>1904</dateCreated>" +
51
76
  mods_origin_info_end_str
52
77
  sdb = sdb_for_mods(m)
53
- expect(sdb.doc_hash_from_mods[:pub_date]).to eq('1904')
78
+ expect(sdb.doc_hash_from_mods[:pub_year_isi]).to eq 1904
54
79
  end
55
- it_behaves_like 'expected', :pub_date, 'blah blah 1945 blah', '1945'
56
- it_behaves_like 'expected', :pub_date, '1945', '1945'
57
- it_behaves_like 'expected', :pub_date, '945', '945'
58
- it_behaves_like 'expected', :pub_date, '66', nil
59
- it_behaves_like 'expected', :pub_date, '5', nil
60
- it_behaves_like 'expected', :pub_date, '0', nil
61
- it_behaves_like 'expected', :pub_date, '-4', nil
62
- it_behaves_like 'expected', :pub_date, '-15', nil
63
- it_behaves_like 'expected', :pub_date, '-666', '666' # WRONG
64
- it_behaves_like 'expected', :pub_date, '16--', nil
65
- it_behaves_like 'expected', :pub_date, '8--', nil
66
- it_behaves_like 'expected', :pub_date, '19th century', '19th century'
67
- it_behaves_like 'expected', :pub_date, '9th century', '9th century'
68
- it_behaves_like 'expected', :pub_date, '300 B.C.', '300 B.C.'
69
- it_behaves_like 'expected', :pub_date, 'Text dated June 4, 1594; miniatures added by 1596', '1594'
70
- it_behaves_like 'expected', :pub_date, 'Aug. 3rd, 1886', '1886'
71
- it_behaves_like 'expected', :pub_date, 'Aug. 3rd, [18]86?', '1886'
72
- it_behaves_like 'expected', :pub_date, 'early 1890s', '1890'
73
- it_behaves_like 'expected', :pub_date, '1865-6', '1865'
74
-
80
+ it_behaves_like 'pub year int (dateIssued)', :pub_year_isi
81
+ it_behaves_like 'pub year int (dateIssued) for B.C. years', :pub_year_isi
75
82
  end
76
83
 
77
- context 'pub_date_sort' do
78
- it 'calls Stanford::Mods::Record instance pub_date_sortable_string(false)' do
79
- expect(sdb.smods_rec).to receive(:pub_date_sortable_string).with(false)
80
- allow(sdb.smods_rec).to receive(:pub_date_sortable_string).with(true) # for pub_year_no_approx_isi
84
+ context 'pub_date_sort (DEPRECATED in favor of pub_year_isi)' do
85
+ it 'calls Stanford::Mods::Record instance pub_year_sort_str(false)' do
86
+ expect(sdb.smods_rec).to receive(:pub_year_sort_str).with(false)
81
87
  sdb.doc_hash_from_mods[:pub_date_sort]
82
88
  end
83
89
  it 'includes approx dates' do
@@ -94,74 +100,88 @@ describe GDor::Indexer::ModsFields do
94
100
  sdb = sdb_for_mods(m)
95
101
  expect(sdb.doc_hash_from_mods[:pub_date_sort]).to eq('1904')
96
102
  end
97
- it_behaves_like 'expected', :pub_date_sort, '1945', '1945'
98
- it_behaves_like 'expected', :pub_date_sort, '945', '0945'
99
- it_behaves_like 'expected', :pub_date_sort, '66', '0066'
100
- it_behaves_like 'expected', :pub_date_sort, '5', '0005'
101
- it_behaves_like 'expected', :pub_date_sort, '0', '0000'
103
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '1945', '1945'
104
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '945', '0945'
105
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '66', '0066'
106
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '5', '0005'
107
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '0', '0000'
108
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '16--', '1600'
109
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '9--', '0900'
110
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '19th century', '1800'
111
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '9th century', '0800'
102
112
  # these negative values are for String lexical sorting as this is a string
103
- it_behaves_like 'expected', :pub_date_sort, '-4', '-996'
104
- it_behaves_like 'expected', :pub_date_sort, '-15', '-985'
105
- it_behaves_like 'expected', :pub_date_sort, '-666', '-334'
106
- it_behaves_like 'expected', :pub_date_sort, '16--', '1600'
107
- it_behaves_like 'expected', :pub_date_sort, '9--', '0900'
108
- it_behaves_like 'expected', :pub_date_sort, '19th century', '1800'
109
- it_behaves_like 'expected', :pub_date_sort, '9th century', '0800'
110
113
  # -(1000 - |yyy|) for BC dates
111
- it_behaves_like 'expected', :pub_date_sort, '300 B.C.', '-700'
114
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '-4', '-996'
115
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '-15', '-985'
116
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '-666', '-334'
117
+ it_behaves_like 'expected (dateIssued)', :pub_date_sort, '300 B.C.', '-700'
112
118
  end
113
119
 
114
- context 'single valued pub year facets' do
115
- let(:mods) do
116
- mods_origin_info_start_str +
117
- "<dateIssued qualifier=\"approximate\">1500</dateIssued>
118
- <dateIssued>2000</dateIssued>" +
119
- mods_origin_info_end_str
120
+ context 'pub_year_no_approx_isi' do
121
+ it 'does not include approx dates' do
122
+ m = mods_origin_info_start_str +
123
+ "<dateIssued qualifier='approximate'>1945</dateIssued>" +
124
+ mods_origin_info_end_str
125
+ sdb = sdb_for_mods(m)
126
+ expect(sdb.doc_hash_from_mods[:pub_year_no_approx_isi]).to eq nil
120
127
  end
121
- it 'pub_year_no_approx_isi calls Stanford::Mods::Record instance pub_date_facet_single_value(true)' do
128
+ it 'calls Stanford::Mods::Record instance pub_year_int(true)' do
129
+ mods = mods_origin_info_start_str +
130
+ "<dateIssued qualifier=\"approximate\">1500</dateIssued>
131
+ <dateIssued>2000</dateIssued>" +
132
+ mods_origin_info_end_str
122
133
  sdb = sdb_for_mods(mods)
123
- expect(sdb.smods_rec).to receive(:pub_date_sortable_string).with(true).and_call_original
124
- allow(sdb.smods_rec).to receive(:pub_date_sortable_string).with(false) # for other flavor
125
- expect(sdb.doc_hash_from_mods[:pub_year_no_approx_isi]).to eq '2000'
134
+ expect(sdb.smods_rec).to receive(:pub_year_int).with(true).and_call_original
135
+ allow(sdb.smods_rec).to receive(:pub_year_int).with(false) # for other flavor
136
+ expect(sdb.doc_hash_from_mods[:pub_year_no_approx_isi]).to eq 2000
137
+ end
138
+ it 'will use dateCreated' do
139
+ m = mods_origin_info_start_str +
140
+ "<dateCreated>1904</dateCreated>" +
141
+ mods_origin_info_end_str
142
+ sdb = sdb_for_mods(m)
143
+ expect(sdb.doc_hash_from_mods[:pub_year_no_approx_isi]).to eq 1904
126
144
  end
127
- it 'pub_year_w_approx_isi calls Stanford::Mods::Record instance pub_date_facet_single_value(false)' do
145
+ it_behaves_like 'pub year int (dateIssued)', :pub_year_no_approx_isi
146
+ it_behaves_like 'pub year int (dateIssued) for B.C. years', :pub_year_no_approx_isi
147
+ end
148
+
149
+ context 'pub_year_w_approx_isi' do
150
+ it 'includes approx dates' do
151
+ m = mods_origin_info_start_str +
152
+ "<dateIssued qualifier='approximate'>1945</dateIssued>" +
153
+ mods_origin_info_end_str
154
+ sdb = sdb_for_mods(m)
155
+ expect(sdb.doc_hash_from_mods[:pub_year_w_approx_isi]).to eq 1945
156
+ end
157
+ it 'calls Stanford::Mods::Record instance pub_year_int(false)' do
158
+ mods = mods_origin_info_start_str +
159
+ "<dateIssued qualifier=\"approximate\">1500</dateIssued>
160
+ <dateIssued>2000</dateIssued>" +
161
+ mods_origin_info_end_str
128
162
  sdb = sdb_for_mods(mods)
129
- expect(sdb.smods_rec).to receive(:pub_date_sortable_string).with(false).and_call_original
130
- allow(sdb.smods_rec).to receive(:pub_date_sortable_string).with(true) # for other flavor
131
- expect(sdb.doc_hash_from_mods[:pub_year_w_approx_isi]).to eq '1500'
163
+ expect(sdb.smods_rec).to receive(:pub_year_int).with(false).and_call_original
164
+ allow(sdb.smods_rec).to receive(:pub_year_int).with(true) # for other flavor
165
+ expect(sdb.doc_hash_from_mods[:pub_year_w_approx_isi]).to eq 1500
132
166
  end
133
- RSpec.shared_examples "single pub year facet" do |field_sym|
134
- it_behaves_like 'expected', field_sym, 'blah blah 1945 blah', '1945'
135
- it_behaves_like 'expected', field_sym, '1945', '1945'
136
- it_behaves_like 'expected', field_sym, '945', '945'
137
- it_behaves_like 'expected', field_sym, '66', '66'
138
- it_behaves_like 'expected', field_sym, '5', '5'
139
- it_behaves_like 'expected', field_sym, '0', '0'
140
- it_behaves_like 'expected', field_sym, '-4', '-4'
141
- it_behaves_like 'expected', field_sym, '-15', '-15'
142
- it_behaves_like 'expected', field_sym, '-666', '-666'
143
- it_behaves_like 'expected', field_sym, '16--', '1600'
144
- it_behaves_like 'expected', field_sym, '8--', '800'
145
- it_behaves_like 'expected', field_sym, '19th century', '1800'
146
- it_behaves_like 'expected', field_sym, '9th century', '800'
147
- it_behaves_like 'expected', field_sym, '300 B.C.', '-300'
148
- it_behaves_like 'expected', field_sym, 'Text dated June 4, 1594; miniatures added by 1596', '1594'
149
- it_behaves_like 'expected', field_sym, 'Aug. 3rd, 1886', '1886'
150
- it_behaves_like 'expected', field_sym, 'Aug. 3rd, [18]86?', '1886'
151
- it_behaves_like 'expected', field_sym, 'early 1890s', '1890'
152
- it_behaves_like 'expected', field_sym, '1865-6', '1865'
167
+ it 'will use dateCreated' do
168
+ m = mods_origin_info_start_str +
169
+ "<dateCreated>1904</dateCreated>" +
170
+ mods_origin_info_end_str
171
+ sdb = sdb_for_mods(m)
172
+ expect(sdb.doc_hash_from_mods[:pub_year_w_approx_isi]).to eq 1904
153
173
  end
154
- it_behaves_like "single pub year facet", :pub_year_no_approx_isi
155
- it_behaves_like "single pub year facet", :pub_year_w_approx_isi
174
+ it_behaves_like 'pub year int (dateIssued)', :pub_year_w_approx_isi
175
+ it_behaves_like 'pub year int (dateIssued) for B.C. years', :pub_year_w_approx_isi
156
176
  end
157
177
 
158
178
  context 'pub_year_tisim for date slider' do
159
179
  it 'should handle multiple pub dates (to be implemented - esp for date slider)'
160
180
 
161
181
  # FIXME: it should be using a method approp for date slider values, not single value
162
- it 'pub_year_tisim calls Stanford::Mods::Record instance pub_date_sortable_string(false)' do
163
- expect(sdb.smods_rec).to receive(:pub_date_sortable_string).with(false)
164
- allow(sdb.smods_rec).to receive(:pub_date_sortable_string).with(true) # for pub_year_no_approx_isi
182
+ it 'pub_year_tisim calls Stanford::Mods::Record instance pub_year_int(false)' do
183
+ expect(sdb.smods_rec).to receive(:pub_year_int).with(false)
184
+ allow(sdb.smods_rec).to receive(:pub_year_int).with(true) # for pub_year_no_approx_isi
165
185
  sdb.doc_hash_from_mods[:pub_year_tisim]
166
186
  end
167
187
  it 'includes approx dates' do
@@ -169,53 +189,36 @@ describe GDor::Indexer::ModsFields do
169
189
  "<dateIssued qualifier='approximate'>1945</dateIssued>" +
170
190
  mods_origin_info_end_str
171
191
  sdb = sdb_for_mods(m)
172
- expect(sdb.doc_hash_from_mods[:pub_year_tisim]).to eq('1945')
192
+ expect(sdb.doc_hash_from_mods[:pub_year_tisim]).to eq 1945
173
193
  end
174
- it 'takes single dateCreated' do
194
+ it 'will use dateCreated' do
175
195
  m = mods_origin_info_start_str +
176
196
  "<dateCreated>1904</dateCreated>" +
177
197
  mods_origin_info_end_str
178
198
  sdb = sdb_for_mods(m)
179
- expect(sdb.doc_hash_from_mods[:pub_year_tisim]).to eq('1904')
180
- end
181
- it 'ignores B.C. dates' do
182
- m = mods_origin_info_start_str +
183
- "<dateCreated>300 B.C.</dateCreated>" +
184
- mods_origin_info_end_str
185
- sdb = sdb_for_mods(m)
186
- expect(sdb.doc_hash_from_mods).not_to have_key(:pub_year_tisim)
187
- expect(sdb.doc_hash_from_mods[:pub_year_tisim]).to be_nil
199
+ expect(sdb.doc_hash_from_mods[:pub_year_tisim]).to eq 1904
188
200
  end
189
- it_behaves_like 'expected', :pub_year_tisim, '1945', '1945'
190
- it_behaves_like 'expected', :pub_year_tisim, '945', '0945'
191
- it_behaves_like 'expected', :pub_year_tisim, '66', '0066'
192
- it_behaves_like 'expected', :pub_year_tisim, '5', '0005'
193
- it_behaves_like 'expected', :pub_year_tisim, '0', '0000'
194
- it_behaves_like 'expected', :pub_year_tisim, '-4', nil
195
- it_behaves_like 'expected', :pub_year_tisim, '-15', nil
196
- it_behaves_like 'expected', :pub_year_tisim, '-666', nil
197
- it_behaves_like 'expected', :pub_year_tisim, '16--', '1600'
198
- it_behaves_like 'expected', :pub_year_tisim, '9--', '0900'
199
- it_behaves_like 'expected', :pub_year_tisim, '19th century', '1800'
200
- it_behaves_like 'expected', :pub_year_tisim, '9th century', '0800'
201
- it_behaves_like 'expected', :pub_year_tisim, 'Text dated June 4, 1594; miniatures added by 1596', '1594'
202
- it_behaves_like 'expected', :pub_year_tisim, 'Aug. 3rd, 1886', '1886'
203
- it_behaves_like 'expected', :pub_year_tisim, 'Aug. 3rd, [18]86?', '1886'
204
- it_behaves_like 'expected', :pub_year_tisim, 'early 1890s', '1890'
205
- it_behaves_like 'expected', :pub_year_tisim, '1865-6', '1865' # FIXME: should be both years
201
+ it_behaves_like 'pub year int (dateIssued)', :pub_year_tisim
202
+ # nil for years before 0
203
+ it_behaves_like 'expected (dateIssued)', :pub_year_tisim, '-4', nil
204
+ it_behaves_like 'expected (dateIssued)', :pub_year_tisim, '-15', nil
205
+ it_behaves_like 'expected (dateIssued)', :pub_year_tisim, '-666', nil
206
+ it_behaves_like 'expected (dateIssued)', :pub_year_tisim, '300 B.C.', nil
207
+ it_behaves_like 'expected (dateIssued)', :pub_year_tisim, 'blah June 4, 1594; blah 1596', 1594 # FIXME: should be both years
208
+ it_behaves_like 'expected (dateIssued)', :pub_year_tisim, '1865-6', 1865 # FIXME: should be both years
206
209
  end
207
210
 
208
211
  context 'creation_year_isi' do
209
- it 'creation_year_isi calls Stanford::Mods::Record pub_date_best_sort_str_value for dateCreated elements' do
212
+ it 'creation_year_isi calls Stanford::Mods::Record year_int for dateCreated elements' do
210
213
  m = mods_origin_info_start_str +
211
214
  "<dateCreated qualifier='approximate'>1500</dateCreated>
212
215
  <dateIssued qualifier='approximate'>2000</dateIssued>" +
213
216
  mods_origin_info_end_str
214
217
  sdb = sdb_for_mods(m)
215
- expect(sdb.smods_rec).to receive(:pub_date_best_sort_str_value).at_least(2).times.and_call_original
216
- expect(sdb.doc_hash_from_mods[:creation_year_isi]).to eq '1500'
218
+ expect(sdb.smods_rec).to receive(:year_int).at_least(2).times.and_call_original
219
+ expect(sdb.doc_hash_from_mods[:creation_year_isi]).to eq 1500
217
220
  end
218
- RSpec.shared_examples 'expected for dateCreated' do |mods_field_val, exp_val|
221
+ RSpec.shared_examples 'expected (dateCreated)' do |mods_field_val, exp_val|
219
222
  it "#{exp_val} for #{mods_field_val}" do
220
223
  m = mods_origin_info_start_str +
221
224
  "<dateCreated>#{mods_field_val}</dateCreated>" +
@@ -224,58 +227,39 @@ describe GDor::Indexer::ModsFields do
224
227
  expect(sdb.doc_hash_from_mods[:creation_year_isi]).to eq exp_val
225
228
  end
226
229
  end
227
- it_behaves_like 'expected for dateCreated', '1945', '1945'
228
- # note that it removes leading zeros
229
- it_behaves_like 'expected for dateCreated', '945', '945'
230
- it_behaves_like 'expected for dateCreated', '66', '66'
231
- it_behaves_like 'expected for dateCreated', '5', '5'
232
- it_behaves_like 'expected for dateCreated', '0', '0'
233
- it_behaves_like 'expected for dateCreated', '-4', '-4'
234
- it_behaves_like 'expected for dateCreated', '-15', '-15'
235
- it_behaves_like 'expected for dateCreated', '-666', '-666'
236
- it_behaves_like 'expected for dateCreated', '16--', '1600'
237
- it_behaves_like 'expected for dateCreated', '9--', '900'
238
- it_behaves_like 'expected for dateCreated', '19th century', '1800'
239
- it_behaves_like 'expected for dateCreated', '9th century', '800'
240
- it_behaves_like 'expected for dateCreated', 'blah June 4, 1594; blah 1596', '1594'
241
- it_behaves_like 'expected for dateCreated', 'Aug. 3rd, 1886', '1886'
242
- it_behaves_like 'expected for dateCreated', 'Aug. 3rd, [18]86?', '1886'
243
- it_behaves_like 'expected for dateCreated', 'early 1890s', '1890'
244
- it_behaves_like 'expected for dateCreated', '1865-6', '1865'
245
- # note: B.C. becomes a regular negative number
246
- it_behaves_like 'expected for dateCreated', '300 B.C.', '-300'
230
+ it_behaves_like 'expected (dateCreated)', '1945', 1945
231
+ it_behaves_like 'expected (dateCreated)', '945', 945
232
+ it_behaves_like 'expected (dateCreated)', '66', 66
233
+ it_behaves_like 'expected (dateCreated)', '5', 5
234
+ it_behaves_like 'expected (dateCreated)', '0', 0
235
+ it_behaves_like 'expected (dateCreated)', '16--', 1600
236
+ it_behaves_like 'expected (dateCreated)', '9--', 900
237
+ it_behaves_like 'expected (dateCreated)', 'blah blah 1945 blah blah', 1945
238
+ it_behaves_like 'expected (dateCreated)', '19th century', 1800
239
+ it_behaves_like 'expected (dateCreated)', '9th century', 800
240
+ it_behaves_like 'expected (dateCreated)', 'blah June 4, 1594; blah 1596', 1594
241
+ it_behaves_like 'expected (dateCreated)', 'Aug. 3rd, 1886', 1886
242
+ it_behaves_like 'expected (dateCreated)', 'Aug. 3rd, [18]86? foo bar', 1886
243
+ it_behaves_like 'expected (dateCreated)', 'early 1890s', 1890
244
+ it_behaves_like 'expected (dateCreated)', '1865-6', 1865
245
+ it_behaves_like 'expected (dateCreated)', '-4', -4
246
+ it_behaves_like 'expected (dateCreated)', '-15', -15
247
+ it_behaves_like 'expected (dateCreated)', '-666', -666
248
+ it_behaves_like 'expected (dateCreated)', '300 B.C.', -300
247
249
  end
248
250
 
249
251
  context 'publication_year_isi' do
250
- it 'publication_year_isi calls Stanford::Mods::Record pub_date_best_sort_str_value for dateIssued elements' do
252
+ it 'publication_year_isi calls Stanford::Mods::Record year_int for dateIssued elements' do
251
253
  m = mods_origin_info_start_str +
252
254
  "<dateCreated qualifier='approximate'>1500</dateCreated>
253
255
  <dateIssued qualifier='approximate'>2000</dateIssued>" +
254
256
  mods_origin_info_end_str
255
257
  sdb = sdb_for_mods(m)
256
- expect(sdb.smods_rec).to receive(:pub_date_best_sort_str_value).at_least(2).times.and_call_original
257
- expect(sdb.doc_hash_from_mods[:publication_year_isi]).to eq '2000'
258
+ expect(sdb.smods_rec).to receive(:year_int).at_least(2).times.and_call_original
259
+ expect(sdb.doc_hash_from_mods[:publication_year_isi]).to eq 2000
258
260
  end
259
- it_behaves_like 'expected', :publication_year_isi, '1945', '1945'
260
- # note that it removes leading zeros
261
- it_behaves_like 'expected', :publication_year_isi, '945', '945'
262
- it_behaves_like 'expected', :publication_year_isi, '66', '66'
263
- it_behaves_like 'expected', :publication_year_isi, '5', '5'
264
- it_behaves_like 'expected', :publication_year_isi, '0', '0'
265
- it_behaves_like 'expected', :publication_year_isi, '-4', '-4'
266
- it_behaves_like 'expected', :publication_year_isi, '-15', '-15'
267
- it_behaves_like 'expected', :publication_year_isi, '-666', '-666'
268
- it_behaves_like 'expected', :publication_year_isi, '16--', '1600'
269
- it_behaves_like 'expected', :publication_year_isi, '9--', '900'
270
- it_behaves_like 'expected', :publication_year_isi, '19th century', '1800'
271
- it_behaves_like 'expected', :publication_year_isi, '9th century', '800'
272
- it_behaves_like 'expected', :publication_year_isi, 'blah June 4, 1594; blah 1596', '1594'
273
- it_behaves_like 'expected', :publication_year_isi, 'Aug. 3rd, 1886', '1886'
274
- it_behaves_like 'expected', :publication_year_isi, 'Aug. 3rd, [18]86?', '1886'
275
- it_behaves_like 'expected', :publication_year_isi, 'early 1890s', '1890'
276
- it_behaves_like 'expected', :publication_year_isi, '1865-6', '1865'
277
- # note: B.C. becomes a regular negative number
278
- it_behaves_like 'expected', :publication_year_isi, '300 B.C.', '-300'
261
+ it_behaves_like 'pub year int (dateIssued)', :publication_year_isi
262
+ it_behaves_like 'pub year int (dateIssued) for B.C. years', :publication_year_isi
279
263
  end
280
264
  end # publication date fields
281
265
 
@@ -285,22 +269,22 @@ describe GDor::Indexer::ModsFields do
285
269
  expect(sdb.smods_rec).to receive(:pub_date_display)
286
270
  sdb.doc_hash_from_mods[:imprint_display]
287
271
  end
288
- it_behaves_like 'expected', :imprint_display, '1945', '1945'
289
- it_behaves_like 'expected', :imprint_display, '945', '945'
290
- it_behaves_like 'expected', :imprint_display, '66', '66'
291
- it_behaves_like 'expected', :imprint_display, '5', '5'
292
- it_behaves_like 'expected', :imprint_display, '0', '0'
293
- it_behaves_like 'expected', :imprint_display, '-4', '-4'
294
- it_behaves_like 'expected', :imprint_display, '-15', '-15'
295
- it_behaves_like 'expected', :imprint_display, '-666', '-666'
296
- it_behaves_like 'expected', :imprint_display, '16--', '16--'
297
- it_behaves_like 'expected', :imprint_display, '9--', '9--'
298
- it_behaves_like 'expected', :imprint_display, '19th century', '19th century'
299
- it_behaves_like 'expected', :imprint_display, '9th century', '9th century'
300
- it_behaves_like 'expected', :imprint_display, 'blah June 4, 1594; blah 1596', 'blah June 4, 1594; blah 1596'
301
- it_behaves_like 'expected', :imprint_display, 'Aug. 3rd, 1886', 'Aug. 3rd, 1886'
302
- it_behaves_like 'expected', :imprint_display, 'Aug. 3rd, [18]86?', 'Aug. 3rd, [18]86?'
303
- it_behaves_like 'expected', :imprint_display, 'early 1890s', 'early 1890s'
304
- it_behaves_like 'expected', :imprint_display, '1865-6', '1865-6'
272
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '1945', '1945'
273
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '945', '945'
274
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '66', '66'
275
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '5', '5'
276
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '0', '0'
277
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '-4', '-4'
278
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '-15', '-15'
279
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '-666', '-666'
280
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '16--', '16--'
281
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '9--', '9--'
282
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '19th century', '19th century'
283
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '9th century', '9th century'
284
+ it_behaves_like 'expected (dateIssued)', :imprint_display, 'blah June 4, 1594; blah 1596', 'blah June 4, 1594; blah 1596'
285
+ it_behaves_like 'expected (dateIssued)', :imprint_display, 'Aug. 3rd, 1886', 'Aug. 3rd, 1886'
286
+ it_behaves_like 'expected (dateIssued)', :imprint_display, 'Aug. 3rd, [18]86?', 'Aug. 3rd, [18]86?'
287
+ it_behaves_like 'expected (dateIssued)', :imprint_display, 'early 1890s', 'early 1890s'
288
+ it_behaves_like 'expected (dateIssued)', :imprint_display, '1865-6', '1865-6'
305
289
  end
306
290
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gdor-indexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-01-07 00:00:00.000000000 Z
13
+ date: 2016-01-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: harvestdor-indexer
@@ -32,14 +32,14 @@ dependencies:
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 1.3.4
35
+ version: 1.4.0
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 1.3.4
42
+ version: 1.4.0
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: nokogiri
45
45
  requirement: !ruby/object:Gem::Requirement