Class: ActiveFedora::Indexing::DefaultDescriptors

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/indexing/default_descriptors.rb

Class Method Summary collapse

Class Method Details

.dateableObject

Takes fields which are stored as strings, but we want indexed as dates. (e.g. “November 6th, 2012”) produces suffixes:

_dtsim - for dates


23
24
25
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 23

def self.dateable
  @dateable ||= Descriptor.new(:date, :stored, :indexed, :multivalued, converter: dateable_converter)
end

.dateable_converterObject



104
105
106
107
108
109
110
111
112
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 104

def dateable_converter
  lambda do |_type|
    lambda do |val|
      iso8601_date(Date.parse(val))
    rescue ArgumentError
      nil
    end
  end
end

.displayableObject

Produces _ssm suffix



55
56
57
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 55

def self.displayable
  @displayable ||= Descriptor.new(:string, :stored, :multivalued)
end

.facetableObject

Produces _sim suffix



28
29
30
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 28

def self.facetable
  @facetable ||= Descriptor.new(:string, :indexed, :multivalued)
end

.iso8601_date(value) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 114

def iso8601_date(value)
  if value.is_a?(Date) || value.is_a?(Time)
    DateTime.parse(value.to_s).to_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
  elsif !value.empty?
    DateTime.parse(value).to_time.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
  end
rescue ArgumentError
  raise ArgumentError, "Unable to parse `#{value}' as a date-time object"
end

.searchableObject

The suffix produced depends on the type parameter – produces suffixes:

_teim - for strings or text fields
_dtim - for dates
_iim - for integers


16
17
18
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 16

def self.searchable
  @searchable ||= Descriptor.new(searchable_field_definition, converter: searchable_converter, requires_type: true)
end

.searchable_converterObject



95
96
97
98
99
100
101
102
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 95

def searchable_converter
  lambda do |type|
    case type
    when :date, :time
      ->(val) { iso8601_date(val) }
    end
  end
end

.searchable_field_definitionObject



69
70
71
72
73
74
75
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 69

def searchable_field_definition
  lambda do |type|
    type = :text_en if [:string, :text].include?(type) # for backwards compatibility with old solr schema
    vals = [type, :indexed, :multivalued]
    vals
  end
end

.simpleObject



64
65
66
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 64

def self.simple
  @simple ||= Descriptor.new(->(field_type) { [field_type, :indexed] })
end

.sortableObject

The suffix produced depends on the type parameter – produces suffixes:

_tei - for text fields
_si - for strings
_dti - for dates
_ii - for integers


43
44
45
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 43

def self.sortable
  @sortable ||= Descriptor.new(sortable_field_definition, converter: searchable_converter, requires_type: true)
end

.sortable_field_definitionObject



88
89
90
91
92
93
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 88

def sortable_field_definition
  lambda do |type|
    vals = [type, :indexed]
    vals
  end
end

.stored_searchableObject

The suffix produced depends on the type parameter – produces suffixes:

_tesim - for strings or text fields
_dtsim - for dates
_isim - for integers


8
9
10
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 8

def self.stored_searchable
  @stored_searchable ||= Descriptor.new(stored_searchable_field_definition, converter: searchable_converter, requires_type: true)
end

.stored_searchable_field_definitionObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 77

def stored_searchable_field_definition
  lambda do |type|
    type = :text_en if [:string, :text].include?(type) # for backwards compatibility with old solr schema
    if type == :boolean
      [type, :indexed, :stored]
    else
      [type, :indexed, :stored, :multivalued]
    end
  end
end

.stored_sortableObject

Fields that are both stored and sortable Produces _ssi suffix if field_type is string Produces _dtsi suffix if field_type is date



50
51
52
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 50

def self.stored_sortable
  @stored_sortable ||= Descriptor.new(->(field_type) { [field_type, :stored, :indexed] }, converter: searchable_converter)
end

.symbolObject

Produces _ssim suffix This is useful for when you only want to match whole words, such as user/group names from the the rightsMetadata datastream



34
35
36
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 34

def self.symbol
  @symbol ||= Descriptor.new(:string, :stored, :indexed, :multivalued)
end

.unstemmed_searchableObject

Produces _tim suffix (used to be _unstem)



60
61
62
# File 'lib/active_fedora/indexing/default_descriptors.rb', line 60

def self.unstemmed_searchable
  @unstemmed_searchable ||= Descriptor.new(:text, :indexed, :multivalued)
end