Apache Lucene open-source search software
SOLR-159: Fix DisMax sorting (contributed by Coda Hale)
Erik Hatcherc3d36ff1794f
diff --git a/client/ruby/solrb/lib/solr/request/dismax.rb b/client/ruby/solrb/lib/solr/request/dismax.rbindex 8a9f1450a47..8b642887eee 100644--- a/client/ruby/solrb/lib/solr/request/dismax.rb+++ b/client/ruby/solrb/lib/solr/request/dismax.rb@@ -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::StandardVALID_PARAMS.replace(VALID_PARAMS + [:tie_breaker, :query_fields, :minimum_match, :phrase_fields, :phrase_slop,@@ -5,6 +17,8 @@ class Solr::Request::Dismax < Solr::Request::Standarddef 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::Standardhash[:ps] = @params[:phrase_slop]hash[:bq] = @params[:boost_query]hash[:bf] = @params[:boost_functions]+ # FIXME: 2007-02-13 <[email protected]> -- 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_valuesreturn hashenddiff --git a/client/ruby/solrb/test/functional/server_test.rb b/client/ruby/solrb/test/functional/server_test.rbindex aef64e9374d..e0743a11bad 100644--- a/client/ruby/solrb/test/functional/server_test.rb+++ b/client/ruby/solrb/test/functional/server_test.rb@@ -77,6 +77,21 @@ class ServerTest < Test::Unit::TestCaseresponse = @connection.query('Åäöêâîôû Öëäïöü')assert_equal 0, response.total_hitsend++ 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")+ enddef test_bad_connectionconn = Solr::Connection.new 'http://127.0.0.1:9999/invalid'diff --git a/client/ruby/solrb/test/unit/dismax_request_test.rb b/client/ruby/solrb/test/unit/dismax_request_test.rbindex 98cd1cbf66b..7141334720d 100644--- a/client/ruby/solrb/test/unit/dismax_request_test.rb+++ b/client/ruby/solrb/test/unit/dismax_request_test.rb@@ -16,10 +16,11 @@ require 'solr'class DismaxRequestTest < Test::Unit::TestCasedef 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)endend\ No newline at end of file