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/02/14 12:46:03 UTC

svn commit: r507493 - in /lucene/solr/trunk/client/ruby/solrb: lib/solr/request/dismax.rb test/functional/server_test.rb test/unit/dismax_request_test.rb

Author: ehatcher
Date: Wed Feb 14 03:46:02 2007
New Revision: 507493

URL: http://svn.apache.org/viewvc?view=rev&rev=507493
Log:
SOLR-159: Fix DisMax sorting (contributed by Coda Hale)


Modified:
    lucene/solr/trunk/client/ruby/solrb/lib/solr/request/dismax.rb
    lucene/solr/trunk/client/ruby/solrb/test/functional/server_test.rb
    lucene/solr/trunk/client/ruby/solrb/test/unit/dismax_request_test.rb

Modified: lucene/solr/trunk/client/ruby/solrb/lib/solr/request/dismax.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solrb/lib/solr/request/dismax.rb?view=diff&rev=507493&r1=507492&r2=507493
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/lib/solr/request/dismax.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/lib/solr/request/dismax.rb Wed Feb 14 03:46:02 2007
@@ -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 @@
 
   def initialize(params)
     super(params)
+    @sort_values = @params[:sort]
+    @params.delete(:sort)
     @query_type = "dismax"
   end
   
@@ -17,6 +31,12 @@
     hash[:ps]  = @params[:phrase_slop]
     hash[:bq]  = @params[:boost_query]
     hash[:bf]  = @params[:boost_functions]
+    # FIXME: 2007-02-13 <co...@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
 

Modified: lucene/solr/trunk/client/ruby/solrb/test/functional/server_test.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solrb/test/functional/server_test.rb?view=diff&rev=507493&r1=507492&r2=507493
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/test/functional/server_test.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/test/functional/server_test.rb Wed Feb 14 03:46:02 2007
@@ -77,6 +77,21 @@
     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'

Modified: lucene/solr/trunk/client/ruby/solrb/test/unit/dismax_request_test.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solrb/test/unit/dismax_request_test.rb?view=diff&rev=507493&r1=507492&r2=507493
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/test/unit/dismax_request_test.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/test/unit/dismax_request_test.rb Wed Feb 14 03:46:02 2007
@@ -16,10 +16,11 @@
 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