From cd44713a89e11391eb890c0b3be224ec74ca88bf Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Fri, 9 Feb 2007 01:03:34 +0000 Subject: [PATCH] SOLR-151: Added command support. Also, committing a few files missed from previous dismax support commit. git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@505109 13f79535-47bb-0310-9956-ffa450edef68 --- client/ruby/solrb/lib/solr/connection.rb | 16 +++++------- client/ruby/solrb/lib/solr/request.rb | 1 + client/ruby/solrb/lib/solr/request/dismax.rb | 23 +++++++++++++++++ .../ruby/solrb/lib/solr/request/optimize.rb | 21 ++++++++++++++++ client/ruby/solrb/lib/solr/response.rb | 3 ++- client/ruby/solrb/lib/solr/response/dismax.rb | 8 ++++++ .../ruby/solrb/lib/solr/response/optimize.rb | 14 +++++++++++ .../ruby/solrb/test/functional/server_test.rb | 5 ++++ .../solrb/test/unit/dismax_request_test.rb | 25 +++++++++++++++++++ 9 files changed, 105 insertions(+), 11 deletions(-) create mode 100644 client/ruby/solrb/lib/solr/request/dismax.rb create mode 100755 client/ruby/solrb/lib/solr/request/optimize.rb create mode 100644 client/ruby/solrb/lib/solr/response/dismax.rb create mode 100755 client/ruby/solrb/lib/solr/response/optimize.rb create mode 100644 client/ruby/solrb/test/unit/dismax_request_test.rb diff --git a/client/ruby/solrb/lib/solr/connection.rb b/client/ruby/solrb/lib/solr/connection.rb index 3073942c386..f4efc3da4a9 100755 --- a/client/ruby/solrb/lib/solr/connection.rb +++ b/client/ruby/solrb/lib/solr/connection.rb @@ -90,16 +90,12 @@ class Solr::Connection return response.ok? end - # TODO add optimize, which can be hacked like this, interestingly! - # class OptimizeRequest - # def handler - # "update" - # end - # def to_s - # "" - # end - # end - + # sends an optimize message to the server + def optimize + response = send(Solr::Request::Optimize.new) + return response.ok? + end + # pings the connection and returns true/false if it is alive or not def ping begin diff --git a/client/ruby/solrb/lib/solr/request.rb b/client/ruby/solrb/lib/solr/request.rb index ae873c17709..a25aaf434cb 100755 --- a/client/ruby/solrb/lib/solr/request.rb +++ b/client/ruby/solrb/lib/solr/request.rb @@ -21,3 +21,4 @@ require 'solr/request/standard' require 'solr/request/dismax' require 'solr/request/update' require 'solr/request/index_info' +require 'solr/request/optimize' diff --git a/client/ruby/solrb/lib/solr/request/dismax.rb b/client/ruby/solrb/lib/solr/request/dismax.rb new file mode 100644 index 00000000000..8a9f1450a47 --- /dev/null +++ b/client/ruby/solrb/lib/solr/request/dismax.rb @@ -0,0 +1,23 @@ +class Solr::Request::Dismax < Solr::Request::Standard + + VALID_PARAMS.replace(VALID_PARAMS + [:tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop, + :boost_query, :boost_functions]) + + def initialize(params) + super(params) + @query_type = "dismax" + end + + def to_hash + hash = super + hash[:tie] = @params[:tie_breaker] + hash[:mm] = @params[:minimum_match] + hash[:qf] = @params[:query_fields] + hash[:pf] = @params[:phrase_fields] + hash[:ps] = @params[:phrase_slop] + hash[:bq] = @params[:boost_query] + hash[:bf] = @params[:boost_functions] + return hash + end + +end \ No newline at end of file diff --git a/client/ruby/solrb/lib/solr/request/optimize.rb b/client/ruby/solrb/lib/solr/request/optimize.rb new file mode 100755 index 00000000000..3bd1fc4e494 --- /dev/null +++ b/client/ruby/solrb/lib/solr/request/optimize.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. + +require 'solr/xml' + +class Solr::Request::Optimize < Solr::Request::Update + + def to_s + Solr::XML::Element.new('optimize').to_s + end + +end \ No newline at end of file diff --git a/client/ruby/solrb/lib/solr/response.rb b/client/ruby/solrb/lib/solr/response.rb index d04fbb404cc..b14b2c239d9 100755 --- a/client/ruby/solrb/lib/solr/response.rb +++ b/client/ruby/solrb/lib/solr/response.rb @@ -20,4 +20,5 @@ require 'solr/response/standard' require 'solr/response/dismax' require 'solr/response/commit' require 'solr/response/delete' -require 'solr/response/index_info' \ No newline at end of file +require 'solr/response/index_info' +require 'solr/response/optimize' \ No newline at end of file diff --git a/client/ruby/solrb/lib/solr/response/dismax.rb b/client/ruby/solrb/lib/solr/response/dismax.rb new file mode 100644 index 00000000000..d495843bcf1 --- /dev/null +++ b/client/ruby/solrb/lib/solr/response/dismax.rb @@ -0,0 +1,8 @@ +class Solr::Response::Dismax < Solr::Response::Standard + # no need for special processing + + # FIXME: 2007-02-07 -- The existence of this class indicates that + # the Request/Response pair architecture is a little hinky. Perhaps we could refactor + # out some of the most common functionality -- Common Query Parameters, Highlighting Parameters, + # Simple Facet Parameters, etc. -- into modules? +end \ No newline at end of file diff --git a/client/ruby/solrb/lib/solr/response/optimize.rb b/client/ruby/solrb/lib/solr/response/optimize.rb new file mode 100755 index 00000000000..4594d90d065 --- /dev/null +++ b/client/ruby/solrb/lib/solr/response/optimize.rb @@ -0,0 +1,14 @@ +# 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::Optimize < Solr::Response::Commit +end \ No newline at end of file diff --git a/client/ruby/solrb/test/functional/server_test.rb b/client/ruby/solrb/test/functional/server_test.rb index 8f0fcbdabe5..aef64e9374d 100644 --- a/client/ruby/solrb/test/functional/server_test.rb +++ b/client/ruby/solrb/test/functional/server_test.rb @@ -97,6 +97,11 @@ class ServerTest < Test::Unit::TestCase assert_equal "", response.raw_response end + def test_optimize + response = @connection.send(Solr::Request::Optimize.new) + assert_equal "", response.raw_response + end + def test_ping assert_equal true, @connection.ping end diff --git a/client/ruby/solrb/test/unit/dismax_request_test.rb b/client/ruby/solrb/test/unit/dismax_request_test.rb new file mode 100644 index 00000000000..98cd1cbf66b --- /dev/null +++ b/client/ruby/solrb/test/unit/dismax_request_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 DismaxRequestTest < Test::Unit::TestCase + + def test_basic_query + request = Solr::Request::Dismax.new(:query => 'query', :phrase_slop => '1000') + assert_match(/q=query/, request.to_s) + assert_match(/qt=dismax/, request.to_s) + assert_match(/ps=1000/, request.to_s) + end + +end \ No newline at end of file