Commit a6c9836d33b832b0f0bf90370854f7b5990e4e72

Authored by AntonioTerceiro
1 parent 0eb087ba

ActionItem25: making search results look better



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1007 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/search_controller.rb
@@ -29,12 +29,14 @@ class SearchController < ApplicationController @@ -29,12 +29,14 @@ class SearchController < ApplicationController
29 SEARCHES.inject([]) do |acc,finder| 29 SEARCHES.inject([]) do |acc,finder|
30 acc += finder.call(query) 30 acc += finder.call(query)
31 end.sort_by do |hit| 31 end.sort_by do |hit|
32 - (hit.respond_to? :ferret_score) ? (1.0 - hit.ferret_score) : (-1.0) 32 + -(relevance_for(hit))
33 end 33 end
34 end 34 end
35 35
36 public 36 public
37 37
  38 + include SearchHelper
  39 +
38 def index 40 def index
39 @query = params[:query] || '' 41 @query = params[:query] || ''
40 @results = search(@query) 42 @results = search(@query)
app/helpers/search_helper.rb
1 module SearchHelper 1 module SearchHelper
  2 +
2 def partial_for_hit(klass) 3 def partial_for_hit(klass)
3 name = klass.name.underscore 4 name = klass.name.underscore
4 if File.exists?(File.join(RAILS_ROOT, 'app', 'views', 'search', "_#{name}.rhtml")) 5 if File.exists?(File.join(RAILS_ROOT, 'app', 'views', 'search', "_#{name}.rhtml"))
@@ -7,4 +8,10 @@ module SearchHelper @@ -7,4 +8,10 @@ module SearchHelper
7 partial_for_hit(klass.superclass) 8 partial_for_hit(klass.superclass)
8 end 9 end
9 end 10 end
  11 +
  12 + def relevance_for(hit)
  13 + n = (hit.ferret_score if hit.respond_to?(:ferret_score))
  14 + n ||= 1.0
  15 + (n * 100.0).round
  16 + end
10 end 17 end
app/views/search/_article.rhtml
1 <div> 1 <div>
2 - <strong>  
3 - <%= design_display_icon('cms') %>  
4 - <%= link_to_document(hit) %>  
5 - </strong>  
6 -</div>  
7 -<div>  
8 - <%= hit.abstract %> 2 + <%= icon('cms') %>
  3 + <div class='search-result-text'>
  4 + <div>
  5 + <strong>
  6 + <%= link_to_document(hit) %>
  7 + </strong>
  8 + </div>
  9 + <div>
  10 + <%= strip_tags(hit.abstract) %>
  11 + </div>
  12 + </div>
9 </div> 13 </div>
10 14
app/views/search/_profile.rhtml
@@ -2,8 +2,10 @@ @@ -2,8 +2,10 @@
2 <%# FIXME add more information %> 2 <%# FIXME add more information %>
3 3
4 <div> 4 <div>
5 - <strong>  
6 - <%= design_display_icon('person') %>  
7 - <%= link_to_homepage(hit.name, hit.identifier) %>  
8 - </strong> 5 + <%= icon('person') %>
  6 + <div class='search-result-text'>
  7 + <strong>
  8 + <%= link_to_homepage(hit.name, hit.identifier) %>
  9 + </strong>
  10 + </div>
9 </div> 11 </div>
app/views/search/index.rhtml
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 <% @results.each do |hit| %> 5 <% @results.each do |hit| %>
6 <%= render :partial => partial_for_hit(hit.class), :locals => { :hit => hit } %> 6 <%= render :partial => partial_for_hit(hit.class), :locals => { :hit => hit } %>
7 <div class='search-relevance'> 7 <div class='search-relevance'>
8 - <%= _('Relevance: %d%%') % (hit.respond_to?(:ferret_score) ? (hit.ferret_score * 100.0).round : 100) %> 8 + <%= _('Relevance: %d%%') % relevance_for(hit) %>
9 </div> 9 </div>
10 <br style='clear: left'/> 10 <br style='clear: left'/>
11 <% end %> 11 <% end %>
public/stylesheets/search.css
@@ -3,3 +3,8 @@ @@ -3,3 +3,8 @@
3 font-style: italic; 3 font-style: italic;
4 color: gray; 4 color: gray;
5 } 5 }
  6 +
  7 +.search-relevance, .search-result-text {
  8 + margin-left: 40px;
  9 +}
  10 +