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

Changeset 42

Show
Ignore:
Timestamp:
05/04/06 22:43:13 (2 years ago)
Author:
jk
Message:

simple test for more_like_this

Files:

Legend:

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

    r30 r42  
    77  # we use the store_class_name flag to be able to retrieve model instances when 
    88  # searching multiple indexes at once. 
    9   acts_as_ferret :fields => { :comment_count => {}, 'title' => { :boost => 2 }, 'description' => { :boost => 1 }, :special => {} }, :store_class_name => true 
     9  # the contents of the description field are stored in the index for running 
     10  # 'more like this' queries to find other content instances with similar 
     11  # descriptions 
     12  acts_as_ferret :fields => { :comment_count => {}, 'title' => { :boost => 2 }, 'description' => { :boost => 1, :store => Ferret::Document::Field::Store::YES }, :special => {} }, :store_class_name => true 
    1013 
    1114  # use this instead to not assign special boost values: 
  • trunk/demo/test/unit/content_test.rb

    r32 r42  
    3030  def test_truth 
    3131    assert_kind_of Content, contents(:first) 
     32  end 
     33 
     34  def test_more_like_this 
     35    assert Content.find_by_contents('lorem ipsum').empty? 
     36    @c1 = Content.new( :title => 'Content item 1',  
     37                       :description => 'lorem ipsum dolor sit amet. lorem.' ) 
     38    @c1.save 
     39    @c2 = Content.new( :title => 'Content item 2',  
     40                       :description => 'lorem ipsum dolor sit amet. lorem ipsum.' ) 
     41    @c2.save 
     42    assert_equal 2, Content.find_by_contents('lorem ipsum').size 
     43    similar = @c1.more_like_this(:field_names => ['description'], :min_doc_freq => 1, :min_term_freq => 1) 
     44    assert_equal 1, similar.size 
     45    assert_equal @c2, similar.first 
    3246  end 
    3347 

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