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

Changeset 30

Show
Ignore:
Timestamp:
04/17/06 15:06:29 (2 years ago)
Author:
jk
Message:

simple sti scenario

Files:

Legend:

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

    r18 r30  
    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 } }, :store_class_name => true 
     9  acts_as_ferret :fields => { :comment_count => {}, 'title' => { :boost => 2 }, 'description' => { :boost => 1 }, :special => {} }, :store_class_name => true 
    1010 
    1111  # use this instead to not assign special boost values: 
  • trunk/demo/db/schema.sql

    r5 r30  
    22create table contents ( 
    33  id int not null auto_increment, 
     4  type varchar(255) not null, 
    45  title varchar(100) not null, 
    56  description text not null, 
     7  special varchar(255) not null, 
    68  primary key (id) 
    79) TYPE=InnoDB DEFAULT CHARSET=utf8; 
  • trunk/demo/test/fixtures/contents.yml

    r5 r30  
    22first: 
    33  id: 1 
     4  title: My Title 
     5  description: A useless description 
     6  type: Content 
    47another: 
    58  id: 2 
     9  type: Content 
     10special: 
     11  id: 3 
     12  title: single table inheritance 
     13  special: special field 
     14  type: SpecialContent 
  • trunk/demo/test/unit/content_test.rb

    r27 r30  
    77 
    88  def setup 
    9     @content = Content.new( :title => 'My Title', :description => 'A useless description' ) 
    10     @content.save 
     9    Content.rebuild_index 
     10    Comment.rebuild_index 
    1111    @another_content = Content.new( :title => 'Another Content item',  
    1212                                    :description => 'this is not the title' ) 
     
    2323   
    2424  def teardown 
    25     @content.destroy if @content 
    2625    @another_content.destroy if @another_content 
    2726    @comment.destroy if @comment 
     
    4039    contents_from_ferret = Content.find_by_contents('useless') 
    4140    assert_equal 1, contents_from_ferret.size 
    42     assert_equal @content.id, contents_from_ferret.first.id 
    43     @content.description = 'Updated description, still useless' 
    44     @content.save 
     41    assert_equal contents(:first).id, contents_from_ferret.first.id 
     42    contents(:first).description = 'Updated description, still useless' 
     43    contents(:first).save 
    4544    contents_from_ferret = Content.find_by_contents('useless') 
    4645    assert_equal 1, contents_from_ferret.size 
    47     assert_equal @content.id, contents_from_ferret.first.id 
     46    assert_equal contents(:first).id, contents_from_ferret.first.id 
    4847    contents_from_ferret = Content.find_by_contents('updated AND description') 
    4948    assert_equal 1, contents_from_ferret.size 
    50     assert_equal @content.id, contents_from_ferret.first.id 
     49    assert_equal contents(:first).id, contents_from_ferret.first.id 
    5150    contents_from_ferret = Content.find_by_contents('updated OR description') 
    5251    assert_equal 1, contents_from_ferret.size 
    53     assert_equal @content.id, contents_from_ferret.first.id 
     52    assert_equal contents(:first).id, contents_from_ferret.first.id 
    5453  end 
    5554 
    5655  def test_indexed_method 
    57     #Content.rebuild_index 
    5856    assert_equal 2, @another_content.comment_count 
    5957    assert_equal 2, contents(:first).comment_count 
     
    103101    contents_from_ferret = Content.multi_search('*:title') 
    104102    assert_equal 2, contents_from_ferret.size 
    105     assert_equal @content.id, contents_from_ferret.first.id 
     103    assert_equal contents(:first).id, contents_from_ferret.first.id 
    106104    assert_equal @another_content.id, contents_from_ferret.last.id 
    107105     
     
    114112    contents_from_ferret = Content.id_multi_search('*:title') 
    115113    assert_equal 2, contents_from_ferret.size 
    116     assert_equal @content.id, contents_from_ferret.first[:id].to_i 
     114    assert_equal contents(:first).id, contents_from_ferret.first[:id].to_i 
    117115    assert_equal @another_content.id, contents_from_ferret.last[:id].to_i 
    118116     
     
    125123    contents_from_ferret = Content.find_by_contents('title') 
    126124    assert_equal 2, contents_from_ferret.size 
    127     # the title field has a higher boost value, so @content must be first in the list 
    128     assert_equal @content.id, contents_from_ferret.first.id  
     125    # the title field has a higher boost value, so contents(:first) must be first in the list 
     126    assert_equal contents(:first).id, contents_from_ferret.first.id  
    129127    assert_equal @another_content.id, contents_from_ferret.last.id 
    130128     
     
    132130    contents_from_ferret = Content.find_by_contents('title', :num_docs => 1) 
    133131    assert_equal 1, contents_from_ferret.size 
    134     assert_equal @content.id, contents_from_ferret.first.id  
     132    assert_equal contents(:first).id, contents_from_ferret.first.id  
    135133     
    136134    # limit result set size to 1, starting with the second result 
     
    142140    contents_from_ferret = Content.find_by_contents('useless') 
    143141    assert_equal 1, contents_from_ferret.size 
    144     assert_equal @content.id, contents_from_ferret.first.id 
     142    assert_equal contents(:first).id, contents_from_ferret.first.id 
    145143     
    146144    # no monkeys here 
     
    154152    contents_from_ferret = Content.find_by_contents('monkey OR description') 
    155153    assert_equal 1, contents_from_ferret.size 
    156     assert_equal @content.id, contents_from_ferret.first.id 
     154    assert_equal contents(:first).id, contents_from_ferret.first.id 
    157155 
    158156    # multiple terms, each term has to occur in a document to be found,  
     
    160158    contents_from_ferret = Content.find_by_contents('useless title') 
    161159    assert_equal 1, contents_from_ferret.size 
    162     assert_equal @content.id, contents_from_ferret.first.id 
     160    assert_equal contents(:first).id, contents_from_ferret.first.id 
    163161     
    164162 
     
    168166    contents_from_ferret = Content.find_by_contents('"useless description"') 
    169167    assert_equal 1, contents_from_ferret.size 
    170     assert_equal @content.id, contents_from_ferret.first.id 
     168    assert_equal contents(:first).id, contents_from_ferret.first.id 
    171169 
    172170    # wildcard query 
     
    185183    assert_equal 2, contents_from_ferret.size 
    186184 
    187     @content.destroy 
     185    contents(:first).destroy 
    188186    contents_from_ferret = Content.find_by_contents('ti*') 
    189187    # should find only one now 

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