Skip to content

Apache Lucene open-source search software

add new indexinfo request capability

Erik Hatcherd5bc3ec4ba58
diff --git a/client/ruby/solrb/lib/solr/request.rb b/client/ruby/solrb/lib/solr/request.rb
index a01d849763f..f0108a3aad7 100755
--- a/client/ruby/solrb/lib/solr/request.rb
+++ b/client/ruby/solrb/lib/solr/request.rb
@@ -18,3 +18,4 @@ require 'solr/request/ping'
require 'solr/request/select'
require 'solr/request/standard'
require 'solr/request/update'
+require 'solr/request/index_info'
diff --git a/client/ruby/solrb/lib/solr/request/index_info.rb b/client/ruby/solrb/lib/solr/request/index_info.rb
new file mode 100755
index 00000000000..b97459ecfda
--- /dev/null
+++ b/client/ruby/solrb/lib/solr/request/index_info.rb
@@ -0,0 +1,21 @@
+# 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+module Solr
+ module Request
+ class IndexInfo < Solr::Request::Select
+ def initialize
+ super('indexinfo')
+ end
+ end
+ end
+end
diff --git a/client/ruby/solrb/lib/solr/response.rb b/client/ruby/solrb/lib/solr/response.rb
index 6394c592e10..4f6b3e97f72 100755
--- a/client/ruby/solrb/lib/solr/response.rb
+++ b/client/ruby/solrb/lib/solr/response.rb
@@ -18,3 +18,4 @@ require 'solr/response/add_document'
require 'solr/response/standard'
require 'solr/response/commit'
require 'solr/response/delete'
+require 'solr/response/index_info'
\ No newline at end of file
diff --git a/client/ruby/solrb/lib/solr/response/base.rb b/client/ruby/solrb/lib/solr/response/base.rb
index 7d492c2cab4..300d8f24eab 100644
--- a/client/ruby/solrb/lib/solr/response/base.rb
+++ b/client/ruby/solrb/lib/solr/response/base.rb
@@ -28,6 +28,8 @@ module Solr
raise Solr::Exception.new("unknown response format: #{request.response_format}" )
end
+ # TODO: Factor out this case... perhaps the request object should provide the response class instead? Or dynamically align by class name?
+ # Maybe the request itself could have the response handling features that get mixed in with a single general purpose response object?
case request
when Solr::Request::Ping
return Solr::Response::Ping.new(raw)
@@ -39,6 +41,8 @@ module Solr
return Solr::Response::Standard.new(raw)
when Solr::Request::Delete
return Solr::Response::Delete.new(raw)
+ when Solr::Request::IndexInfo
+ return Solr::Response::IndexInfo.new(raw)
else
raise Solr::Exception.new("unknown request type: #{request.class}")
end
diff --git a/client/ruby/solrb/lib/solr/response/index_info.rb b/client/ruby/solrb/lib/solr/response/index_info.rb
new file mode 100755
index 00000000000..98c20b74115
--- /dev/null
+++ b/client/ruby/solrb/lib/solr/response/index_info.rb
@@ -0,0 +1,30 @@
+# 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
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+module Solr
+ module Response
+ class IndexInfo < Solr::Response::Ruby
+ def initialize(ruby_code)
+ super(ruby_code)
+ end
+
+ def num_docs
+ return @data['index']['numDocs']
+ end
+
+ def field_names
+ return @data['fields'].keys
+ end
+
+ end
+ end
+end
diff --git a/client/ruby/solrb/solr/solr/conf/solrconfig.xml b/client/ruby/solrb/solr/solr/conf/solrconfig.xml
index 451f23a8bb1..ac3416b4c4e 100755
--- a/client/ruby/solrb/solr/solr/conf/solrconfig.xml
+++ b/client/ruby/solrb/solr/solr/conf/solrconfig.xml
@@ -224,6 +224,7 @@
The "standard" request handler is the default and will be used if qt
is not specified in the request.
-->
+ <requestHandler name="indexinfo" class="solr.IndexInfoRequestHandler"/>
<requestHandler name="standard" class="solr.StandardRequestHandler">
<!-- default values for query parameters -->
<lst name="defaults">
diff --git a/client/ruby/solrb/solr/webapps/solr.war b/client/ruby/solrb/solr/webapps/solr.war
index f07c16e9f93..9dfbf082113 100644
Binary files a/client/ruby/solrb/solr/webapps/solr.war and b/client/ruby/solrb/solr/webapps/solr.war differ
diff --git a/client/ruby/solrb/test/conf/solrconfig.xml b/client/ruby/solrb/test/conf/solrconfig.xml
index 451f23a8bb1..ac3416b4c4e 100755
--- a/client/ruby/solrb/test/conf/solrconfig.xml
+++ b/client/ruby/solrb/test/conf/solrconfig.xml
@@ -224,6 +224,7 @@
The "standard" request handler is the default and will be used if qt
is not specified in the request.
-->
+ <requestHandler name="indexinfo" class="solr.IndexInfoRequestHandler"/>
<requestHandler name="standard" class="solr.StandardRequestHandler">
<!-- default values for query parameters -->
<lst name="defaults">
diff --git a/client/ruby/solrb/test/functional/server_test.rb b/client/ruby/solrb/test/functional/server_test.rb
index 52a93969d39..58256dafcde 100644
--- a/client/ruby/solrb/test/functional/server_test.rb
+++ b/client/ruby/solrb/test/functional/server_test.rb
@@ -91,7 +91,7 @@ class ServerTest < Test::Unit::TestCase
def test_escaping
doc = Solr::Document.new :id => 47, :ruby_text => 'puts "ouch!"'
- @connection.send(Solr::Request::AddDocument.new(doc))
+ @connection.add(doc)
@connection.commit
request = Solr::Request::Standard.new :query => 'ouch'
@@ -119,6 +119,14 @@ class ServerTest < Test::Unit::TestCase
assert_equal "ERROR:unknown field 'bogus'", response.status_message
end
+ def test_index_info
+ doc = {:id => 999, :test_index_facet => 'value'}
+ @connection.add(doc)
+ info = @connection.send(Solr::Request::IndexInfo.new)
+ assert info.field_names.include?("id") && info.field_names.include?("test_index_facet")
+ assert_equal 1, info.num_docs
+ end
+
# wipe the index clean
def clean
@connection.delete_by_query('[* TO *]')