diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 80ad050..9923541 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -250,10 +250,9 @@ class SearchController < PublicController end def limit - searching = @searching.values.select{ |v| v } - if params[:display] == 'map' + if map_search? MAP_SEARCH_LIMIT - elsif searching.size <= 1 + elsif !multiple_search? if [:people, :communities].include? @asset BLOCKS_SEARCH_LIMIT elsif @asset == :enterprises and @empty_query @@ -267,31 +266,34 @@ class SearchController < PublicController end def paginate_options(page = params[:page]) + page = 1 if multiple_search? or params[:display] == 'map' { :per_page => limit, :page => page } end def full_text_search(filters = [], options = {}) paginate_options = paginate_options(params[:page]) asset_class = asset_class(@asset) - solr_options = options - if !@results_only and asset_class.respond_to? :facets - solr_options.merge! asset_class.facets_find_options(params[:facet]) - solr_options[:all_facets] = true - solr_options[:limit] = 0 if @facets_only - end - solr_options[:filter_queries] ||= [] - solr_options[:filter_queries] += filters - solr_options[:filter_queries] << "environment_id:#{environment.id}" - solr_options[:filter_queries] << asset_class.facet_category_query.call(@category) if @category - - solr_options[:boost_functions] ||= [] - params[:order_by] = nil if params[:order_by] == 'none' - if params[:order_by] - order = SortOptions[@asset][params[:order_by].to_sym] - raise "Unknown order by" if order.nil? - order[:solr_opts].each do |opt, value| - solr_options[opt] = value.is_a?(Proc) ? instance_eval(&value) : value + pg_options = paginate_options(params[:page]) + + if !multiple_search? + if !@results_only and asset_class.respond_to? :facets + solr_options.merge! asset_class.facets_find_options(params[:facet]) + solr_options[:all_facets] = true + end + solr_options[:filter_queries] ||= [] + solr_options[:filter_queries] += filters + solr_options[:filter_queries] << "environment_id:#{environment.id}" + solr_options[:filter_queries] << asset_class.facet_category_query.call(@category) if @category + + solr_options[:boost_functions] ||= [] + params[:order_by] = nil if params[:order_by] == 'none' + if params[:order_by] + order = SortOptions[@asset][params[:order_by].to_sym] + raise "Unknown order by" if order.nil? + order[:solr_opts].each do |opt, value| + solr_options[opt] = value.is_a?(Proc) ? instance_eval(&value) : value + end end end diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index a4f7cdc..2edc315 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -45,6 +45,14 @@ module SearchHelper # FIXME remove it after search_controler refactored include EventsHelper + def multiple_search? + ['index', 'category_index'].include?(params[:action]) or @results.size > 1 + end + + def map_search? + !@query.blank? and !multiple_search? and params[:display] == 'map' + end + def search_page_title(title, category = nil) title = "

" + title title += '' + category.name + '' if category @@ -58,8 +66,8 @@ module SearchHelper :align => 'center', :class => 'search-category-context') if category end - def display_results(use_map = false) - if params[:display] == 'map' && use_map + def display_results(map_capable = false) + if map_capable and map_search? partial = 'google_maps' klass = 'map' else diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index 6501b65..47c930d 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -1,4 +1,4 @@ -
+
<% @order.each do |name| %> <% results = @results[name] %> <% empty = results.nil? || results.empty? %> @@ -7,7 +7,7 @@ <% if not empty %> <% partial = partial_for_class(results.first.class.class_name.constantize) %> - <% if @results.size > 1 %> + <% if multiple_search? %>

<%= @names[name] %>

<% if results.total_entries > SearchController::MULTIPLE_SEARCH_LIMIT %> <%= link_to(_('see all (%d)') % results.total_entries, params.merge(:action => name), :class => 'see-more' ) %> @@ -22,9 +22,10 @@
<% else %> - <% if @results.size > 1 %> + <% if multiple_search? %>

<%= @names[name] %>

<% end %> +
<%= _('None') %>
diff --git a/app/views/search/_profile.rhtml b/app/views/search/_profile.rhtml index e50f253..c0daf94 100644 --- a/app/views/search/_profile.rhtml +++ b/app/views/search/_profile.rhtml @@ -1,5 +1,5 @@
  • -<% if @empty_query or @results.size > 1 or !profile.enterprise? %> +<% if @empty_query or multiple_search? or !profile.enterprise? %> <%= profile_image_link profile, :portrait, 'div', @filter == 'more_recent' ? profile.send(@filter + '_label') + show_date(profile.created_at) : profile.send(@filter + '_label') %> <% else %> diff --git a/test/unit/search_helper_test.rb b/test/unit/search_helper_test.rb index 559e744..73bddd1 100644 --- a/test/unit/search_helper_test.rb +++ b/test/unit/search_helper_test.rb @@ -4,6 +4,28 @@ class SearchHelperTest < ActiveSupport::TestCase include SearchHelper + should 'return whether on a multiple search' do + stubs(:params).returns({:action => 'index', :display => 'map'}) + @results = {:articles => [1,2], :products => [1,2]} + assert multiple_search? + + stubs(:params).returns({:action => 'products', :display => 'map'}) + @results = {:products => [1,2]} + assert !multiple_search? + end + + should 'return whether on a map search' do + stubs(:params).returns({:action => 'index', :display => 'map'}) + @results = {:articles => [1,2], :products => [1,2]} + @query = '' + assert !map_search? + + stubs(:params).returns({:action => 'products', :display => 'map'}) + @results = {:products => [1,2]} + @query = 'test' + assert map_search? + end + should 'display search page title' do title = 'page_title' assert_equal search_page_title(title), '

    page_title

    ' @@ -35,6 +57,8 @@ class SearchHelperTest < ActiveSupport::TestCase should 'display results with map' do stubs(:params).returns({:display => 'map'}) + @query = 'test' + @results = {:products => [1,2]} expects('render').with({:partial => 'google_maps'}).returns('render_return') expects('content_tag').with('div', 'render_return', :class => 'map-or-list-search-results map') display_results true @@ -231,7 +255,6 @@ class SearchHelperTest < ActiveSupport::TestCase end end - should 'return asset class from string' do asset_names = ['products', 'events', 'articles', 'enterprises', 'people', 'communities'] asset_classes = [Product, Event, Article, Enterprise, Person, Community] -- libgit2 0.21.2