To edit pages or tickets please login with username/password: aaf/aaf

Changeset 142

Show
Ignore:
Timestamp:
02/03/07 21:18:55 (2 years ago)
Author:
jk
Message:

some drb remoting :-)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/demo/app/models/comment.rb

    r135 r142  
    1414  # the :ignore flag tells aaf to not try to set this field's value itself (we 
    1515  # do this in our custom to_doc method) 
    16   acts_as_ferret :store_class_name => true, :additional_fields => { 
    17     :added => { :index => :untokenized, :store => :yes, :ignore => true }, 
    18   } 
     16  acts_as_ferret( :store_class_name => true,  
     17                  :remote           => ENV['AAF_REMOTE'],  # for testing drb remote indexing 
     18                  :additional_fields => { 
     19                    :added => { :index => :untokenized, :store => :yes, :ignore => true } 
     20                  } ) 
    1921 
    2022  # only index the named fields: 
  • trunk/demo/app/models/content.rb

    r102 r142  
    1 # common base class for Content and SpecialContent 
    2 class ContentBase < ActiveRecord::Base 
    3   set_table_name 'contents' 
    4  
    5   # a higher boost means more importance for the field --> documents having a 
    6   # match in a field with a higher boost value will be ranked higher 
    7   # 
    8   # we use the store_class_name flag to be able to retrieve model instances when 
    9   # searching multiple indexes at once. 
    10   # the contents of the description field are stored in the index for running 
    11   # 'more like this' queries to find other content instances with similar 
    12   # descriptions 
    13   acts_as_ferret( :fields => {  
    14     :comment_count => {}, 
    15     :title         => { :boost => 2 },  
    16     :description   => { :boost => 1, :store => :yes }, 
    17     :special       => {}  
    18   }, :store_class_name => true) 
    19  
    20  
    21   def comment_count; 0 end 
    22  
    23 end 
    24  
    251class Content < ContentBase #ActiveRecord::Base 
    262 
  • trunk/demo/app/models/shared_index1.rb

    r60 r142  
    11class SharedIndex1 < ActiveRecord::Base 
    2   acts_as_ferret :single_index => true 
     2  acts_as_ferret :single_index => true, :remote => ENV['AAF_REMOTE'] 
    33end 
  • trunk/demo/app/models/shared_index2.rb

    r60 r142  
    11class SharedIndex2 < ActiveRecord::Base 
    2   acts_as_ferret :single_index => true 
     2  acts_as_ferret :single_index => true, :remote => ENV['AAF_REMOTE'] 
    33end 
  • trunk/demo/test/unit/content_test.rb

    r140 r142  
    1313    Comment.rebuild_index 
    1414    ContentBase.rebuild_index  
     15    raise "missing fixtures" unless ContentBase.count > 2 
    1516     
    1617    @another_content = Content.new( :title => 'Another Content item',  
     
    274275     
    275276    [ 'title:title OR description:title OR content:title', 'title', '*:title'].each do |query| 
    276       contents_from_ferret = Content.id_multi_search(query) 
     277      total_hits, contents_from_ferret = Content.id_multi_search(query) 
    277278      assert_equal 2, contents_from_ferret.size, query 
     279      assert_equal 2, total_hits, query 
    278280      assert_equal contents(:first).id, contents_from_ferret.first[:id].to_i 
    279281      assert_equal @another_content.id, contents_from_ferret.last[:id].to_i 
     
    283285    Comment.rebuild_index 
    284286    ['title OR comment', 'title:(title OR comment) OR description:(title OR comment) OR content:(title OR comment)'].each do |query| 
    285       contents_from_ferret = Content.id_multi_search(query, [Comment]) 
     287      total_hits, contents_from_ferret = Content.id_multi_search(query, [Comment]) 
    286288      assert_equal 5, contents_from_ferret.size, query 
     289      assert_equal 5, total_hits 
    287290    end 
    288291  end 
     
    294297 
    295298  def test_find_id_by_contents 
    296     contents_from_ferret = Content.find_id_by_contents('title:title OR description:title') 
    297     assert_equal 2, contents_from_ferret.size 
     299    total_hits, contents_from_ferret = Content.find_id_by_contents('title:title OR description:title') 
     300    assert_equal 2, contents_from_ferret.size 
     301    assert_equal 2, total_hits 
    298302    #puts "first (id=#{contents_from_ferret.first[:id]}): #{contents_from_ferret.first[:score]}" 
    299303    #puts "last  (id=#{contents_from_ferret.last[:id]}): #{contents_from_ferret.last[:score]}" 
     
    303307      
    304308    # give description field higher boost: 
    305     contents_from_ferret = Content.find_id_by_contents('title:title OR description:title^10') 
    306     assert_equal 2, contents_from_ferret.size 
     309    total_hits, contents_from_ferret = Content.find_id_by_contents('title:title OR description:title^10') 
     310    assert_equal 2, contents_from_ferret.size 
     311    assert_equal 2, total_hits 
    307312    #puts "first (id=#{contents_from_ferret.first[:id]}): #{contents_from_ferret.first[:score]}" 
    308313    #puts "last  (id=#{contents_from_ferret.last[:id]}): #{contents_from_ferret.last[:score]}" 

To edit pages or tickets please login with username/password: aaf/aaf