| | 30 | def test_find_with_ferret_on_has_many_assoc |
|---|
| | 31 | c = contents(:first) |
|---|
| | 32 | comments = c.comments.find_with_ferret 'second' |
|---|
| | 33 | assert_equal 1, comments.size |
|---|
| | 34 | assert_equal comments(:another), comments.first |
|---|
| | 35 | end |
|---|
| | 36 | |
|---|
| | 37 | def test_total_hits_on_has_many_assoc |
|---|
| | 38 | c = contents(:first) |
|---|
| | 39 | assert_equal 2, Comment.find_with_ferret('second OR regarding').total_hits |
|---|
| | 40 | assert_equal 1, c.comments.find_with_ferret('second OR regarding').total_hits |
|---|
| | 41 | end |
|---|
| | 42 | |
|---|
| | 486 | |
|---|
| | 487 | |
|---|
| | 488 | more_contents(true) |
|---|
| | 489 | r = Content.find_with_ferret('title OR comment', { :multi => Comment, :limit => :all } ) |
|---|
| | 490 | assert_equal 60, r.size |
|---|
| | 491 | assert_equal 60, r.total_hits |
|---|
| | 492 | |
|---|
| | 493 | id = Content.find_with_ferret('title').first.id |
|---|
| | 494 | r = Content.find_with_ferret('title OR comment', { :multi => Comment, :limit => :all }, |
|---|
| | 495 | { :conditions => ["id != ?", id] }) |
|---|
| | 496 | assert_equal 59, r.size |
|---|
| | 497 | assert_equal 59, r.total_hits |
|---|
| | 498 | |
|---|
| | 499 | r = Content.find_with_ferret('title OR comment', { :multi => Comment, :limit => 20 }, |
|---|
| | 500 | { :conditions => ["id != ?", id] }) |
|---|
| | 501 | assert_equal 20, r.size |
|---|
| | 502 | assert_equal 59, r.total_hits |
|---|
| | 503 | |
|---|
| | 504 | r = Content.find_with_ferret('title OR comment', { :multi => Comment }, |
|---|
| | 505 | { :conditions => ["id != ?", id], :limit => 20 }) |
|---|
| | 506 | assert_equal 20, r.size |
|---|
| | 507 | assert_equal 59, r.total_hits |
|---|
| 477 | | contents_from_ferret = Content.multi_search('description:title') |
|---|
| 478 | | assert_equal 1, contents_from_ferret.size |
|---|
| 479 | | contents_from_ferret = Content.multi_search('title:title OR description:title') |
|---|
| 480 | | assert_equal 2, contents_from_ferret.size |
|---|
| 481 | | contents_from_ferret = Content.multi_search('title:title') |
|---|
| 482 | | assert_equal 1, contents_from_ferret.size |
|---|
| 483 | | contents_from_ferret = Content.multi_search('*:title') |
|---|
| 484 | | assert_equal 2, contents_from_ferret.size |
|---|
| 485 | | contents_from_ferret = Content.multi_search('title') |
|---|
| | 514 | contents_from_ferret = Content.find_with_ferret('description:title', :multi => []) |
|---|
| | 515 | assert_equal 1, contents_from_ferret.size |
|---|
| | 516 | contents_from_ferret = Content.find_with_ferret('title:title OR description:title', :multi => []) |
|---|
| | 517 | assert_equal 2, contents_from_ferret.size |
|---|
| | 518 | contents_from_ferret = Content.find_with_ferret('title:title', :multi => []) |
|---|
| | 519 | assert_equal 1, contents_from_ferret.size |
|---|
| | 520 | contents_from_ferret = Content.find_with_ferret('*:title', :multi => []) |
|---|
| | 521 | assert_equal 2, contents_from_ferret.size |
|---|
| | 522 | contents_from_ferret = Content.find_with_ferret('title', :multi => []) |
|---|
| 491 | | contents_from_ferret = Content.multi_search('title', []) |
|---|
| 492 | | assert_equal 2, contents_from_ferret.size |
|---|
| 493 | | contents_from_ferret = Content.multi_search('title', [], :limit => 1) |
|---|
| 494 | | assert_equal 1, contents_from_ferret.size |
|---|
| 495 | | contents_from_ferret = Content.multi_search('title', [], :offset => 1) |
|---|
| 496 | | assert_equal 1, contents_from_ferret.size |
|---|
| 497 | | |
|---|
| 498 | | contents_from_ferret = Content.multi_search('title:title OR content:comment OR description:title', [Comment]) |
|---|
| | 528 | contents_from_ferret = Content.find_with_ferret('title', :multi => []) |
|---|
| | 529 | assert_equal 2, contents_from_ferret.size |
|---|
| | 530 | contents_from_ferret = Content.find_with_ferret('title', :multi => [], :limit => 1) |
|---|
| | 531 | assert_equal 1, contents_from_ferret.size |
|---|
| | 532 | contents_from_ferret = Content.find_with_ferret('title', :multi => [], :offset => 1) |
|---|
| | 533 | assert_equal 1, contents_from_ferret.size |
|---|
| | 534 | |
|---|
| | 535 | contents_from_ferret = Content.find_with_ferret('title:title OR content:comment OR description:title', :multi => [Comment]) |
|---|
| 500 | | contents_from_ferret = Content.multi_search('title:title OR content:comment OR description:title', [Comment], :limit => 2) |
|---|
| 501 | | assert_equal 2, contents_from_ferret.size |
|---|
| 502 | | |
|---|
| 503 | | contents_from_ferret = Content.multi_search('*:title OR *:comment', Comment) |
|---|
| | 537 | contents_from_ferret = Content.find_with_ferret('title:title OR content:comment OR description:title', :multi => [Comment], :limit => 2) |
|---|
| | 538 | assert_equal 2, contents_from_ferret.size |
|---|
| | 539 | |
|---|
| | 540 | contents_from_ferret = Content.find_with_ferret('*:title OR *:comment', :multi => Comment) |
|---|
| | 763 | end |
|---|
| | 764 | |
|---|
| | 765 | def test_limits_and_offsets_with_ar_conditions |
|---|
| | 766 | more_contents |
|---|
| | 767 | |
|---|
| | 768 | r = Content.find_with_ferret 'title', { :limit => 10, :offset => 0 }, |
|---|
| | 769 | { :conditions => "description != '0'", :order => 'title ASC' } |
|---|
| | 770 | assert_equal 29, r.total_hits |
|---|
| | 771 | assert_equal 10, r.size |
|---|
| | 772 | assert_equal "1", r.first.description |
|---|
| | 773 | assert_equal "10", r.last.description |
|---|
| | 774 | |
|---|
| | 775 | r = Content.find_with_ferret 'title', { :limit => 10, :offset => 10 }, |
|---|
| | 776 | { :conditions => "description != '0'", :order => 'title ASC' } |
|---|
| | 777 | assert_equal 29, r.total_hits |
|---|
| | 778 | assert_equal 10, r.size |
|---|
| | 779 | assert_equal "11", r.first.description |
|---|
| | 780 | assert_equal "20", r.last.description |
|---|
| | 781 | |
|---|
| | 782 | r = Content.find_with_ferret 'title', { }, |
|---|
| | 783 | { :conditions => "description != '0'", :order => 'title ASC', |
|---|
| | 784 | :limit => 10, :offset => 0 } |
|---|
| | 785 | assert_equal 29, r.total_hits |
|---|
| | 786 | assert_equal 10, r.size |
|---|
| | 787 | assert_equal "1", r.first.description |
|---|
| | 788 | assert_equal "10", r.last.description |
|---|
| | 789 | |
|---|
| | 790 | r = Content.find_with_ferret 'title', { }, |
|---|
| | 791 | { :conditions => "description != '0'", :order => 'title ASC', |
|---|
| | 792 | :limit => 10, :offset => 10 } |
|---|
| | 793 | assert_equal 29, r.total_hits |
|---|
| | 794 | assert_equal 10, r.size |
|---|
| | 795 | assert_equal "11", r.first.description |
|---|
| | 796 | assert_equal "20", r.last.description |
|---|