From 54b00182f9c26156a76c80a95f5092adf965239e Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Thu, 10 Jan 2013 03:25:39 +0000 Subject: [PATCH] [pluginize-solr] Moving index back --- app/controllers/public/search_controller.rb | 23 +++++++++++++++++++++-- app/helpers/search_helper.rb | 2 +- app/views/search/_display_results.rhtml | 2 +- app/views/search/index.rhtml | 29 +++++++++++++++++++++++++++++ plugins/solr/lib/solr_plugin.rb | 7 ++++++- plugins/solr/lib/solr_plugin/results_helper.rb | 4 ++++ 6 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 app/views/search/index.rhtml diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 7f1dcd7..e17e97f 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -18,6 +18,25 @@ class SearchController < PublicController no_design_blocks + def index + @results = {} + @order = [] + @names = {} + @results_only = true + + @enabled_searches.select { |key,description| @searching[key] }.each do |key, description| + load_query + @asset = key + send(:get_results, key) + @order << key + @names[key] = getterm(description) + end + @asset = nil + + render :action => @results.keys.first if @results.keys.size == 1 + end + + def articles if @search_engine && !@empty_query full_text_search @@ -127,7 +146,7 @@ class SearchController < PublicController protected def load_query - @asset = params[:action].to_sym + @asset = (params[:asset] || params[:action]).to_sym @order ||= [@asset] params[:display] ||= 'list' @results ||= {} @@ -196,7 +215,7 @@ class SearchController < PublicController @titles = {} @enabled_searches.each do |key, name| @titles[key] = _(name) - @searching[key] = params[:action] == key.to_s + @searching[key] = params[:action] == 'index' || params[:action] == key.to_s end @names = @titles if @names.nil? end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 18910e0..c1ec497 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -18,7 +18,7 @@ module SearchHelper include EventsHelper def multiple_search? - @results.size > 1 + ['index', 'category_index'].include?(params[:action]) or @results.size > 1 end def map_search? diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index d18ba70..79e802e 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -4,7 +4,7 @@
"> <% if !results.blank? %> - <% partial = partial_for_class(results.first.class.class_name.constantize) %> + <% partial = partial_for_class(name.to_s.singularize.camelize.constantize) %> <% if multiple_search? %>

<%= @names[name] %>

diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml new file mode 100644 index 0000000..e330cd4 --- /dev/null +++ b/app/views/search/index.rhtml @@ -0,0 +1,29 @@ +
"> + + <% if @category %> +
<%= image_tag(@category.image.public_filename(:thumb), :id => 'category-image') if @category.image %>
+ <% end %> + + <%= search_page_title(_('Search Results'), @category) %> + <%= render :partial => 'search_form', :locals => { :hint => '' } if @search_engine %> + <%= category_context(@category, params) %> + <%= display_results(@asset) %> + +
+ <% if @category %> +

<%= _('Sub-categories') %>

+ <% if @category.children.empty? %> + <%= _('No sub-categories') %> + <% else %> +
    + <% @category.children.each do |c| %> +
  • <%= link_to_category c, false %>
  • + <% end %> +
+ <% end %> + <% end %> +
+ +
+ +
diff --git a/plugins/solr/lib/solr_plugin.rb b/plugins/solr/lib/solr_plugin.rb index 2e8ea22..444f45d 100644 --- a/plugins/solr/lib/solr_plugin.rb +++ b/plugins/solr/lib/solr_plugin.rb @@ -20,7 +20,12 @@ class SolrPlugin < Noosfero::Plugin asset_class = asset_class(asset) solr_options = solr_options(asset, category) solr_options.merge!(products_options(context.send(:user))) if asset == :products && empty_query?(query, category) - asset_class.find_by_contents(query, paginate_options, solr_options) + search = asset_class.find_by_contents(query, paginate_options, solr_options) + if context.params[:action] == 'index' + return search[:results] + else + return search + end end end diff --git a/plugins/solr/lib/solr_plugin/results_helper.rb b/plugins/solr/lib/solr_plugin/results_helper.rb index 96b92b6..f0adfe4 100644 --- a/plugins/solr/lib/solr_plugin/results_helper.rb +++ b/plugins/solr/lib/solr_plugin/results_helper.rb @@ -1,5 +1,9 @@ class SolrPlugin < Noosfero::Plugin module ResultsHelper + def asset_class(asset) + asset.to_s.singularize.camelize.constantize + end + def set_results_variables if @results[@asset].kind_of?(Hash) ret = @results[@asset] -- libgit2 0.21.2