mirror of https://github.com/apache/lucene.git
Add Spellcheck support
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@579743 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2faac488b3
commit
56ceddd6c0
|
@ -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
|
||||
|
|
|
@ -19,6 +19,7 @@ require 'solr/request/delete'
|
|||
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'
|
||||
|
|
|
@ -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
|
|
@ -18,6 +18,7 @@ require 'solr/response/ping'
|
|||
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'
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
Loading…
Reference in New Issue