Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

Enable Solr::Request::Select to work as a general pass through to any registered request handler using /select?..., and a few other minor changes

Erik Hatcher4efd666e2406
diff --git a/client/ruby/solr-ruby/CHANGES.yml b/client/ruby/solr-ruby/CHANGES.yml
index 68fdb302d0d..193a7c7cc99 100644
--- a/client/ruby/solr-ruby/CHANGES.yml
+++ b/client/ruby/solr-ruby/CHANGES.yml
@@ -2,6 +2,8 @@ v0.0.6:
release_date: TBD
changes:
- Added Solr::Request::Spellcheck
+ - Enabled Solr::Requst::Select to work as a general pass through to any registered request handler
+ - Fixed modify_document_test.rb so as to not be brittle with Hash ordering
v0.0.5:
release_date: 2007-08-27
diff --git a/client/ruby/solr-ruby/lib/solr/request/index_info.rb b/client/ruby/solr-ruby/lib/solr/request/index_info.rb
index 30431711fe1..d4eeea54d67 100755
--- a/client/ruby/solr-ruby/lib/solr/request/index_info.rb
+++ b/client/ruby/solr-ruby/lib/solr/request/index_info.rb
@@ -17,6 +17,6 @@ class Solr::Request::IndexInfo < Solr::Request::Select
end
def to_hash
- {:numTerms => 0, :show => 'schema'}.merge(super.to_hash)
+ {:numTerms => 0}.merge(super.to_hash)
end
end
diff --git a/client/ruby/solr-ruby/lib/solr/request/select.rb b/client/ruby/solr-ruby/lib/solr/request/select.rb
index eec4fa71bb8..122c5b71156 100644
--- a/client/ruby/solr-ruby/lib/solr/request/select.rb
+++ b/client/ruby/solr-ruby/lib/solr/request/select.rb
@@ -17,8 +17,9 @@ class Solr::Request::Select < Solr::Request::Base
attr_reader :query_type
- def initialize(qt=nil)
+ def initialize(qt=nil, params={})
@query_type = qt
+ @select_params = params
end
def response_format
@@ -34,7 +35,7 @@ class Solr::Request::Select < Solr::Request::Base
end
def to_hash
- return {:qt => query_type, :wt => 'ruby'}
+ return {:qt => query_type, :wt => 'ruby'}.merge(@select_params)
end
def to_s
diff --git a/client/ruby/solr-ruby/lib/solr/response.rb b/client/ruby/solr-ruby/lib/solr/response.rb
index ce3c0812b3d..72c55fe664c 100755
--- a/client/ruby/solr-ruby/lib/solr/response.rb
+++ b/client/ruby/solr-ruby/lib/solr/response.rb
@@ -23,4 +23,5 @@ require 'solr/response/dismax'
require 'solr/response/commit'
require 'solr/response/delete'
require 'solr/response/index_info'
-require 'solr/response/optimize'
\ No newline at end of file
+require 'solr/response/optimize'
+require 'solr/response/select'
\ No newline at end of file
diff --git a/client/ruby/solr-ruby/lib/solr/response/ruby.rb b/client/ruby/solr-ruby/lib/solr/response/ruby.rb
index 05619b9a20a..6e8f651748c 100644
--- a/client/ruby/solr-ruby/lib/solr/response/ruby.rb
+++ b/client/ruby/solr-ruby/lib/solr/response/ruby.rb
@@ -11,7 +11,7 @@
# limitations under the License.
class Solr::Response::Ruby < Solr::Response::Base
- attr_reader :data
+ attr_reader :data, :header
def initialize(ruby_code)
super
diff --git a/client/ruby/solr-ruby/lib/solr/response/select.rb b/client/ruby/solr-ruby/lib/solr/response/select.rb
new file mode 100755
index 00000000000..8e2185d67de
--- /dev/null
+++ b/client/ruby/solr-ruby/lib/solr/response/select.rb
@@ -0,0 +1,17 @@
+# 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.
+
+class Solr::Response::Select < Solr::Response::Ruby
+ def initialize(ruby_code)
+ super
+ end
+end
diff --git a/client/ruby/solr-ruby/test/unit/modify_document_test.rb b/client/ruby/solr-ruby/test/unit/modify_document_test.rb
index 5760058c2fa..9291dd16623 100755
--- a/client/ruby/solr-ruby/test/unit/modify_document_test.rb
+++ b/client/ruby/solr-ruby/test/unit/modify_document_test.rb
@@ -18,8 +18,7 @@ class ModifyDocumentTest < Test::Unit::TestCase
def test_update_formatting
request = Solr::Request::ModifyDocument.new(:id => 10, :overwrite => {:name => ['val1', 'val2'], :copyfield => nil})
assert_equal :xml, request.response_format
- assert_equal 'update?mode=copyfield:OVERWRITE,name:OVERWRITE', request.handler
-
- assert_match(/<add>[\s]*<doc>[\s]*<field name=["']id['"]>10<\/field>[\s]*<field name=['"]name['"]>val1<\/field>[\s]*<field name=['"]name['"]>val2<\/field>[\s]*<\/doc>[\s]*<\/add>/, request.to_s)
+ assert_match /copyfield\:OVERWRITE/, request.handler
+ assert_match /name\:OVERWRITE/, request.handler
end
end
diff --git a/client/ruby/solr-ruby/test/unit/response_test.rb b/client/ruby/solr-ruby/test/unit/response_test.rb
index 846510c04b8..1496262beed 100644
--- a/client/ruby/solr-ruby/test/unit/response_test.rb
+++ b/client/ruby/solr-ruby/test/unit/response_test.rb
@@ -32,11 +32,12 @@ class ResponseTest < SolrMockBaseTestCase
Solr::Response::Ruby.new(' {...')
end
end
-
- def test_bogus_request_handling
- assert_raise(Solr::Exception) do
- Solr::Response::Base.make_response(Solr::Request::Select.new, "response data")
- end
- end
+
+ # This is now an acceptable use of Select, for the default request handler with no parameters (other than &wt=ruby)
+ # def test_bogus_request_handling
+ # assert_raise(Solr::Exception) do
+ # Solr::Response::Base.make_response(Solr::Request::Select.new, "response data")
+ # end
+ # end
end
diff --git a/client/ruby/solr-ruby/test/unit/select_test.rb b/client/ruby/solr-ruby/test/unit/select_test.rb
new file mode 100755
index 00000000000..ae1a40bb719
--- /dev/null
+++ b/client/ruby/solr-ruby/test/unit/select_test.rb
@@ -0,0 +1,25 @@
+# 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.
+
+require 'test/unit'
+require 'solr'
+
+class SelectTest < Test::Unit::TestCase
+
+ def test_basic_query
+ request = Solr::Request::Select.new('custom', :q => 'query')
+ assert_equal :ruby, request.response_format
+ assert_equal 'select', request.handler
+ assert_equal 'query', request.to_hash[:q]
+ end
+
+end