Sha256: 0c2aa32260ff62823dff787f74ebf3b9e80f936819f5dca0c9cf2f3a26e8a1cf

Contents?: true

Size: 1.47 KB

Versions: 5

Compression:

Stored size: 1.47 KB

Contents

class Solrizer::FieldMapper::Default

  id_field 'id'
  index_as :searchable do |t|
    t.default :suffix => '_t'
    t.date    :suffix => '_dt'
    t.string  :suffix => '_t'
    t.text    :suffix => '_t'
    t.symbol  :suffix => '_s'
    t.integer :suffix => '_i'
    t.long    :suffix => '_l'
    t.boolean :suffix => '_b'
    t.float   :suffix => '_f'
    t.double  :suffix => '_d'
  end
  index_as :displayable,          :suffix => '_display'
  index_as :facetable,            :suffix => '_facet'
  index_as :sortable,             :suffix => '_sort'
  index_as :unstemmed_searchable, :suffix => '_unstem_search'
  index_as :converted_date do |t|
    t.default :suffix => '_dt' do |value|
      pbcore_date(value)
    end
  end

  # We assume that all dates are in ISO 8601 format, but sometimes users may only
  # specify a year or a year and month.  This method adds a -01-01 or -01 respectively
  # defaulting to Jan. 1st for dates that are only a year, and the first day of the 
  # month for dates that are only a year and a month.
  # NOTE: This only applies to the date as it is stored in solr.  The original value
  # as entered by the user is still maintained in the xml.
  def self.pbcore_date(date, value = String.new)
    return date if date.empty?
    if date.match(/^[0-9]{4,4}$/)
      value = date + "-01-01"
    elsif date.match(/^[0-9]{4,4}-[0-9]{2,2}$/)
      value = date + "-01"
    else 
      value = date  
    end
    return DateTime.parse(value).to_time.utc.iso8601
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hydra-pbcore-1.1.2 lib/custom_mapper.rb
hydra-pbcore-1.1.1 lib/custom_mapper.rb
hydra-pbcore-1.1.0 lib/custom_mapper.rb
hydra-pbcore-1.0.0 lib/custom_mapper.rb
hydra-pbcore-0.1.0 lib/custom_mapper.rb