Changeset 102
- Timestamp:
- 09/12/06 20:38:09 (2 years ago)
- Files:
-
- trunk/demo/app/models/content.rb (modified) (2 diffs)
- trunk/demo/test/unit/comment_test.rb (modified) (1 diff)
- trunk/demo/test/unit/content_test.rb (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/content.rb
r78 r102 4 4 5 5 # 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 better6 # match in a field with a higher boost value will be ranked higher 7 7 # 8 8 # we use the store_class_name flag to be able to retrieve model instances when … … 18 18 }, :store_class_name => true) 19 19 20 # use this instead to not assign special boost values:21 #acts_as_ferret :fields => [ 'title', 'description' ]22 20 23 21 def comment_count; 0 end trunk/demo/test/unit/comment_test.rb
r86 r102 56 56 assert_equal 15, (res = Comment.find_by_contents('multicomment', :limit => 15)).size 57 57 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 63 59 assert_equal 20, res.total_hits 64 60 end trunk/demo/test/unit/content_test.rb
r99 r102 1 1 require File.dirname(__FILE__) + '/../test_helper' 2 2 require 'pp' 3 require 'fileutils' 3 4 4 5 class ContentTest < Test::Unit::TestCase … … 9 10 def setup 10 11 #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 14 15 15 16 @another_content = Content.new( :title => 'Another Content item', … … 19 20 @comment2 = @another_content.comments.create(:author => 'another', :content => 'content') 20 21 @another_content.save # to update comment_count in ferret-index 21 #puts "\n### another content: #{@another_content.id}\n"22 22 end 23 23 … … 233 233 assert_equal 4, ContentBase.find(:all).size 234 234 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 235 240 contents_from_ferret = Content.multi_search('title:title') 236 241 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.size240 242 contents_from_ferret = Content.multi_search('*:title') 241 243 assert_equal 2, contents_from_ferret.size … … 334 336 assert_equal @another_content.id, contents_from_ferret.last.id 335 337 336 # find options337 contents_from_ferret = Content.find_by_contents('title', {}, :conditions => ["id=?",contents(:first).id])338 assert_equal 1, contents_from_ferret.size339 assert_equal contents(:first), contents_from_ferret.first340 341 # limit result set size to 1342 contents_from_ferret = Content.find_by_contents('title', :num_docs => 1)343 assert_equal 1, contents_from_ferret.size344 assert_equal contents(:first), contents_from_ferret.first345 346 # limit result set size to 1, starting with the second result347 contents_from_ferret = Content.find_by_contents('title', :num_docs => 1, :first_doc => 1)348 assert_equal 1, contents_from_ferret.size349 assert_equal @another_content.id, contents_from_ferret.first.id350 338 351 339 … … 387 375 assert_equal 1, contents_from_ferret.size 388 376 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 392 399 393 400 end
