Skip to content

Commit

Permalink
add blacklight:check rake tasks for checking solr and controller conf…
Browse files Browse the repository at this point in the history
…igurations; fixes #812
  • Loading branch information
cbeer committed Mar 20, 2014
1 parent 949faab commit a4040cb
Showing 1 changed file with 94 additions and 1 deletion.
95 changes: 94 additions & 1 deletion lib/railties/blacklight.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a4040cb

Please sign in to comment.