Class: Solrizer::Fedora::Indexer

Inherits:
Object
  • Object
show all
Defined in:
lib/solrizer/fedora/indexer.rb

Constant Summary collapse

@@unique_id =

Class variables

0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Indexer

This method performs initialization tasks



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/solrizer/fedora/indexer.rb', line 29

def initialize( opts={} )
  @@index_list = false unless defined?(@@index_list)
  @extractor = ::Solrizer::Extractor.new
  
  if opts[:index_full_text] == true || opts[:index_full_text] == "true"
    @index_full_text = true 
  else
    @index_full_text = false 
  end
  
  connect
end

Instance Attribute Details

#extractorObject

The extractor to use. This is usually Solrizer::Extractor



21
22
23
# File 'lib/solrizer/fedora/indexer.rb', line 21

def extractor
  @extractor
end

#index_full_textObject

Boolean or “true” or “false”

tells the indexer whether to index full text or just field values



24
25
26
# File 'lib/solrizer/fedora/indexer.rb', line 24

def index_full_text
  @index_full_text
end

#solrObject

The instance of solr that updates will be written to



18
19
20
# File 'lib/solrizer/fedora/indexer.rb', line 18

def solr
  @solr
end

Class Method Details

.unique_idObject



12
13
14
# File 'lib/solrizer/fedora/indexer.rb', line 12

def self.unique_id
  @@unique_id
end

Instance Method Details

#generate_dates(solr_doc) ⇒ Object

This method generates the month and day facets from the date_t in solr_doc



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/solrizer/fedora/indexer.rb', line 103

def generate_dates(solr_doc)
  
  # This will check for valid dates, but it seems most of the dates are currently invalid....
  #date_check =  /^(19|20)\d\d([- \/.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])/

 #if there is not date_t, add on with easy-to-find value
 if solr_doc[:date_t].nil?
      ::Solrizer::Extractor.insert_solr_field_value(solr_doc, :date_t, "9999-99-99")
 end #if

  # Grab the date value from date_t regardless of wheter it is inside of an array
  # then convert it to a Date object
  date_value =    solr_doc[:date_t]
  if date_value.kind_of? Array
    date_value = date_value.first
  end
  date_obj = Date._parse(date_value)
  
  if date_obj[:mon].nil? 
     ::Solrizer::Extractor.insert_solr_field_value(solr_doc, :month_facet, "99")
  elsif 0 < date_obj[:mon] && date_obj[:mon] < 13
    ::Solrizer::Extractor.insert_solr_field_value(solr_doc, :month_facet, date_obj[:mon].to_s.rjust(2, '0'))
  else
    ::Solrizer::Extractor.insert_solr_field_value(solr_doc, :month_facet, "99")
  end
    
  if  date_obj[:mday].nil?
    ::Solrizer::Extractor.insert_solr_field_value(solr_doc, :day_facet, "99")
  elsif 0 < date_obj[:mday] && date_obj[:mday] < 32   
    ::Solrizer::Extractor.insert_solr_field_value(solr_doc, :day_facet, date_obj[:mday].to_s.rjust(2, '0'))
  else
     ::Solrizer::Extractor.insert_solr_field_value(solr_doc, :day_facet, "99")
  end
  
  return solr_doc
      
end

#index(obj) ⇒ Object

This method adds a document to the Solr search index



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/solrizer/fedora/indexer.rb', line 182

def index( obj )
 # print "Indexing '#{obj.pid}'..."
  begin
    
    solr_doc = create_document( obj )
    
    begin
      solr.add( solr_doc )
      solr.commit
    # rescue
    #   debugger
    end
 
   # puts solr.url
   #puts solr_doc
   #  puts "done"
 
  # rescue Exception => e
  #    p "unable to index #{obj.pid}.  Failed with #{e.inspect}"
  end
 
end