Skip to content

Instantly share code, notes, and snippets.

@rsinger
Created January 7, 2010 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsinger/270920 to your computer and use it in GitHub Desktop.
Save rsinger/270920 to your computer and use it in GitHub Desktop.
Ruby script to check which MARC records are missing from a Solr index.
require 'rubygems'
# Be sure to have the latest version of rubygems and run:
# sudo gem install rsolr
# sudo gem install marc
require 'rsolr'
require 'marc'
# Set the following three vars to whatever applies locally.
solr = RSolr.connect :url=>'http://localhost:8080/solr'
marc_path = '/path/to/marc/files/'
skipped_marc_out = '/path/to/skipped_marc_out.mrc'
marc_out = MARC::Writer.new(skipped_marc_out)
Dir.open(marc_path).each do | file |
MARC::ForgivingReader.new(open("#{marc_path}#{file}")).each do | record |
ctrl = record['001'].value
response = solr.select :q=>"id:#{ctrl}"
unless response['response']['numFound'] > 0
marc_out.write(record)
end
end
end
marc_out.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment