From a6c9836d33b832b0f0bf90370854f7b5990e4e72 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Sat, 1 Dec 2007 19:00:21 +0000 Subject: [PATCH] ActionItem25: making search results look better --- app/controllers/public/search_controller.rb | 4 +++- app/helpers/search_helper.rb | 7 +++++++ app/views/search/_article.rhtml | 18 +++++++++++------- app/views/search/_profile.rhtml | 10 ++++++---- app/views/search/index.rhtml | 2 +- public/stylesheets/search.css | 5 +++++ 6 files changed, 33 insertions(+), 13 deletions(-) diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 3425ff5..d31fc83 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -29,12 +29,14 @@ class SearchController < ApplicationController SEARCHES.inject([]) do |acc,finder| acc += finder.call(query) end.sort_by do |hit| - (hit.respond_to? :ferret_score) ? (1.0 - hit.ferret_score) : (-1.0) + -(relevance_for(hit)) end end public + include SearchHelper + def index @query = params[:query] || '' @results = search(@query) diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 26e7dc4..95ff74e 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -1,4 +1,5 @@ module SearchHelper + def partial_for_hit(klass) name = klass.name.underscore if File.exists?(File.join(RAILS_ROOT, 'app', 'views', 'search', "_#{name}.rhtml")) @@ -7,4 +8,10 @@ module SearchHelper partial_for_hit(klass.superclass) end end + + def relevance_for(hit) + n = (hit.ferret_score if hit.respond_to?(:ferret_score)) + n ||= 1.0 + (n * 100.0).round + end end diff --git a/app/views/search/_article.rhtml b/app/views/search/_article.rhtml index 13b4a0a..ec02f90 100644 --- a/app/views/search/_article.rhtml +++ b/app/views/search/_article.rhtml @@ -1,10 +1,14 @@
- - <%= design_display_icon('cms') %> - <%= link_to_document(hit) %> - -
-
- <%= hit.abstract %> + <%= icon('cms') %> +
+
+ + <%= link_to_document(hit) %> + +
+
+ <%= strip_tags(hit.abstract) %> +
+
diff --git a/app/views/search/_profile.rhtml b/app/views/search/_profile.rhtml index 9e9345b..fa0c2da 100644 --- a/app/views/search/_profile.rhtml +++ b/app/views/search/_profile.rhtml @@ -2,8 +2,10 @@ <%# FIXME add more information %>
- - <%= design_display_icon('person') %> - <%= link_to_homepage(hit.name, hit.identifier) %> - + <%= icon('person') %> +
+ + <%= link_to_homepage(hit.name, hit.identifier) %> + +
diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml index 6765094..77d396a 100644 --- a/app/views/search/index.rhtml +++ b/app/views/search/index.rhtml @@ -5,7 +5,7 @@ <% @results.each do |hit| %> <%= render :partial => partial_for_hit(hit.class), :locals => { :hit => hit } %>
- <%= _('Relevance: %d%%') % (hit.respond_to?(:ferret_score) ? (hit.ferret_score * 100.0).round : 100) %> + <%= _('Relevance: %d%%') % relevance_for(hit) %>

<% end %> diff --git a/public/stylesheets/search.css b/public/stylesheets/search.css index 8b5455c..dff2084 100644 --- a/public/stylesheets/search.css +++ b/public/stylesheets/search.css @@ -3,3 +3,8 @@ font-style: italic; color: gray; } + +.search-relevance, .search-result-text { + margin-left: 40px; +} + -- libgit2 0.21.2