You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by eh...@apache.org on 2007/09/26 20:04:51 UTC

svn commit: r579743 - in /lucene/solr/trunk/client/ruby/solr-ruby: ./ lib/solr/ lib/solr/request/ lib/solr/response/ test/unit/

Author: ehatcher
Date: Wed Sep 26 11:04:49 2007
New Revision: 579743

URL: http://svn.apache.org/viewvc?rev=579743&view=rev
Log:
Add Spellcheck support

Added:
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/spellcheck.rb
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/spellcheck.rb
    lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellcheck_response_test.rb
    lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellchecker_request_test.rb
Modified:
    lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb
    lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb

Modified: lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml?rev=579743&r1=579742&r2=579743&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/CHANGES.yml Wed Sep 26 11:04:49 2007
@@ -1,5 +1,10 @@
+v0.0.6:
+  release_date: TBD
+  changes:
+    - Added Solr::Request::Spellcheck
+  
 v0.0.5:
-  release_date: 2007-08-??
+  release_date: 2007-08-27
   changes:
     - Added support for highlighter fragment size to Solr::Request::Standard
     - Added support for MoreLikeThese to Solr::Request::Standard

Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb?rev=579743&r1=579742&r2=579743&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request.rb Wed Sep 26 11:04:49 2007
@@ -19,6 +19,7 @@
 require 'solr/request/ping'
 require 'solr/request/select'
 require 'solr/request/standard'
+require 'solr/request/spellcheck'
 require 'solr/request/dismax'
 require 'solr/request/update'
 require 'solr/request/index_info'

Added: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/spellcheck.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/spellcheck.rb?rev=579743&view=auto
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/spellcheck.rb (added)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/request/spellcheck.rb Wed Sep 26 11:04:49 2007
@@ -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.
+
+class Solr::Request::Spellcheck < Solr::Request::Select
+
+  def initialize(params)
+    super('spellchecker')
+    @params = params
+  end
+  
+  def to_hash
+    hash = super
+    hash[:q] = @params[:query]
+    hash[:suggestionCount] = @params[:suggestion_count]
+    hash[:accuracy] = @params[:accuracy]
+    hash[:onlyMorePopular] = @params[:only_more_popular]
+    hash[:cmd] = @params[:command]
+    return hash
+  end
+
+end
\ No newline at end of file

Modified: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb?rev=579743&r1=579742&r2=579743&view=diff
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb (original)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response.rb Wed Sep 26 11:04:49 2007
@@ -18,6 +18,7 @@
 require 'solr/response/add_document'
 require 'solr/response/modify_document'
 require 'solr/response/standard'
+require 'solr/response/spellcheck'
 require 'solr/response/dismax'
 require 'solr/response/commit'
 require 'solr/response/delete'

Added: lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/spellcheck.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/spellcheck.rb?rev=579743&view=auto
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/spellcheck.rb (added)
+++ lucene/solr/trunk/client/ruby/solr-ruby/lib/solr/response/spellcheck.rb Wed Sep 26 11:04:49 2007
@@ -0,0 +1,20 @@
+# 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::Spellcheck < Solr::Response::Ruby
+  attr_reader :suggestions
+  
+  def initialize(ruby_code)
+    super
+    @suggestions = @data['suggestions']
+  end
+end

Added: lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellcheck_response_test.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellcheck_response_test.rb?rev=579743&view=auto
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellcheck_response_test.rb (added)
+++ lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellcheck_response_test.rb Wed Sep 26 11:04:49 2007
@@ -0,0 +1,26 @@
+# 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_mock_base'
+
+class SpellcheckResponseTest <  SolrMockBaseTestCase
+  def test_basic
+    ruby_code = "{'responseHeader'=>{'status'=>0,'QTime'=>5},'suggestions'=>['whately','whatcha','whatever']}"
+    conn = Solr::Connection.new 'http://localhost:9999'
+    set_post_return(ruby_code)
+    response = conn.send(Solr::Request::Spellcheck.new(:query => 'whateva'))
+    assert_equal true, response.ok?
+    assert_equal 3, response.suggestions.size
+    assert_equal ['whately','whatcha','whatever'], response.suggestions
+  end
+end
+

Added: lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellchecker_request_test.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellchecker_request_test.rb?rev=579743&view=auto
==============================================================================
--- lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellchecker_request_test.rb (added)
+++ lucene/solr/trunk/client/ruby/solr-ruby/test/unit/spellchecker_request_test.rb Wed Sep 26 11:04:49 2007
@@ -0,0 +1,27 @@
+# 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 SpellcheckRequestTest < Test::Unit::TestCase
+  def test_spellcheck_request
+    request = Solr::Request::Spellcheck.new(:query => 'whateva', :suggestion_count => 5, :accuracy => 0.7, :only_more_popular => true)
+    assert_equal :ruby, request.response_format
+    assert_equal 'select', request.handler
+    hash = request.to_hash
+    assert_equal 'whateva', hash[:q]
+    assert_equal 5, hash[:suggestionCount]
+    assert_equal 0.7, hash[:accuracy]
+    assert_equal true, hash[:onlyMorePopular]
+  end
+end