Sha256: 7b3682c1c0e0cea2c3b3ee16815476c83c23c3676ad25ae10e0ec2bf0e0fba6f

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

# indexes the publication_date_start and _end fields
module NewspaperWorks
  module IndexesPublicationDateRange
    # adds publication date start to solr_doc Hash in Solr datetime format
    #
    # @param pubdate [String] publication start date
    # @param solr_doc [Hash] the hash of field data to be pushed to Solr
    def index_pubdate_start(pubdate, solr_doc)
      case pubdate
      when /\A\d{4}\z/
        solr_doc['publication_date_start_dtsi'] = "#{pubdate}-01-01".to_datetime
      when /\A\d{4}-\d{2}\z/
        solr_doc['publication_date_start_dtsi'] = "#{pubdate}-01".to_datetime
      end
      solr_doc['publication_date_start_ssi'] = nil
    end

    # adds publication date end to solr_doc Hash in Solr datetime format
    #
    # @param pubdate [String] publication end date
    # @param solr_doc [Hash] the hash of field data to be pushed to Solr
    def index_pubdate_end(pubdate, solr_doc)
      end_time = 'T23:59:59Z'
      case pubdate
      when /\A\d{4}\z/
        solr_doc['publication_date_end_dtsi'] = "#{pubdate}-12-31#{end_time}"
      when /\A\d{4}-\d{2}\z/
        date_split = pubdate.split('-')
        end_day = Date.new(date_split[0].to_i, date_split[1].to_i, -1).strftime('%d')
        solr_doc['publication_date_end_dtsi'] = "#{pubdate}-#{end_day}#{end_time}"
      end
      solr_doc['publication_date_end_ssi'] = nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
newspaper_works-1.0.1 app/indexers/concerns/newspaper_works/indexes_publication_date_range.rb
newspaper_works-1.0.0 app/indexers/concerns/newspaper_works/indexes_publication_date_range.rb
newspaper_works-0.1.0 app/indexers/concerns/newspaper_works/indexes_publication_date_range.rb