Changeset 246
- Timestamp:
- 09/23/07 08:58:20 (1 year ago)
- Files:
-
- trunk/demo/app/models/comment.rb (modified) (1 diff)
- trunk/demo/app/models/shared_index1.rb (modified) (1 diff)
- trunk/demo/app/models/shared_index2.rb (modified) (1 diff)
- trunk/demo/test/functional/contents_controller_test.rb (modified) (1 diff)
- trunk/demo/test/unit/content_test.rb (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/demo/app/models/comment.rb
r142 r246 15 15 # do this in our custom to_doc method) 16 16 acts_as_ferret( :store_class_name => true, 17 :remote => ENV['AAF_REMOTE'] , # for testing drb remote indexing17 :remote => ENV['AAF_REMOTE'] == 'true', # for testing drb remote indexing 18 18 :additional_fields => { 19 19 :added => { :index => :untokenized, :store => :yes, :ignore => true } trunk/demo/app/models/shared_index1.rb
r186 r246 4 4 acts_as_ferret( :fields => { :name => { :store => :yes } }, 5 5 :single_index => true, 6 :remote => ENV['AAF_REMOTE'] ,6 :remote => ENV['AAF_REMOTE'] == 'true', 7 7 :ferret => { :default_field => DEFAULT_FIELDS } 8 8 ) trunk/demo/app/models/shared_index2.rb
r169 r246 2 2 acts_as_ferret( { :fields => { :name => { :store => :yes } }, 3 3 :single_index => true, 4 :remote => ENV['AAF_REMOTE'] },4 :remote => ENV['AAF_REMOTE'] == 'true' }, 5 5 { :default_field => SharedIndex1::DEFAULT_FIELDS } ) 6 6 end trunk/demo/test/functional/contents_controller_test.rb
r232 r246 46 46 47 47 assert_response :redirect 48 assert_redirected_to :action => 'list'48 assert_redirected_to contents_url 49 49 50 50 assert_equal num_contents + 1, Content.count trunk/demo/test/unit/content_test.rb
r244 r246 30 30 # weiter: single index / multisearch lazy loading 31 31 def test_lazy_loading 32 results = Content.find_ by_contents'description', :lazy => true32 results = Content.find_with_ferret 'description', :lazy => true 33 33 assert_equal 1, results.size 34 34 result = results.first … … 48 48 [ '"A.s. Haakon"', 'A.s. Haakon', 'à 49 49 mot A/S', 'A/S' ].each do |query| 50 assert_equal content, Content.find_ by_contents(query).first, query50 assert_equal content, Content.find_with_ferret(query).first, query 51 51 end 52 52 end … … 68 68 assert_equal "the <em>new</em> description", highlight.first 69 69 70 c1 = Content.find_ by_contents('new description').first70 c1 = Content.find_with_ferret('new description').first 71 71 assert_equal c, c1 72 72 highlight = c1.highlight('new') … … 85 85 content.save 86 86 assert content.ferret_enabled? 87 assert Content.find_ by_contents('"find me"').empty?87 assert Content.find_with_ferret('"find me"').empty? 88 88 89 89 content.save 90 90 assert content.ferret_enabled? 91 assert_equal content, Content.find_ by_contents('"find me"').first91 assert_equal content, Content.find_with_ferret('"find me"').first 92 92 end 93 93 … … 99 99 2.times do 100 100 content.save 101 assert Content.find_ by_contents('"find me"').empty?101 assert Content.find_with_ferret('"find me"').empty? 102 102 assert !content.ferret_enabled? 103 103 end … … 106 106 content.save 107 107 assert content.ferret_enabled? 108 assert_equal content, Content.find_ by_contents('"find me"').first108 assert_equal content, Content.find_with_ferret('"find me"').first 109 109 end 110 110 … … 116 116 2.times do 117 117 content.save 118 assert Content.find_ by_contents('"find me"').empty?118 assert Content.find_with_ferret('"find me"').empty? 119 119 assert !Content.ferret_enabled? 120 120 assert !content.ferret_enabled? … … 130 130 assert content.ferret_enabled? 131 131 assert Content.ferret_enabled? 132 assert_equal content, Content.find_ by_contents('"find me"').first132 assert_equal content, Content.find_with_ferret('"find me"').first 133 133 end 134 134 … … 138 138 2.times do 139 139 content.save 140 assert Content.find_ by_contents('"find me"').empty?140 assert Content.find_with_ferret('"find me"').empty? 141 141 assert !content.ferret_enabled? 142 142 end 143 143 end 144 144 assert content.ferret_enabled? 145 assert Content.find_ by_contents('"find me"').empty?145 assert Content.find_with_ferret('"find me"').empty? 146 146 147 147 content.disable_ferret(:index_when_finished) do 148 148 2.times do 149 149 content.save 150 assert Content.find_ by_contents('"find me"').empty?150 assert Content.find_with_ferret('"find me"').empty? 151 151 assert !content.ferret_enabled? 152 152 end 153 153 end 154 154 assert content.ferret_enabled? 155 assert_equal content, Content.find_ by_contents('"find me"').first155 assert_equal content, Content.find_with_ferret('"find me"').first 156 156 end 157 157 … … 161 161 2.times do 162 162 content.save 163 assert Content.find_ by_contents('"find me"').empty?163 assert Content.find_with_ferret('"find me"').empty? 164 164 assert !content.ferret_enabled? 165 165 assert !Content.ferret_enabled? … … 168 168 assert content.ferret_enabled? 169 169 assert Content.ferret_enabled? 170 assert Content.find_ by_contents('"find me"').empty?170 assert Content.find_with_ferret('"find me"').empty? 171 171 content.save 172 assert_equal content, Content.find_ by_contents('"find me"').first172 assert_equal content, Content.find_with_ferret('"find me"').first 173 173 end 174 174 … … 199 199 :description => 'look - an Ã') 200 200 content.save 201 result = Content.find_ by_contents('ÀöÌ')201 result = Content.find_with_ferret('ÀöÌ') 202 202 assert_equal content, result.first 203 result = Content.find_ by_contents('ÃŒml*')203 result = Content.find_with_ferret('ÃŒml*') 204 204 assert_equal content, result.first 205 result = Content.find_ by_contents('Ã')205 result = Content.find_with_ferret('Ã') 206 206 assert_equal content, result.first 207 207 end … … 230 230 231 231 def test_more_like_this 232 assert Content.find_ by_contents('lorem ipsum').empty?232 assert Content.find_with_ferret('lorem ipsum').empty? 233 233 @c1 = Content.new( :title => 'Content item 1', 234 234 :description => 'lorem ipsum dolor sit amet. lorem.' ) … … 237 237 :description => 'lorem ipsum dolor sit amet. lorem ipsum.' ) 238 238 @c2.save 239 assert_equal 2, Content.find_ by_contents('lorem ipsum').size239 assert_equal 2, Content.find_with_ferret('lorem ipsum').size 240 240 similar = @c1.more_like_this(:field_names => [:description], :min_doc_freq => 1, :min_term_freq => 1) 241 241 assert_equal 1, similar.size … … 244 244 245 245 def test_more_like_this_new_record 246 assert Content.find_ by_contents('lorem ipsum').empty?246 assert Content.find_with_ferret('lorem ipsum').empty? 247 247 @c1 = Content.new( :title => 'Content item 1', 248 248 :description => 'lorem ipsum dolor sit amet. lorem.' ) … … 250 250 :description => 'lorem ipsum dolor sit amet. lorem ipsum.' ) 251 251 @c2.save 252 assert_equal 1, Content.find_ by_contents('lorem ipsum').size252 assert_equal 1, Content.find_with_ferret('lorem ipsum').size 253 253 similar = @c1.more_like_this(:field_names => [:description], :min_doc_freq => 1, :min_term_freq => 1) 254 254 assert_equal 1, similar.size … … 261 261 262 262 def test_update 263 contents_from_ferret = Content.find_ by_contents('useless')263 contents_from_ferret = Content.find_with_ferret('useless') 264 264 assert_equal 1, contents_from_ferret.size 265 265 assert_equal contents(:first).id, contents_from_ferret.first.id 266 266 contents(:first).description = 'Updated description, still useless' 267 267 contents(:first).save 268 contents_from_ferret = Content.find_ by_contents('useless')268 contents_from_ferret = Content.find_with_ferret('useless') 269 269 assert_equal 1, contents_from_ferret.size 270 270 assert_equal contents(:first).id, contents_from_ferret.first.id 271 contents_from_ferret = Content.find_ by_contents('updated AND description')271 contents_from_ferret = Content.find_with_ferret('updated AND description') 272 272 assert_equal 1, contents_from_ferret.size 273 273 assert_equal contents(:first).id, contents_from_ferret.first.id 274 contents_from_ferret = Content.find_ by_contents('updated OR description')274 contents_from_ferret = Content.find_with_ferret('updated OR description') 275 275 assert_equal 1, contents_from_ferret.size 276 276 assert_equal contents(:first).id, contents_from_ferret.first.id … … 282 282 assert_equal 1, contents(:another).comment_count 283 283 # retrieve all content objects having 2 comments 284 result = Content.find_ by_contents('comment_count:2')284 result = Content.find_with_ferret('comment_count:2') 285 285 # TODO check why this range query returns 3 results 286 #result = Content.find_ by_contents('comment_count:[2 TO 1000]')286 #result = Content.find_with_ferret('comment_count:[2 TO 1000]') 287 287 # p result 288 288 assert_equal 2, result.size … … 293 293 def test_sorting 294 294 sorting = [ Ferret::Search::SortField.new(:id, :reverse => true) ] 295 result = Content.find_ by_contents('comment_count:2', :sort => sorting)295 result = Content.find_with_ferret('comment_count:2', :sort => sorting) 296 296 assert result.first.id > result.last.id 297 297 298 298 sorting = [ Ferret::Search::SortField.new(:id) ] 299 result = Content.find_ by_contents('comment_count:2', :sort => sorting)299 result = Content.find_with_ferret('comment_count:2', :sort => sorting) 300 300 assert result.first.id < result.last.id 301 301 … … 305 305 306 306 307 result = Content.find_ by_contents('comment_count:2', :sort => sorting)307 result = Content.find_with_ferret('comment_count:2', :sort => sorting) 308 308 assert result.first.id > result.last.id 309 309 end 310 310 311 311 def test_total_hits_multi 312 result = Content.total_hits('*:title OR *:comment', :m odels => [Comment])312 result = Content.total_hits('*:title OR *:comment', :multi => Comment) 313 313 assert_equal 5, result 314 314 end … … 316 316 def test_multi_search_sorting 317 317 sorting = [ Ferret::Search::SortField.new(:id) ] 318 result = Content. multi_search('*:title OR *:comment',[Comment], :sort => sorting)318 result = Content.find_with_ferret('*:title OR *:comment', :multi => [Comment], :sort => sorting) 319 319 assert_equal result.map(&:id).sort, result.map(&:id) 320 320 321 321 sorting = [ Ferret::Search::SortField.new(:title) ] 322 result = Content. multi_search('*:title OR *:comment',[Comment], :sort => sorting)322 result = Content.find_with_ferret('*:title OR *:comment', :multi => [Comment], :sort => sorting) 323 323 sorting = [ Ferret::Search::SortField.new(:title, :reverse => true) ] 324 result2 = Content. multi_search('*:title OR *:comment',[Comment], :sort => sorting)324 result2 = Content.find_with_ferret('*:title OR *:comment', :multi => [Comment], :sort => sorting) 325 325 assert result.any? 326 326 assert result.map(&:id) != result2.map(&:id) 327 327 328 328 sorting = [ Ferret::Search::SortField::SCORE ] 329 result = Content. multi_search('*:title OR *:comment', [Comment], :sort => sorting)329 result = Content.find_with_ferret('*:title OR *:comment', :multi => Comment, :sort => sorting) 330 330 assert result.any? 331 331 assert_equal result.map(&:ferret_score).sort.reverse, result.map(&:ferret_score) 332 332 333 333 sorting = [ Ferret::Search::SortField::SCORE_REV ] 334 result2 = Content. multi_search('*:title OR *:comment', [Comment], :sort => sorting)334 result2 = Content.find_with_ferret('*:title OR *:comment', :multi => Comment, :sort => sorting) 335 335 assert_equal result2.map(&:ferret_score).sort, result2.map(&:ferret_score) 336 336 assert_equal result.map(&:ferret_score), result2.map(&:ferret_score).reverse … … 339 339 def test_sort_class 340 340 sorting = Ferret::Search::Sort.new(Ferret::Search::SortField.new(:id, :reverse => true)) 341 result = Content.find_ by_contents('comment_count:2 OR comment_count:1', :sort => sorting)341 result = Content.find_with_ferret('comment_count:2 OR comment_count:1', :sort => sorting) 342 342 assert result.size > 2 343 343 assert result.first.id > result.last.id 344 result = Content.find_ by_contents('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2)344 result = Content.find_with_ferret('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2) 345 345 assert_equal 2, result.size 346 346 assert result.first.id > result.last.id … … 349 349 def test_sort_with_limit 350 350 sorting = [ Ferret::Search::SortField.new(:id) ] 351 result = Content.find_ by_contents('comment_count:2 OR comment_count:1', :sort => sorting)351 result = Content.find_with_ferret('comment_count:2 OR comment_count:1', :sort => sorting) 352 352 assert result.size > 2 353 353 assert result.first.id < result.last.id 354 result = Content.find_ by_contents('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2)354 result = Content.find_with_ferret('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2) 355 355 assert_equal 2, result.size 356 356 assert result.first.id < result.last.id 357 357 358 358 sorting = [ Ferret::Search::SortField.new(:id, :reverse => true) ] 359 result = Content.find_ by_contents('comment_count:2 OR comment_count:1', :sort => sorting)359 result = Content.find_with_ferret('comment_count:2 OR comment_count:1', :sort => sorting) 360 360 assert result.size > 2 361 361 assert result.first.id > result.last.id 362 result = Content.find_ by_contents('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2)362 result = Content.find_with_ferret('comment_count:2 OR comment_count:1', :sort => sorting, :limit => 2) 363 363 assert_equal 2, result.size 364 364 assert result.first.id > result.last.id … … 409 409 remove_index Content 410 410 Content.create(:title => 'another one', :description => 'description') 411 contents_from_ferret = Content.find_ by_contents('description:title')411 contents_from_ferret = Content.find_with_ferret('description:title') 412 412 assert_equal 1, contents_from_ferret.size 413 413 end 414 414 def test_find_rebuilds_index 415 415 remove_index Content 416 contents_from_ferret = Content.find_ by_contents('description:title')416 contents_from_ferret = Content.find_with_ferret('description:title') 417 417 assert_equal 1, contents_from_ferret.size 418 418 end … … 420 420 def test_multi_search_rebuilds_index 421 421 remove_index Content 422 contents_from_ferret = Content. multi_search('description:title')422 contents_from_ferret = Content.find_with_ferret('description:title', :multi => Comment) 423 423 assert_equal 1, contents_from_ferret.size 424 424 end … … 435 435 end 436 436 437 def remove_index(clazz)438 clazz.aaf_index.close # avoid io error when deleting the open index439 FileUtils.rm_rf clazz.aaf_configuration[:index_dir]440 assert !File.exists?("#{clazz.aaf_configuration[:index_dir]}/segments")441 end442 443 # segfaults (Feret 0.10.13)444 #def test_multi_searcher445 # s = MultiSearcher.new([Searcher.new(Content.class_index_dir), Searcher.new(Comment.class_index_dir)])446 # hits = s.search(TermQuery.new(:title,"title"))447 # assert_equal 1, hits.total_hits448 #end449 450 437 def test_multi_search_find_options 451 contents_from_ferret = Content. multi_search('title', [], {}, :order => 'id desc')438 contents_from_ferret = Content.find_with_ferret('title', { :multi => Comment }, :order => 'id desc') 452 439 assert_equal 2, contents_from_ferret.size 453 440 assert contents_from_ferret.first.id > contents_from_ferret.last.id 454 contents_from_ferret = Content. multi_search('title', [], {}, :order => 'id asc')441 contents_from_ferret = Content.find_with_ferret('title', { :multi => Comment }, :order => 'id asc') 455 442 assert contents_from_ferret.first.id < contents_from_ferret.last.id 456 443 457 contents_from_ferret = Content. multi_search('title', [], {}, :limit => 1)444 contents_from_ferret = Content.find_with_ferret('title', { :multi => Comment }, :limit => 1) 458 445 assert_equal 1, contents_from_ferret.size 459 446 end … … 498 485 499 486 def test_multi_search_lazy 500 contents_from_ferret = Content. multi_search('title', [Comment], :lazy => true)487 contents_from_ferret = Content.find_with_ferret('title', :multi => Comment, :lazy => true) 501 488 assert_equal 2, contents_from_ferret.size 502 489 contents_from_ferret.each do |record| … … 567 554 end 568 555 569 def test_find_ by_contents_boost556 def test_find_with_ferret_boost 570 557 # give description field higher boost: 571 contents_from_ferret = Content.find_ by_contents('title:title OR description:title^200')558 contents_from_ferret = Content.find_with_ferret('title:title OR description:title^200') 572 559 assert_equal 2, contents_from_ferret.size 573 560 assert_equal @another_content.id, contents_from_ferret.first.id … … 577 564 def test_default_and_queries 578 565 # multiple terms are ANDed by default... 579 contents_from_ferret = Content.find_ by_contents('monkey description')566 contents_from_ferret = Content.find_with_ferret('monkey description') 580 567 assert contents_from_ferret.empty? 581 568 # ...unless you connect them by OR 582 contents_from_ferret = Content.find_ by_contents('monkey OR description')569 contents_from_ferret = Content.find_with_ferret('monkey OR description') 583 570 assert_equal 1, contents_from_ferret.size 584 571 assert_equal contents(:first).id, contents_from_ferret.first.id … … 586 573 # multiple terms, each term has to occur in a document to be found, 587 574 # but they may occur in different fields 588 contents_from_ferret = Content.find_ by_contents('useless title')575 contents_from_ferret = Content.find_with_ferret('useless title') 589 576 assert_equal 1, contents_from_ferret.size 590 577 assert_equal contents(:first).id, contents_from_ferret.first.id 591 578 end 592 579 593 def test_find_ by_contents594 595 contents_from_ferret = Content.find_ by_contents('lorem ipsum not here')580 def test_find_with_ferret 581 582 contents_from_ferret = Content.find_with_ferret('lorem ipsum not here') 596 583 assert contents_from_ferret.empty? 597 584 598 contents_from_ferret = Content.find_ by_contents('title')585 contents_from_ferret = Content.find_with_ferret('title') 599 586 assert_equal 2, contents_from_ferret.size 600 587 # the title field has a higher boost value, so contents(:first) must be first in the list … … 604 591 605 592 606 contents_from_ferret = Content.find_ by_contents('useless')593 contents_from_ferret = Content.find_with_ferret('useless') 607 594 assert_equal 1, contents_from_ferret.size 608 595 assert_equal contents(:first).id, contents_from_ferret.first.id 609 596 610 597 # no monkeys here 611 contents_from_ferret = Content.find_ by_contents('monkey')598 contents_from_ferret = Content.find_with_ferret('monkey') 612 599 assert contents_from_ferret.empty? 613 600 … … 615 602 616 603 # search for an exact string by enclosing it in " 617 contents_from_ferret = Content.find_ by_contents('"useless title"')604 contents_from_ferret = Content.find_with_ferret('"useless title"') 618 605 assert contents_from_ferret.empty? 619 contents_from_ferret = Content.find_ by_contents('"useless description"')606 contents_from_ferret = Content.find_with_ferret('"useless description"') 620 607 assert_equal 1, contents_from_ferret.size 621 608 assert_equal contents(:first).id, contents_from_ferret.first.id 622 609 623 610 # wildcard query 624 contents_from_ferret = Content.find_ by_contents('use*')611 contents_from_ferret = Content.find_with_ferret('use*') 625 612 assert_equal 1, contents_from_ferret.size 626 613 627 614 # ferret-bug ? wildcard queries don't seem to get lowercased even when 628 615 # using StandardAnalyzer: 629 # contents_from_ferret = Content.find_ by_contents('Ti*')616 # contents_from_ferret = Content.find_with_ferret('Ti*') 630 617 # we should find both 'Title' and 'title' 631 618 # assert_equal 2, contents_from_ferret.size 632 619 # theory: :wild_lower parser option isn't used 633 620 634 contents_from_ferret = Content.find_ by_contents('ti*')621 contents_from_ferret = Content.find_with_ferret('ti*') 635 622 # this time we find both 'Title' and 'title' 636 623 assert_equal 2, contents_from_ferret.size 637 624 638 625 contents(:first).destroy 639 contents_from_ferret = Content.find_ by_contents('ti*')626 contents_from_ferret = Content.find_with_ferret('ti*') 640 627 # should find only one now 641 628 assert_equal 1, contents_from_ferret.size … … 643 630 end 644 631 645 def test_find_ by_contents_options632 def test_find_with_ferret_options 646 633 # find options 647 contents_from_ferret = Content.find_ by_contents('title', {}, :conditions => ["id=?",contents(:first).id])634 contents_from_ferret = Content.find_with_ferret('title', {}, :conditions => ["id=?",contents(:first).id]) 648 635 assert_equal 1, contents_from_ferret.size 649 636 assert_equal contents(:first), contents_from_ferret.first 650 637 651 638 # limit result set size to 1 652 contents_from_ferret = Content.find_ by_contents('title', :limit => 1)639 contents_from_ferret = Content.find_with_ferret('title', :limit => 1) 653 640 assert_equal 1, contents_from_ferret.size 654 641 assert_equal contents(:first), contents_from_ferret.first 655 642 656 643 # limit result set size to 1, starting with the second result 657 contents_from_ferret = Content.find_ by_contents('title', :limit => 1, :offset => 1)644 contents_from_ferret = Content.find_with_ferret('title', :limit => 1, :offset => 1) 658 645 assert_equal 1, contents_from_ferret.size 659 646 assert_equal @another_content.id, contents_from_ferret.first.id 660 647 661 648 # deprecated options, still supported 662 contents_from_ferret = Content.find_ by_contents('title', :num_docs => 1, :first_doc => 1)649 contents_from_ferret = Content.find_with_ferret('title', :num_docs => 1, :first_doc => 1) 663 650 assert_equal 1, contents_from_ferret.size 664 651 assert_equal @another_content.id, contents_from_ferret.first.id 665 652 653 end 654 655 def test_multi_pagination 656 more_contents(true) 657 658 r = Content.find_with_ferret 'title OR comment', :multi => Comment, :per_page => 10, :sort => 'title' 659 assert_equal 60, r.total_hits 660 assert_equal 10, r.size 661 assert_equal "0", r.first.description 662 assert_equal "9", r.last.description 663 assert_equal 1, r.current_page 664 assert_equal 6, r.page_count 665 666 r = Content.find_with_ferret 'title OR comment', :multi => Comment, :page => '2', :per_page => 10, :sort => 'title' 667 assert_equal 60, r.total_hits 668 assert_equal 10, r.size 669 assert_equal "10", r.first.description 670 assert_equal "19", r.last.description 671 assert_equal 2, r.current_page 672 assert_equal 6, r.page_count 673 674 r = Content.find_with_ferret 'title OR comment', :multi => Comment, :page => 7, :per_page => 10, :sort => 'title' 675 assert_equal 60, r.total_hits 676 assert_equal 0, r.size 666 677 end 667 678 … … 712 723 end 713 724 725 def test_multi_pagination_with_ar_conditions 726 more_contents(true) 727 id = Content.find_with_ferret('title').first.id 728 r = Content.find_with_ferret 'title OR comment', { :page => 1, :per_page => 10, :multi => Comment }, 729 { :conditions => ["id != ?", id], :order => 'id ASC' } 730 assert_equal 59, r.total_hits 731 assert_equal 10, r.size 732 assert_equal "Comment for content 00", r.first.content 733 assert_equal "Comment for content 09", r.last.content 734 assert_equal 1, r.current_page 735 assert_equal 6, r.page_count 736 737 r = Content.find_with_ferret 'title OR comment', { :page => 6, :per_page => 10, :multi => Comment }, 738 { :conditions => [ "id != ?", id ], :order => 'id ASC' } 739 assert_equal 59, r.total_hits 740 assert_equal 9, r.size 741 assert_equal "21", r.first.description 742 assert_equal "29", r.last.description 743 assert_equal 6, r.current_page 744 assert_equal 6, r.page_count 745 end 746 714 747 def test_pagination_with_more_conditions 715 748 more_contents 716 749 717 750 r = Content.find_with_ferret 'title -description:0', { :page => 1, :per_page => 10 }, 718 { :conditions => " description != '9'", :order => 'title ASC' }751 { :conditions => "contents.description != '9'", :order => 'title ASC' } 719 752 assert_equal 28, r.total_hits 720 753 assert_equal 10, r.size … … 762 795 763 796 protected 764 def more_contents 797 798 def more_contents(with_comments = false) 799 Comment.destroy_all if with_comments 765 800 Content.destroy_all 766 801 SpecialContent.destroy_all 767 802 30.times do |i| 768 Content.create! :title => sprintf("title of Content %02d", i), :description => "#{i}" 769 end 770 end 803 c = Content.create! :title => sprintf("title of Content %02d", i), :description => "#{i}" 804 c.comments.create! :content => sprintf("Comment for content %02d", i) if with_comments 805 end 806 end 807 808 def remove_index(clazz) 809 clazz.aaf_index.close # avoid io error when deleting the open index 810 FileUtils.rm_rf clazz.aaf_configuration[:index_dir] 811 assert !File.exists?("#{clazz.aaf_configuration[:index_dir]}/segments") 812 end 813 771 814 end
