Commit e66e4541b79a2483682e806216c47a5b3809f9d7

Authored by MoisesMachado
1 parent d8b607f9

ActionItem501: limiting the number of objects shown in the search results to 6 a…

…nd adding a counter of total hits on the 'see all' sub tab


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2144 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/search_controller.rb
... ... @@ -113,7 +113,7 @@ class SearchController < ApplicationController
113 113 # limit the number of results per page
114 114 # TODO: dont hardcore like this
115 115 def limit
116   - 10
  116 + (@searching.size == 1) ? 10 : 6
117 117 end
118 118  
119 119 public
... ...
app/models/category_finder.rb
... ... @@ -35,11 +35,7 @@ class CategoryFinder
35 35 def count(asset, query='', options={})
36 36 # because will_paginate needs a page
37 37 options = {:page => 1}.merge(options)
38   - if query.blank?
39   - find(asset, query, options).total_entries
40   - else
41   - find(asset, query, options).total_hits
42   - end
  38 + find(asset, query, options).total_entries
43 39 end
44 40  
45 41 def most_commented_articles(limit=10)
... ...
app/models/environment_finder.rb
... ... @@ -49,12 +49,7 @@ class EnvironmentFinder
49 49 def count(asset, query = '', options = {})
50 50 # because will_paginate needs a page
51 51 options = {:page => 1}.merge(options)
52   - if query.blank?
53   - # SLOW
54   - find(asset, query, options).total_entries
55   - else
56   - find(asset, query, options).total_hits
57   - end
  52 + find(asset, query, options).total_entries
58 53 end
59 54  
60 55 end
... ...
app/views/search/_display_results.rhtml
... ... @@ -17,7 +17,7 @@
17 17 <%= @names[name] %>
18 18 </h3>
19 19 <% end %>
20   - <%= link_to _('see all...'), params.merge(:action => 'index', :find_in => [ name ]), :class => 'see-more' %>
  20 + <%= link_to _('see all (%d)') % results.total_entries, params.merge(:action => 'index', :find_in => [ name ]), :class => 'see-more' %>
21 21 <% end %>
22 22 <% partial = partial_for_class results.first.class %>
23 23 <div class="search-results-innerbox search-results-type-<%= partial %> <%= 'common-profile-list-block' if partial == 'profile' %>">
... ...
test/unit/category_finder_test.rb
... ... @@ -215,7 +215,7 @@ class CategoryFinderTest &lt; ActiveSupport::TestCase
215 215  
216 216 @finder.expects(:find).with('people', 'my query', kind_of(Hash)).returns(results)
217 217  
218   - results.expects(:total_hits).returns(99)
  218 + results.expects(:total_entries).returns(99)
219 219  
220 220 assert_equal 99, @finder.count('people', 'my query', {})
221 221 end
... ...
test/unit/environment_finder_test.rb
... ... @@ -120,7 +120,7 @@ class EnvironmentFinderTest &lt; ActiveSupport::TestCase
120 120  
121 121 finder.expects(:find).with('people', 'my query', kind_of(Hash)).returns(results)
122 122  
123   - results.expects(:total_hits).returns(99)
  123 + results.expects(:total_entries).returns(99)
124 124  
125 125 assert_equal 99, finder.count('people', 'my query', {})
126 126 end
... ...