Changeset 30
- Timestamp:
- 04/17/06 15:06:29 (2 years ago)
- Files:
-
- trunk/demo/app/models/content.rb (modified) (1 diff)
- trunk/demo/app/models/special_content.rb (added)
- trunk/demo/db/schema.sql (modified) (1 diff)
- trunk/demo/test/fixtures/contents.yml (modified) (1 diff)
- trunk/demo/test/unit/content_test.rb (modified) (12 diffs)
- trunk/demo/test/unit/special_content_test.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/content.rb
r18 r30 7 7 # we use the store_class_name flag to be able to retrieve model instances when 8 8 # searching multiple indexes at once. 9 acts_as_ferret :fields => { :comment_count => {}, 'title' => { :boost => 2 }, 'description' => { :boost => 1 } }, :store_class_name => true9 acts_as_ferret :fields => { :comment_count => {}, 'title' => { :boost => 2 }, 'description' => { :boost => 1 }, :special => {} }, :store_class_name => true 10 10 11 11 # use this instead to not assign special boost values: trunk/demo/db/schema.sql
r5 r30 2 2 create table contents ( 3 3 id int not null auto_increment, 4 type varchar(255) not null, 4 5 title varchar(100) not null, 5 6 description text not null, 7 special varchar(255) not null, 6 8 primary key (id) 7 9 ) TYPE=InnoDB DEFAULT CHARSET=utf8; trunk/demo/test/fixtures/contents.yml
r5 r30 2 2 first: 3 3 id: 1 4 title: My Title 5 description: A useless description 6 type: Content 4 7 another: 5 8 id: 2 9 type: Content 10 special: 11 id: 3 12 title: single table inheritance 13 special: special field 14 type: SpecialContent trunk/demo/test/unit/content_test.rb
r27 r30 7 7 8 8 def setup 9 @content = Content.new( :title => 'My Title', :description => 'A useless description' )10 @content.save9 Content.rebuild_index 10 Comment.rebuild_index 11 11 @another_content = Content.new( :title => 'Another Content item', 12 12 :description => 'this is not the title' ) … … 23 23 24 24 def teardown 25 @content.destroy if @content26 25 @another_content.destroy if @another_content 27 26 @comment.destroy if @comment … … 40 39 contents_from_ferret = Content.find_by_contents('useless') 41 40 assert_equal 1, contents_from_ferret.size 42 assert_equal @content.id, contents_from_ferret.first.id43 @content.description = 'Updated description, still useless'44 @content.save41 assert_equal contents(:first).id, contents_from_ferret.first.id 42 contents(:first).description = 'Updated description, still useless' 43 contents(:first).save 45 44 contents_from_ferret = Content.find_by_contents('useless') 46 45 assert_equal 1, contents_from_ferret.size 47 assert_equal @content.id, contents_from_ferret.first.id46 assert_equal contents(:first).id, contents_from_ferret.first.id 48 47 contents_from_ferret = Content.find_by_contents('updated AND description') 49 48 assert_equal 1, contents_from_ferret.size 50 assert_equal @content.id, contents_from_ferret.first.id49 assert_equal contents(:first).id, contents_from_ferret.first.id 51 50 contents_from_ferret = Content.find_by_contents('updated OR description') 52 51 assert_equal 1, contents_from_ferret.size 53 assert_equal @content.id, contents_from_ferret.first.id52 assert_equal contents(:first).id, contents_from_ferret.first.id 54 53 end 55 54 56 55 def test_indexed_method 57 #Content.rebuild_index58 56 assert_equal 2, @another_content.comment_count 59 57 assert_equal 2, contents(:first).comment_count … … 103 101 contents_from_ferret = Content.multi_search('*:title') 104 102 assert_equal 2, contents_from_ferret.size 105 assert_equal @content.id, contents_from_ferret.first.id103 assert_equal contents(:first).id, contents_from_ferret.first.id 106 104 assert_equal @another_content.id, contents_from_ferret.last.id 107 105 … … 114 112 contents_from_ferret = Content.id_multi_search('*:title') 115 113 assert_equal 2, contents_from_ferret.size 116 assert_equal @content.id, contents_from_ferret.first[:id].to_i114 assert_equal contents(:first).id, contents_from_ferret.first[:id].to_i 117 115 assert_equal @another_content.id, contents_from_ferret.last[:id].to_i 118 116 … … 125 123 contents_from_ferret = Content.find_by_contents('title') 126 124 assert_equal 2, contents_from_ferret.size 127 # the title field has a higher boost value, so @contentmust be first in the list128 assert_equal @content.id, contents_from_ferret.first.id125 # 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 129 127 assert_equal @another_content.id, contents_from_ferret.last.id 130 128 … … 132 130 contents_from_ferret = Content.find_by_contents('title', :num_docs => 1) 133 131 assert_equal 1, contents_from_ferret.size 134 assert_equal @content.id, contents_from_ferret.first.id132 assert_equal contents(:first).id, contents_from_ferret.first.id 135 133 136 134 # limit result set size to 1, starting with the second result … … 142 140 contents_from_ferret = Content.find_by_contents('useless') 143 141 assert_equal 1, contents_from_ferret.size 144 assert_equal @content.id, contents_from_ferret.first.id142 assert_equal contents(:first).id, contents_from_ferret.first.id 145 143 146 144 # no monkeys here … … 154 152 contents_from_ferret = Content.find_by_contents('monkey OR description') 155 153 assert_equal 1, contents_from_ferret.size 156 assert_equal @content.id, contents_from_ferret.first.id154 assert_equal contents(:first).id, contents_from_ferret.first.id 157 155 158 156 # multiple terms, each term has to occur in a document to be found, … … 160 158 contents_from_ferret = Content.find_by_contents('useless title') 161 159 assert_equal 1, contents_from_ferret.size 162 assert_equal @content.id, contents_from_ferret.first.id160 assert_equal contents(:first).id, contents_from_ferret.first.id 163 161 164 162 … … 168 166 contents_from_ferret = Content.find_by_contents('"useless description"') 169 167 assert_equal 1, contents_from_ferret.size 170 assert_equal @content.id, contents_from_ferret.first.id168 assert_equal contents(:first).id, contents_from_ferret.first.id 171 169 172 170 # wildcard query … … 185 183 assert_equal 2, contents_from_ferret.size 186 184 187 @content.destroy185 contents(:first).destroy 188 186 contents_from_ferret = Content.find_by_contents('ti*') 189 187 # should find only one now
