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/09 01:39:51 UTC

svn commit: r505102 - in /lucene/solr/trunk/client/ruby/solrb: lib/solr/request/standard.rb lib/solr/response/standard.rb test/functional/server_test.rb test/unit/standard_request_test.rb

Author: ehatcher
Date: Thu Feb  8 16:39:50 2007
New Revision: 505102

URL: http://svn.apache.org/viewvc?view=rev&rev=505102
Log:
add highlighting support to Standard request

Modified:
    lucene/solr/trunk/client/ruby/solrb/lib/solr/request/standard.rb
    lucene/solr/trunk/client/ruby/solrb/lib/solr/response/standard.rb
    lucene/solr/trunk/client/ruby/solrb/test/functional/server_test.rb
    lucene/solr/trunk/client/ruby/solrb/test/unit/standard_request_test.rb

Modified: lucene/solr/trunk/client/ruby/solrb/lib/solr/request/standard.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solrb/lib/solr/request/standard.rb?view=diff&rev=505102&r1=505101&r2=505102
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/lib/solr/request/standard.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/lib/solr/request/standard.rb Thu Feb  8 16:39:50 2007
@@ -13,7 +13,7 @@
 class Solr::Request::Standard < Solr::Request::Select
 
   VALID_PARAMS = [:query, :sort, :default_field, :operator, :start, :rows,
-    :filter_queries, :field_list, :debug_query, :explain_other, :facets]
+    :filter_queries, :field_list, :debug_query, :explain_other, :facets, :highlighting]
   
   def initialize(params)
     super('standard')
@@ -38,8 +38,6 @@
     @params[:rows] = params[:rows].to_i if params[:rows]
     
     @params[:field_list] ||= ["*","score"]
-
-    #TODO model highlighting parameters: http://wiki.apache.org/solr/HighlightingParameters
   end
   
   def to_hash
@@ -88,6 +86,18 @@
         end
       end
     end
+    
+    # highlighting parameter processing - http://wiki.apache.org/solr/HighlightingParameters
+    #TODO need to add per-field overriding to snippets, fragsize, requiredFieldMatch, formatting, and simple.pre/post
+    if @params[:highlighting]
+      hash[:hl] = true
+      hash["hl.fl"] = @params[:highlighting][:field_list].join(',') if @params[:highlighting][:field_list]
+      hash["hl.snippets"] = @params[:highlighting][:max_snippets]
+      hash["hl.requireFieldMatch"] = @params[:highlighting][:require_field_match]
+      hash["hl.simple.pre"] = @params[:highlighting][:prefix]
+      hash["hl.simple.post"] = @params[:highlighting][:suffix]
+    end
+    
     
     hash.merge(super.to_hash)
   end

Modified: lucene/solr/trunk/client/ruby/solrb/lib/solr/response/standard.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solrb/lib/solr/response/standard.rb?view=diff&rev=505102&r1=505101&r2=505102
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/lib/solr/response/standard.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/lib/solr/response/standard.rb Thu Feb  8 16:39:50 2007
@@ -47,7 +47,10 @@
     facets
   end
   
-
+  def highlighted(id, field)
+    @data['highlighting'][id.to_s][field.to_s]
+  end
+  
   # supports enumeration of hits
   # TODO revisit - should this iterate through *all* hits by re-requesting more?
   def each

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=505102&r1=505101&r2=505102
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/test/functional/server_test.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/test/functional/server_test.rb Thu Feb  8 16:39:50 2007
@@ -149,6 +149,22 @@
     assert info.field_names.include?("id") && info.field_names.include?("test_index_facet")
     assert_equal 1, info.num_docs
   end
+  
+  def test_highlighting
+    @connection.add(:id => 1, :title_text => "Apache Solr")
+    
+    request = Solr::Request::Standard.new(:query => 'solr',
+      :highlighting => {
+        :field_list => ['title_text'],
+        :max_snippets => 3,
+        :prefix => ">>",
+        :suffix => "<<"
+      }
+    )
+    
+    response = @connection.send(request)
+    assert_equal ["Apache >>Solr<<"], response.highlighted(1, :title_text)
+  end
 
   # wipe the index clean
   def clean

Modified: lucene/solr/trunk/client/ruby/solrb/test/unit/standard_request_test.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/solrb/test/unit/standard_request_test.rb?view=diff&rev=505102&r1=505101&r2=505102
==============================================================================
--- lucene/solr/trunk/client/ruby/solrb/test/unit/standard_request_test.rb (original)
+++ lucene/solr/trunk/client/ruby/solrb/test/unit/standard_request_test.rb Thu Feb  8 16:39:50 2007
@@ -85,5 +85,24 @@
     request = Solr::Request::Standard.new(:query => 'query', :sort => [{:title => :descending}])
     assert_equal 'query;title desc', request.to_hash[:q]
   end
+  
+  def test_highlighting
+    request = Solr::Request::Standard.new(:query => 'query',
+      :highlighting => {
+        :field_list => ['title', 'author'],
+        :max_snippets => 3,
+        :require_field_match => true,
+        :prefix => "<blink>",
+        :suffix => "</blink>"
+      }
+    )
+    
+    hash = request.to_hash
+    assert_equal true, hash[:hl]
+    assert_equal "title,author", hash["hl.fl"]
+    assert_equal true, hash["hl.requireFieldMatch"]
+    assert_equal "<blink>", hash["hl.simple.pre"]
+    assert_equal "</blink>", hash["hl.simple.post"]
+  end
 
 end