diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 4f110e5..45c7f48 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -271,6 +271,7 @@ class CmsController < MyProfileController def search query = params[:q] results = profile.files.published.find_by_contents(query)[:results] + # results = @plugins.first(:find_by_contents, profile.files.published, query)[:results] render :text => article_list_to_json(results), :content_type => 'application/json' end diff --git a/app/controllers/public/profile_search_controller.rb b/app/controllers/public/profile_search_controller.rb index d6b1209..dd7b70f 100644 --- a/app/controllers/public/profile_search_controller.rb +++ b/app/controllers/public/profile_search_controller.rb @@ -11,7 +11,7 @@ class ProfileSearchController < PublicController if params[:where] == 'environment' redirect_to :controller => 'search', :query => @q else - @results = profile.articles.published.find_by_contents(@q, {:per_page => 10, :page => params[:page]})[:results] + @results = @plugins.first(:find_by_contents, profile.articles.published, @q, {:per_page => 10, :page => params[:page]})[:results] end end end diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 05d8c9d..dc086c5 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -19,7 +19,7 @@ class SearchController < PublicController no_design_blocks def index - @results = {} + @searches = {} @order = [] @names = {} @results_only = true @@ -33,12 +33,12 @@ class SearchController < PublicController end @asset = nil - render :action => @results.keys.first if @results.keys.size == 1 + render :action => @searches.keys.first if @searches.keys.size == 1 end # view the summary of one category def category_index - @results = {} + @searches = {} @order = [] @names = {} limit = MULTIPLE_SEARCH_LIMIT @@ -51,8 +51,8 @@ class SearchController < PublicController [ :articles, _('Contents'), :recent_articles ] ].each do |asset, name, filter| @order << asset - @results[asset] = @category.send(filter, limit) - raise "No total_entries for: #{asset}" unless @results[asset].respond_to?(:total_entries) + @searches[asset] = @category.send(filter, limit) + raise "No total_entries for: #{asset}" unless @searches[asset][:results].respond_to?(:total_entries) @names[asset] = name end end @@ -61,7 +61,8 @@ class SearchController < PublicController if @search_engine && !@empty_query full_text_search else - @results[@asset] = @environment.articles.public.send(@filter).paginate(paginate_options) + @searches[@asset] = {} + @searches[@asset][:results] = @environment.articles.public.send(@filter).paginate(paginate_options) end end @@ -73,7 +74,8 @@ class SearchController < PublicController if @search_engine && !@empty_query full_text_search else - @results[@asset] = visible_profiles(Person).send(@filter).paginate(paginate_options) + @searches[@asset] = {} + @searches[@asset][:results] = visible_profiles(Person).send(@filter).paginate(paginate_options) end end @@ -81,7 +83,8 @@ class SearchController < PublicController if @search_engine full_text_search else - @results[@asset] = @environment.products.send(@filter).paginate(paginate_options) + @searches[@asset] = {} + @searches[@asset][:results] = @environment.products.send(@filter).paginate(paginate_options) end end @@ -90,7 +93,8 @@ class SearchController < PublicController full_text_search else @filter_title = _('Enterprises from network') - @results[@asset] = visible_profiles(Enterprise, [{:products => :product_category}]).paginate(paginate_options) + @searches[@asset] = {} + @searches[@asset][:results] = visible_profiles(Enterprise, [{:products => :product_category}]).paginate(paginate_options) end end @@ -98,7 +102,8 @@ class SearchController < PublicController if @search_engine && !@empty_query full_text_search else - @results[@asset] = visible_profiles(Community).send(@filter).paginate(paginate_options) + @searches[@asset] = {} + @searches[@asset][:results] = visible_profiles(Community).send(@filter).paginate(paginate_options) end end @@ -121,10 +126,11 @@ class SearchController < PublicController if @search_engine && !@empty_query full_text_search else - @results[@asset] = date_range ? environment.events.by_range(date_range) : environment.events + @searches[@asset] = {} + @searches[@asset][:results] = date_range ? environment.events.by_range(date_range) : environment.events end - events = @results[@asset] + events = @searches[@asset][:results] @calendar = populate_calendar(date, events) @previous_calendar = populate_calendar(date - 1.month, events) @next_calendar = populate_calendar(date + 1.month, events) @@ -147,7 +153,7 @@ class SearchController < PublicController @tag = params[:tag] @tag_cache_key = "tag_#{CGI.escape(@tag.to_s)}_env_#{environment.id.to_s}_page_#{params[:npage]}" if is_cache_expired?(@tag_cache_key) - @results[@asset] = environment.articles.find_tagged_with(@tag).paginate(paginate_options) + @searches[@asset] = environment.articles.find_tagged_with(@tag).paginate(paginate_options) end end @@ -164,7 +170,7 @@ class SearchController < PublicController @asset = (params[:asset] || params[:action]).to_sym @order ||= [@asset] params[:display] ||= 'list' - @results ||= {} + @searches ||= {} @filter = filter @filter_title = filter_description(@asset, @filter) @@ -254,8 +260,8 @@ class SearchController < PublicController { :per_page => limit, :page => page } end - def full_text_search(options = {}) - @results[@asset] = @plugins.first(:full_text_search, @asset, @query, @category, paginate_options(params[:page])) + def full_text_search + @searches[@asset] = @plugins.first(:find_by_contents, asset_class(@asset), @query, paginate_options(params[:page]), {:category => @category}) end private diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 6f3bd65..2d51f78 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -18,13 +18,17 @@ module SearchHelper include EventsHelper def multiple_search? - ['index', 'category_index'].include?(params[:action]) or @results.size > 1 + ['index', 'category_index'].include?(params[:action]) or @searches.size > 1 end def map_search? !multiple_search? and params[:display] == 'map' end + def asset_class(asset) + asset.to_s.singularize.camelize.constantize + end + def search_page_title(title, category = nil) title = "

" + title title += ' - ' + category.name + '' if category diff --git a/app/models/region.rb b/app/models/region.rb index cd9a64b..6e807d8 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -4,10 +4,12 @@ class Region < Category require_dependency 'enterprise' # enterprises can also be validators + include Noosfero::Plugin::HotSpot + # searches for organizations that could become validators for this region. # search is passed as is to find_by_contents on Organization. def search_possible_validators(search) - Organization.find_by_contents(search)[:results].docs.reject {|item| self.validator_ids.include?(item.id) } + plugins.find_by_contents(Organization, search)[:results].docs.reject {|item| self.validator_ids.include?(item.id) } end def has_validator? diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index 79e802e..b1f2793 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -1,21 +1,21 @@
<% @order.each do |name| %> - <% results = @results[name] %> + <% search = @searches[name] %> -
"> - <% if !results.blank? %> +
"> + <% if !search[:results].blank? %> <% partial = partial_for_class(name.to_s.singularize.camelize.constantize) %> <% 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' ) %> + <% if search[:results].total_entries > SearchController::MULTIPLE_SEARCH_LIMIT %> + <%= link_to(_('see all (%d)') % search[:results].total_entries, params.merge(:action => name), :class => 'see-more' ) %> <% end %> <% end %>
    - <% results.each do |hit| %> + <% search[:results].each do |hit| %> <%= render :partial => partial_for_class(hit.class), :object => hit %> <% end %>
diff --git a/app/views/search/_google_maps.rhtml b/app/views/search/_google_maps.rhtml index a105be5..b9aaae1 100644 --- a/app/views/search/_google_maps.rhtml +++ b/app/views/search/_google_maps.rhtml @@ -13,7 +13,7 @@