# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'marc'
require 'solr'
$KCODE = 'UTF8'
mapping = {
# :solr_field_name => String
# :solr_field_name => Array of Strings
# :solr_field_name => Proc [Proc operates on record]
# String = 3 digit control field number or 3 digit data field number + subfield letter
:year_facet => Proc.new do |r|
end,
:filename_facet => Proc.new {|r| file_number},
}
if marc_filename =~ /.gz$/
puts "Unzipping data file..."
temp_filename = "/tmp/marc_data_#{file_number}.mrc"
end
count = 0
extracted_data = []
fields.each do |field|
extracted_data << field_instance.value rescue nil
else # data field
subfield = field[3].chr
extracted_data << field_instance[subfield] rescue nil
end
end
end
extracted_data.compact.uniq
end
puts "Indexing #{marc_filename}..."
for record in reader
doc = {}
mapping.each do |key,value|
data = nil
case value
when Proc
data = value.call(record)
when String, Array
data = extract_record_data(record, value)
data = nil if data.empty?
end
doc[key] = data if data
end
puts doc.inspect,"------" if debug
connection.send(Solr::Request::AddDocument.new(doc)) unless debug
count += 1
puts count if count % 100 == 0
end
connection.send(Solr::Request::Commit.new) unless debug
puts "Done"