Skip to content

Commit

Permalink
Merge pull request #19 from sul-dlss/master-wip
Browse files Browse the repository at this point in the history
Change in mechanism for determining dates for display only and for indexing, sorting, and faceting
  • Loading branch information
ndushay committed Jan 23, 2015
2 parents 40e4946 + 6f2501d commit b46ee6e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 73 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
@@ -1,11 +1,13 @@
language: ruby
script: rake rspec
rvm:
- 2.1.1
- 2.2.0
- 2.1.5
- 2.0.0
- 1.9.3
- ruby-head
- jruby-19mode # JRuby in 1.9 mode
- jruby-1.7.9-d19 # fails after 1.7.10 for some reason
# - jruby-19mode # JRuby in 1.9 mode
# - jruby-head # failing 2014-07
notifications:
email:
Expand Down
1 change: 1 addition & 0 deletions README.rdoc
Expand Up @@ -59,6 +59,7 @@ Example Using SearchWorks Mixins:
6. Create new Pull Request

== Releases
* <b>1.1.0</b> Changed mechanism for determining dates for display only and for indexing, sorting, and faceting and removed deprecated pub_date_group method
* <b>1.0.3</b> format_main value 'Article' is now 'Book'
* <b>1.0.2</b> add format_main and sw_genre tests to searchworks.rb
* <b>1.0.1</b> sw_title_display keeps appropriate trailing punct more or less per spec in solrmarc-sw sw_index.properties
Expand Down
87 changes: 45 additions & 42 deletions lib/stanford-mods/searchworks.rb
Expand Up @@ -383,52 +383,22 @@ def place
vals
end

# For the date display only, the first place to look is in the dates without encoding=marc array.
# If no such dates, select the first date in the pub_dates array. Otherwise return nil
# @return [String] value for the pub_date_display Solr field for this document or nil if none
def pub_date_display
if pub_dates
pub_dates.first
else
nil
end
end

# @return [Array<String>] values for the pub_date_group_facet
# @deprecated
def pub_date_groups year
if not year
return dates_no_marc_encoding.first unless dates_no_marc_encoding.empty?
return pub_dates.first unless pub_dates.empty?
return nil
end
year=year.to_i
current_year=Time.new.year.to_i
result = []
if year >= current_year - 1
result << "This year"
else
if year >= current_year - 3
result << "Last 3 years"
else
if year >= current_year - 10
result << "Last 10 years"
else
if year >= current_year - 50
result << "Last 50 years"
else
result << "More than 50 years ago"
end
end
end
end
end

#get the dates from dateIssued, and dateCreated merged into 1 array.
# @return [Array<String>] values for the issue_date_display Solr field for this document or nil if none
# For the date indexing, sorting and faceting, the first place to look is in the dates with encoding=marc array.
# If that doesn't exist, look in the dates without encoding=marc array. Otherwise return nil
# @return [Array<String>] values for the date Solr field for this document or nil if none
def pub_dates
vals = self.term_values([:origin_info,:dateIssued])
if vals
vals = vals.concat self.term_values([:origin_info,:dateCreated]) unless not self.term_values([:origin_info,:dateCreated])
else
vals = self.term_values([:origin_info,:dateCreated])
end
vals and vals.empty? ? nil : vals
return dates_marc_encoding unless dates_marc_encoding.empty?
return dates_no_marc_encoding unless dates_no_marc_encoding.empty?
return nil
end

def is_number?(object)
Expand Down Expand Up @@ -813,7 +783,40 @@ def get_single_digit_century dates
end
end
return nil
end
end

# @return [Array<String>] dates from dateIssued and dateCreated tags from origin_info with encoding="marc"
def dates_marc_encoding
split_date_encodings unless @dates_marc_encoding
return @dates_marc_encoding
end

# @return [Array<String>] dates from dateIssued and dateCreated tags from origin_info with encoding not "marc"
def dates_no_marc_encoding
split_date_encodings unless @dates_no_marc_encoding
return @dates_no_marc_encoding
end

# Populate @dates_marc_encoding and @dates_no_marc_encoding from dateIssued and dateCreated tags from origin_info
# with and without encoding=marc
def split_date_encodings
@dates_marc_encoding = []
@dates_no_marc_encoding = []
self.origin_info.dateIssued.each { |di|
if di.encoding == "marc"
@dates_marc_encoding << di.text
else
@dates_no_marc_encoding << di.text
end
}
self.origin_info.dateCreated.each { |dc|
if dc.encoding == "marc"
@dates_marc_encoding << dc.text
else
@dates_no_marc_encoding << dc.text
end
}
end
end # class Record
end # Module Mods
end # Module Stanford
2 changes: 1 addition & 1 deletion lib/stanford-mods/version.rb
@@ -1,6 +1,6 @@
module Stanford
module Mods
# this is the Ruby Gem version
VERSION = "1.0.3"
VERSION = "1.1.0"
end
end
39 changes: 11 additions & 28 deletions spec/searchworks_pub_dates_spec.rb
Expand Up @@ -122,6 +122,16 @@
@smods_rec.pub_date_sort.should =='0800'
@smods_rec.pub_date_facet.should == '9th century'
end
it 'should use the dateIssued without marc encoding for pub_date_display and the one with marc encoding for indexing, sorting and faceting' do
m = "<mods #{@ns_decl}><originInfo><dateIssued>[186-?]</dateIssued><dateIssued encoding=\"marc\">1860</dateIssued><issuance>monographic</issuance></originInfo>"
@smods_rec = Stanford::Mods::Record.new
@smods_rec.from_str(m)

@smods_rec.pub_date_display.should == '[186-?]'
@smods_rec.pub_date.should =='1860'
@smods_rec.pub_date_sort.should =='1860'
@smods_rec.pub_date_facet.should == '1860'
end
end # pub_date

context "dates with u notation (198u, 19uu)" do
Expand Down Expand Up @@ -204,31 +214,4 @@
end
end

context "pub_date_groups" do
it 'should generate the groups' do
m = "<mods #{@ns_decl}><originInfo>
<dateCreated>1904</dateCreated>
</originInfo></mods>"
@smods_rec = Stanford::Mods::Record.new
@smods_rec.from_str(m)
@smods_rec.pub_date_groups(1904).should == ['More than 50 years ago']
end
it 'should work for a modern date too' do
m = "<mods #{@ns_decl}><originInfo>
<dateCreated>1904</dateCreated>
</originInfo></mods>"
@smods_rec = Stanford::Mods::Record.new
@smods_rec.from_str(m)
@smods_rec.pub_date_groups(2013).should == ["This year"]
end
it 'should work ok given a nil date' do
m = "<mods #{@ns_decl}><originInfo>
<dateCreated>1904</dateCreated>
</originInfo></mods>"
@smods_rec = Stanford::Mods::Record.new
@smods_rec.from_str(m)
@smods_rec.pub_date_groups(nil).should == nil
end
end #context pub date groups

end
end

0 comments on commit b46ee6e

Please sign in to comment.