Changeset 18
- Timestamp:
- 03/25/06 13:15:43 (3 years ago)
- Files:
-
- trunk/demo/app/models/content.rb (modified) (1 diff)
- trunk/demo/test/unit/content_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/content.rb
r16 r18 4 4 # a higher boost means more importance for the field --> documents having a 5 5 # match in a field with a higher boost value will be ranked better 6 acts_as_ferret :fields => { 'title' => { :boost => 2 }, 'description' => { :boost => 1 } }, :store_class_name => true 6 # 7 # we use the store_class_name flag to be able to retrieve model instances when 8 # searching multiple indexes at once. 9 acts_as_ferret :fields => { :comment_count => {}, 'title' => { :boost => 2 }, 'description' => { :boost => 1 } }, :store_class_name => true 7 10 8 11 # use this instead to not assign special boost values: 9 12 #acts_as_ferret :fields => [ 'title', 'description' ] 13 14 # returns the number of comments attached to this content. 15 # the value returned by this method will be indexed, too. 16 def comment_count 17 comments.size 18 end 10 19 end trunk/demo/test/unit/content_test.rb
r16 r18 16 16 @comment2 = Comment.new( :author => 'another', :content => 'content' ) 17 17 @comment2.save 18 19 @another_content.comments << @comment 20 @another_content.comments << @comment2 21 @another_content.save 18 22 end 19 23 … … 31 35 def test_class_index_dir 32 36 assert_equal "#{RAILS_ROOT}/index/test/Content", Content.class_index_dir 37 end 38 39 def test_indexed_method 40 assert_equal 2, @another_content.comments.size 41 # retrieve all content objects having more than 1 comments 42 result = Content.find_by_contents('comment_count:[2 TO 1000]') 43 assert_equal 1, result.size 44 assert_equal @another_content.id, result.first.id 33 45 end 34 46
