| | 25 | end |
|---|
| | 26 | |
|---|
| | 27 | def test_rebuild_index |
|---|
| | 28 | Comment.ferret_index.query_delete('comment') |
|---|
| | 29 | comments_from_ferret = Comment.find_by_contents('comment AND fixture') |
|---|
| | 30 | assert comments_from_ferret.empty? |
|---|
| | 31 | Comment.rebuild_index |
|---|
| | 32 | comments_from_ferret = Comment.find_by_contents('comment AND fixture') |
|---|
| | 33 | assert_equal 2, comments_from_ferret.size |
|---|
| | 34 | end |
|---|
| | 35 | |
|---|
| | 36 | def test_total_hits |
|---|
| | 37 | comments_from_ferret = Comment.find_by_contents('comment AND fixture', :num_docs => 1) |
|---|
| | 38 | assert_equal 1, comments_from_ferret.size |
|---|
| | 39 | assert_equal 2, comments_from_ferret.total_hits |
|---|
| | 40 | end |
|---|
| | 41 | |
|---|
| | 42 | def test_find_all |
|---|
| | 43 | 20.times do |i| |
|---|
| | 44 | Comment.create( :author => 'multi-commenter', :content => "This is multicomment no #{i}" ) |
|---|
| | 45 | end |
|---|
| | 46 | assert_equal 10, (res = Comment.find_by_contents('multicomment')).size |
|---|
| | 47 | assert_equal 20, res.total_hits |
|---|
| | 48 | assert_equal 15, (res = Comment.find_by_contents('multicomment', :num_docs => 15)).size |
|---|
| | 49 | assert_equal 20, res.total_hits |
|---|
| | 50 | assert_equal 20, (res = Comment.find_by_contents('multicomment', :num_docs => :all)).size |
|---|
| | 51 | assert_equal 20, res.total_hits |
|---|
| | 52 | |
|---|
| | 53 | Comment.configuration[:max_results] = 15 |
|---|
| | 54 | assert_equal 15, (res = Comment.find_by_contents('multicomment', :num_docs => :all)).size |
|---|
| | 55 | assert_equal 20, res.total_hits |
|---|