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 29 SEARCHES.inject([]) do |acc,finder|
30 30 acc += finder.call(query)
31 31 end.sort_by do |hit|
32   - (hit.respond_to? :ferret_score) ? (1.0 - hit.ferret_score) : (-1.0)
  32 + -(relevance_for(hit))
33 33 end
34 34 end
35 35  
36 36 public
37 37  
  38 + include SearchHelper
  39 +
38 40 def index
39 41 @query = params[:query] || ''
40 42 @results = search(@query)
... ...
app/helpers/search_helper.rb
1 1 module SearchHelper
  2 +
2 3 def partial_for_hit(klass)
3 4 name = klass.name.underscore
4 5 if File.exists?(File.join(RAILS_ROOT, 'app', 'views', 'search', "_#{name}.rhtml"))
... ... @@ -7,4 +8,10 @@ module SearchHelper
7 8 partial_for_hit(klass.superclass)
8 9 end
9 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 17 end
... ...
app/views/search/_article.rhtml
1 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 13 </div>
10 14  
... ...
app/views/search/_profile.rhtml
... ... @@ -2,8 +2,10 @@
2 2 <%# FIXME add more information %>
3 3  
4 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 11 </div>
... ...
app/views/search/index.rhtml
... ... @@ -5,7 +5,7 @@
5 5 <% @results.each do |hit| %>
6 6 <%= render :partial => partial_for_hit(hit.class), :locals => { :hit => hit } %>
7 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 9 </div>
10 10 <br style='clear: left'/>
11 11 <% end %>
... ...
public/stylesheets/search.css
... ... @@ -3,3 +3,8 @@
3 3 font-style: italic;
4 4 color: gray;
5 5 }
  6 +
  7 +.search-relevance, .search-result-text {
  8 + margin-left: 40px;
  9 +}
  10 +
... ...