diff --git a/lib/railties/blacklight.rake b/lib/railties/blacklight.rake index 7c10817be1..27565e4769 100644 --- a/lib/railties/blacklight.rake +++ b/lib/railties/blacklight.rake @@ -19,6 +19,99 @@ namespace :blacklight do end end -end + namespace :check do + desc "Check the Solr connection and controller configuration" + task :solr, [:controller_name] => [:environment] do |_, args| + errors = 0 + verbose = ENV.fetch('VERBOSE', false).present? + + puts "[#{Blacklight.solr.uri}]" + + print " - admin/ping: " + begin + response = Blacklight.solr.send_and_receive 'admin/ping', {} + puts response['status'] + errors += 1 unless response['status'] == "OK" + rescue Exception => e + errors += 1 + puts e.to_s + end + + exit 1 if errors > 0 + end + + task :controller, [:controller_name] => [:environment] do |_, args| + errors = 0 + verbose = ENV.fetch('VERBOSE', false).present? + controller = args[:controller_name].constantize.new if args[:controller_name] + controller ||= CatalogController.new + + puts "[#{controller.class.to_s}]" + + print " - find: " + + begin + response = controller.find q: '{!lucene}*:*' + if response.header['status'] == 0 + puts "OK" + else + errors += 1 + end + + if verbose + puts "\tstatus: #{response.header['status']}" + puts "\tnumFound: #{response.response['numFound']}" + puts "\tdoc count: #{response.docs.length}" + puts "\tfacet fields: #{response.facets.length}" + end + rescue Exception => e + errors += 1 + puts e.to_s + end + + print " - get_search_results: " + begin + response, docs = controller.get_search_results({}, q: '{!lucene}*:*') + + if response.header['status'] == 0 and docs.length > 0 + puts "OK" + else + errors += 1 + end + + if verbose + puts "\tstatus: #{response.header['status']}" + puts "\tnumFound: #{response.response['numFound']}" + puts "\tdoc count: #{docs.length}" + puts "\tfacet fields: #{response.facets.length}" + end + rescue Exception => e + errors += 1 + puts e.to_s + end + + print " - get_solr_response_for_doc_id: " + + begin + doc_id = response.docs.first[SolrDocument.unique_key] + response, doc = controller.get_solr_response_for_doc_id doc_id + if response.header['status'] == 0 and doc + puts "OK" + else + errors += 1 + end + + if verbose + puts "\tstatus: #{response.header['status']}" + end + rescue Exception => e + errors += 1 + puts e.to_s + end + + exit 1 if errors > 0 + end + end +end