diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 1a17c1e..67c217a 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -2,35 +2,10 @@ class SearchController < ApplicationController helper TagsHelper - SEARCHES = [] - - def self.search(&block) - SEARCHES << block - end - protected - ############################################# - # XXX add yours searches here - ############################################# - - search do |query| - Article.find_by_contents(query) - end - - search do |query| - Profile.find_by_contents(query) - end - - search do |query| - Product.find_by_contents(query) - end - - # auxiliary method to search in all defined searches and collect the results - def search(query) - SEARCHES.inject([]) do |acc,finder| - acc += finder.call(query) - end.sort_by do |hit| + def search(klass, query) + klass.find_by_contents(query).sort_by do |hit| -(relevance_for(hit)) end end @@ -42,7 +17,8 @@ class SearchController < ApplicationController def index @query = params[:query] || '' @filtered_query = remove_stop_words(@query) - @results = search(@filtered_query) + @articles, @people, @enterprises, @communities, @products = + [Article, Person, Enterprise, Community, Product].map{ |klass| search(klass, @query) } end def tags diff --git a/app/views/search/_article.rhtml b/app/views/search/_article.rhtml index 7dac088..8006742 100644 --- a/app/views/search/_article.rhtml +++ b/app/views/search/_article.rhtml @@ -1,5 +1,3 @@ -
- <%= icon('cms', :style => 'float: left') %>
@@ -10,5 +8,4 @@ <%= strip_tags(hit.abstract) %>
-
diff --git a/app/views/search/_product.rhtml b/app/views/search/_product.rhtml index 63b63bd..1dc4678 100644 --- a/app/views/search/_product.rhtml +++ b/app/views/search/_product.rhtml @@ -1,15 +1,15 @@ -<%# FIXME add photo if available %> <%# FIXME add more information %> -
- <%= icon('product', :style => 'float: left') %>
- <%= image_tag(hit.image.public_filename(:minor), :style => 'float:right;') if hit.image %> - + <%= image_tag(hit.image.public_filename(:minor)) if hit.image %> + <%= link_to_product(hit) %> -
- <%= _('Price: %d') % hit.price %>
- <%= _('Suplier: %s') % link_to_homepage(hit.enterprise.name, hit.enterprise.identifier) if hit.enterprise %>
- <%= _('Category: %s') % link_to_category(hit.product_category) %> +
+
    +
  • <%= _('Price: %d') % hit.price %>
  • + <% if hit.enterprise %> +
  • <%= _('Suplier: %s') % link_to_homepage(hit.enterprise.name, hit.enterprise.identifier) %>
  • + <% end %> +
  • <%= _('Category: %s') % link_to_category(hit.product_category) %>
  • +
-
diff --git a/app/views/search/_profile.rhtml b/app/views/search/_profile.rhtml index 9c241b9..0d21f7f 100644 --- a/app/views/search/_profile.rhtml +++ b/app/views/search/_profile.rhtml @@ -1,11 +1,8 @@ -<%# FIXME add photo if available %> <%# FIXME add more information %> -
- <%= icon('person', :style => 'float: left') %> -
- - <%= link_to_homepage(hit.name, hit.identifier) %> - -
+
+ <%= image_tag(hit.image.public_filename(:minor)) if hit.image %> + + <%= link_to_homepage(hit.name, hit.identifier) %> +
diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml index 8cd8e32..de6d113 100644 --- a/app/views/search/index.rhtml +++ b/app/views/search/index.rhtml @@ -1,6 +1,16 @@

<%= _('Search results for "%s"') % @query %>

-<% @results.each do |hit| %> - <%= render :partial => partial_for_class(hit.class), :locals => { :hit => hit } %> -
+<% [ [@articles, _('Articles'), 'articles'], + [@people, _('People'), 'people'], + [@enterprises, _('Entreprises'), 'enterprises'], + [@communities, _('Communities'), 'communities'], + [@products, _('Products'), 'products'] ].each do |results, iname, name| %> + <% if results && !results.empty? %> +
+

<%= iname %>

+ <% results.each do |hit| %> + <%= render :partial => partial_for_class(hit.class), :locals => { :hit => hit } %> + <% end %> +
+ <% end %> <% end %> diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index cee8ef0..034dffb 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -16,9 +16,8 @@ class SearchControllerTest < Test::Unit::TestCase get 'index', :query => 'teste' assert_response :success assert_template 'index' - assert assigns('results') - assert assigns('results').include?(ent) - + assert assigns('enterprises') + assert assigns('enterprises').include?(ent) end should 'filter stop words' do -- libgit2 0.21.2