@@ -19,6 +19,99 @@ namespace :blacklight do
1919 end
2020 end
2121
22- end
22+ namespace :check do
23+ desc "Check the Solr connection and controller configuration"
24+ task :solr , [ :controller_name ] => [ :environment ] do |_ , args |
25+ errors = 0
26+ verbose = ENV . fetch ( 'VERBOSE' , false ) . present?
27+
28+ puts "[#{ Blacklight . solr . uri } ]"
29+
30+ print " - admin/ping: "
31+ begin
32+ response = Blacklight . solr . send_and_receive 'admin/ping' , { }
33+ puts response [ 'status' ]
34+ errors += 1 unless response [ 'status' ] == "OK"
35+ rescue Exception => e
36+ errors += 1
37+ puts e . to_s
38+ end
39+
40+ exit 1 if errors > 0
41+ end
42+
43+ task :controller , [ :controller_name ] => [ :environment ] do |_ , args |
44+ errors = 0
45+ verbose = ENV . fetch ( 'VERBOSE' , false ) . present?
46+ controller = args [ :controller_name ] . constantize . new if args [ :controller_name ]
47+ controller ||= CatalogController . new
48+
49+ puts "[#{ controller . class . to_s } ]"
50+
51+ print " - find: "
52+
53+ begin
54+ response = controller . find q : '{!lucene}*:*'
55+ if response . header [ 'status' ] == 0
56+ puts "OK"
57+ else
58+ errors += 1
59+ end
60+
61+ if verbose
62+ puts "\t status: #{ response . header [ 'status' ] } "
63+ puts "\t numFound: #{ response . response [ 'numFound' ] } "
64+ puts "\t doc count: #{ response . docs . length } "
65+ puts "\t facet fields: #{ response . facets . length } "
66+ end
67+ rescue Exception => e
68+ errors += 1
69+ puts e . to_s
70+ end
71+
72+ print " - get_search_results: "
2373
74+ begin
75+ response , docs = controller . get_search_results ( { } , q : '{!lucene}*:*' )
76+
77+ if response . header [ 'status' ] == 0 and docs . length > 0
78+ puts "OK"
79+ else
80+ errors += 1
81+ end
82+
83+ if verbose
84+ puts "\t status: #{ response . header [ 'status' ] } "
85+ puts "\t numFound: #{ response . response [ 'numFound' ] } "
86+ puts "\t doc count: #{ docs . length } "
87+ puts "\t facet fields: #{ response . facets . length } "
88+ end
89+ rescue Exception => e
90+ errors += 1
91+ puts e . to_s
92+ end
93+
94+ print " - get_solr_response_for_doc_id: "
95+
96+ begin
97+ doc_id = response . docs . first [ SolrDocument . unique_key ]
98+ response , doc = controller . get_solr_response_for_doc_id doc_id
2499
100+ if response . header [ 'status' ] == 0 and doc
101+ puts "OK"
102+ else
103+ errors += 1
104+ end
105+
106+ if verbose
107+ puts "\t status: #{ response . header [ 'status' ] } "
108+ end
109+ rescue Exception => e
110+ errors += 1
111+ puts e . to_s
112+ end
113+
114+ exit 1 if errors > 0
115+ end
116+ end
117+ end
0 commit comments