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

Changeset 102

Show
Ignore:
Timestamp:
09/12/06 20:38:09 (2 years ago)
Author:
jk
Message:

r1258@monsoon: jk | 2006-09-12 22:38:04 +0200
backup

Files:

Legend:

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

    r78 r102  
    44 
    55  # 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 better 
     6  # match in a field with a higher boost value will be ranked higher 
    77  # 
    88  # we use the store_class_name flag to be able to retrieve model instances when 
     
    1818  }, :store_class_name => true) 
    1919 
    20   # use this instead to not assign special boost values: 
    21   #acts_as_ferret :fields => [ 'title', 'description' ] 
    2220 
    2321  def comment_count; 0 end 
  • trunk/demo/test/unit/comment_test.rb

    r86 r102  
    5656    assert_equal 15, (res = Comment.find_by_contents('multicomment', :limit => 15)).size 
    5757    assert_equal 20, res.total_hits 
    58     assert_equal 20, (res = Comment.find_by_contents('multicomment', :num_docs => :all)).size 
    59     assert_equal 20, res.total_hits 
    60  
    61     Comment.configuration[:max_results] = 15 
    62     assert_equal 15, (res = Comment.find_by_contents('multicomment', :num_docs => :all)).size 
     58    assert_equal 20, (res = Comment.find_by_contents('multicomment', :limit => :all)).size 
    6359    assert_equal 20, res.total_hits 
    6460  end 
  • trunk/demo/test/unit/content_test.rb

    r99 r102  
    11require File.dirname(__FILE__) + '/../test_helper' 
    22require 'pp' 
     3require 'fileutils' 
    34 
    45class ContentTest < Test::Unit::TestCase 
     
    910  def setup 
    1011    #make sure the fixtures are in the index 
    11     ContentBase.find(:all).each { |c| c.save } 
    12     Comment.find(:all).each { |c| c.save } 
    13  
     12    FileUtils.rm_f 'index/test/' 
     13    Comment.rebuild_index 
     14    ContentBase.rebuild_index  
    1415     
    1516    @another_content = Content.new( :title => 'Another Content item',  
     
    1920    @comment2 = @another_content.comments.create(:author => 'another', :content => 'content') 
    2021    @another_content.save # to update comment_count in ferret-index 
    21     #puts "\n### another content: #{@another_content.id}\n" 
    2222  end 
    2323   
     
    233233    assert_equal 4, ContentBase.find(:all).size 
    234234     
     235    Content.ferret_index.flush 
     236    contents_from_ferret = Content.multi_search('description:title') 
     237    assert_equal 1, contents_from_ferret.size 
     238    contents_from_ferret = Content.multi_search('title:title OR description:title') 
     239    assert_equal 2, contents_from_ferret.size 
    235240    contents_from_ferret = Content.multi_search('title:title') 
    236241    assert_equal 1, contents_from_ferret.size 
    237      
    238     contents_from_ferret = Content.multi_search('title:title OR description:title') 
    239     assert_equal 2, contents_from_ferret.size 
    240242    contents_from_ferret = Content.multi_search('*:title') 
    241243    assert_equal 2, contents_from_ferret.size 
     
    334336    assert_equal @another_content.id, contents_from_ferret.last.id 
    335337 
    336     # find options 
    337     contents_from_ferret = Content.find_by_contents('title', {}, :conditions => ["id=?",contents(:first).id]) 
    338     assert_equal 1, contents_from_ferret.size 
    339     assert_equal contents(:first), contents_from_ferret.first 
    340      
    341     # limit result set size to 1 
    342     contents_from_ferret = Content.find_by_contents('title', :num_docs => 1) 
    343     assert_equal 1, contents_from_ferret.size 
    344     assert_equal contents(:first), contents_from_ferret.first  
    345      
    346     # limit result set size to 1, starting with the second result 
    347     contents_from_ferret = Content.find_by_contents('title', :num_docs => 1, :first_doc => 1) 
    348     assert_equal 1, contents_from_ferret.size 
    349     assert_equal @another_content.id, contents_from_ferret.first.id  
    350338      
    351339 
     
    387375    assert_equal 1, contents_from_ferret.size 
    388376    assert_equal @another_content.id, contents_from_ferret.first.id 
    389    end 
    390  
    391    def test_find_by_contents_options 
     377  end 
     378 
     379  def test_find_by_contents_options 
     380    # find options 
     381    contents_from_ferret = Content.find_by_contents('title', {}, :conditions => ["id=?",contents(:first).id]) 
     382    assert_equal 1, contents_from_ferret.size 
     383    assert_equal contents(:first), contents_from_ferret.first 
     384     
     385    # limit result set size to 1 
     386    contents_from_ferret = Content.find_by_contents('title', :limit => 1) 
     387    assert_equal 1, contents_from_ferret.size 
     388    assert_equal contents(:first), contents_from_ferret.first  
     389     
     390    # limit result set size to 1, starting with the second result 
     391    contents_from_ferret = Content.find_by_contents('title', :limit => 1, :offset => 1) 
     392    assert_equal 1, contents_from_ferret.size 
     393    assert_equal @another_content.id, contents_from_ferret.first.id  
     394 
     395    # deprecated options, still supported 
     396    contents_from_ferret = Content.find_by_contents('title', :num_docs => 1, :first_doc => 1) 
     397    assert_equal 1, contents_from_ferret.size 
     398    assert_equal @another_content.id, contents_from_ferret.first.id  
    392399      
    393400   end 

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