mirror of https://github.com/apache/lucene.git
SOLR-159: Fix DisMax sorting (contributed by Coda Hale)
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@507493 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cb2e229a7c
commit
c3d36ff179
|
@ -1,3 +1,15 @@
|
|||
# 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::Dismax < Solr::Request::Standard
|
||||
|
||||
VALID_PARAMS.replace(VALID_PARAMS + [:tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop,
|
||||
|
@ -5,6 +17,8 @@ class Solr::Request::Dismax < Solr::Request::Standard
|
|||
|
||||
def initialize(params)
|
||||
super(params)
|
||||
@sort_values = @params[:sort]
|
||||
@params.delete(:sort)
|
||||
@query_type = "dismax"
|
||||
end
|
||||
|
||||
|
@ -17,6 +31,12 @@ class Solr::Request::Dismax < Solr::Request::Standard
|
|||
hash[:ps] = @params[:phrase_slop]
|
||||
hash[:bq] = @params[:boost_query]
|
||||
hash[:bf] = @params[:boost_functions]
|
||||
# FIXME: 2007-02-13 <coda.hale@gmail.com> -- This code is duplicated in
|
||||
# Solr::Request::Standard. It should be refactored into a single location.
|
||||
hash[:sort] = @sort_values.collect do |sort|
|
||||
key = sort.keys[0]
|
||||
"#{key.to_s} #{sort[key] == :descending ? 'desc' : 'asc'}"
|
||||
end.join(',') if @sort_values
|
||||
return hash
|
||||
end
|
||||
|
||||
|
|
|
@ -77,6 +77,21 @@ class ServerTest < Test::Unit::TestCase
|
|||
response = @connection.query('Åäöêâîôû Öëäïöü')
|
||||
assert_equal 0, response.total_hits
|
||||
end
|
||||
|
||||
def test_sorting
|
||||
@connection.add(:id => 1, :text => 'aaa woot')
|
||||
@connection.add(:id => 2, :text => 'bbb woot')
|
||||
@connection.add(:id => 3, :text => 'ccc woot')
|
||||
@connection.commit
|
||||
|
||||
results = @connection.query('woot', :sort => [:id => :descending], :rows => 2)
|
||||
assert_equal([3, 2], results.hits.map { |h| h['id'].to_i })
|
||||
|
||||
results = @connection.search('woot', :sort => [:id => :descending], :rows => 2)
|
||||
assert_equal([3, 2], results.hits.map { |h| h['id'].to_i })
|
||||
|
||||
@connection.delete_by_query("id:1 OR id:2 OR id:3")
|
||||
end
|
||||
|
||||
def test_bad_connection
|
||||
conn = Solr::Connection.new 'http://127.0.0.1:9999/invalid'
|
||||
|
|
|
@ -16,10 +16,11 @@ require 'solr'
|
|||
class DismaxRequestTest < Test::Unit::TestCase
|
||||
|
||||
def test_basic_query
|
||||
request = Solr::Request::Dismax.new(:query => 'query', :phrase_slop => '1000')
|
||||
request = Solr::Request::Dismax.new(:query => 'query', :phrase_slop => '1000', :sort => [{:deedle => :descending}])
|
||||
assert_match(/q=query/, request.to_s)
|
||||
assert_match(/qt=dismax/, request.to_s)
|
||||
assert_match(/ps=1000/, request.to_s)
|
||||
assert_match(/sort=deedle%20desc/, request.to_s)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue