From 5954b0972f784a8d59bbe996e967349fd400328d Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 27 Feb 2013 20:29:56 -0300 Subject: [PATCH] Concentrating find_by_contents on application controller --- app/controllers/admin/region_validators_controller.rb | 2 +- app/controllers/application_controller.rb | 5 +++++ app/controllers/my_profile/cms_controller.rb | 3 +-- app/controllers/public/profile_search_controller.rb | 2 +- app/controllers/public/search_controller.rb | 19 +++++++------------ app/models/region.rb | 8 -------- app/views/layouts/application-ng.rhtml | 12 +++++------- app/views/search/_profile.rhtml | 2 +- app/views/search/category_index.rhtml | 2 +- app/views/search/index.rhtml | 2 +- lib/noosfero/plugin.rb | 7 ------- lib/noosfero/plugin/manager.rb | 2 +- plugins/solr/lib/solr_plugin.rb | 4 ---- test/unit/plugin_manager_test.rb | 10 ---------- 14 files changed, 24 insertions(+), 56 deletions(-) diff --git a/app/controllers/admin/region_validators_controller.rb b/app/controllers/admin/region_validators_controller.rb index 4388a7f..fe6bcb2 100644 --- a/app/controllers/admin/region_validators_controller.rb +++ b/app/controllers/admin/region_validators_controller.rb @@ -33,7 +33,7 @@ class RegionValidatorsController < AdminController def load_region_and_search @region = environment.regions.find(params[:id]) if params[:search] - @search = @region.search_possible_validators(params[:search]) + @search = find_by_contents(Organization, params[:search])[:results].docs.reject {|item| @region.validator_ids.include?(item.id) } end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7d51312..87715a7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -154,4 +154,9 @@ class ApplicationController < ActionController::Base end end + def find_by_contents(klass, query, paginate_options{}, options={}) + @plugins.first(:find_by_contents, klass, query, paginate_options, options) || + # Failback search using like + end + end diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index ccae169..85dba4b 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -270,8 +270,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] + results = 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 dd7b70f..f6bc0f8 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 = @plugins.first(:find_by_contents, profile.articles.published, @q, {:per_page => 10, :page => params[:page]})[:results] + @results = 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 dc086c5..b0a0e0f 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -8,7 +8,6 @@ class SearchController < PublicController before_filter :load_category before_filter :load_search_assets before_filter :load_query - before_filter :load_search_engine # Backwards compatibility with old URLs def redirect_asset_param @@ -58,7 +57,7 @@ class SearchController < PublicController end def articles - if @search_engine && !@empty_query + if !@empty_query full_text_search else @searches[@asset] = {} @@ -71,7 +70,7 @@ class SearchController < PublicController end def people - if @search_engine && !@empty_query + if !@empty_query full_text_search else @searches[@asset] = {} @@ -80,7 +79,7 @@ class SearchController < PublicController end def products - if @search_engine + if !@empty_query full_text_search else @searches[@asset] = {} @@ -89,7 +88,7 @@ class SearchController < PublicController end def enterprises - if @search_engine && !@empty_query + if !@empty_query full_text_search else @filter_title = _('Enterprises from network') @@ -99,7 +98,7 @@ class SearchController < PublicController end def communities - if @search_engine && !@empty_query + if !@empty_query full_text_search else @searches[@asset] = {} @@ -123,7 +122,7 @@ class SearchController < PublicController environment.events.by_day(@selected_day) end - if @search_engine && !@empty_query + if !@empty_query full_text_search else @searches[@asset] = {} @@ -192,10 +191,6 @@ class SearchController < PublicController end end - def load_search_engine - @search_engine = @plugins.first_plugin(:search_engine?) - end - FILTERS = %w( more_recent more_active @@ -261,7 +256,7 @@ class SearchController < PublicController end def full_text_search - @searches[@asset] = @plugins.first(:find_by_contents, asset_class(@asset), @query, paginate_options(params[:page]), {:category => @category}) + @searches[@asset] = find_by_contents(asset_class(@asset), @query, paginate_options(params[:page]), {:category => @category}) end private diff --git a/app/models/region.rb b/app/models/region.rb index 6e807d8..4aad293 100644 --- a/app/models/region.rb +++ b/app/models/region.rb @@ -4,14 +4,6 @@ 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) - plugins.find_by_contents(Organization, search)[:results].docs.reject {|item| self.validator_ids.include?(item.id) } - end - def has_validator? validators.count > 0 end diff --git a/app/views/layouts/application-ng.rhtml b/app/views/layouts/application-ng.rhtml index cc96b58..480e3f9 100644 --- a/app/views/layouts/application-ng.rhtml +++ b/app/views/layouts/application-ng.rhtml @@ -69,13 +69,11 @@ <% end %> - <% if @plugins.first(:search_engine?) %> -
- -
<%=_('Press Enter to send the search query.')%>
- <%= javascript_tag 'jQuery("#user form input").hint();' %> -
- <% end %> +
+ +
<%=_('Press Enter to send the search query.')%>
+ <%= javascript_tag 'jQuery("#user form input").hint();' %> +

diff --git a/app/views/search/_profile.rhtml b/app/views/search/_profile.rhtml index b2f665f..6717f40 100644 --- a/app/views/search/_profile.rhtml +++ b/app/views/search/_profile.rhtml @@ -1,5 +1,5 @@
  • -<% if @empty_query || multiple_search? || !profile.enterprise? || !@search_engine %> +<% if @empty_query || multiple_search? || !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/app/views/search/category_index.rhtml b/app/views/search/category_index.rhtml index b8859a5..7b2ee19 100644 --- a/app/views/search/category_index.rhtml +++ b/app/views/search/category_index.rhtml @@ -5,7 +5,7 @@ <% end %> <%= search_page_title(_('Search Results'), @category) %> - <%= render :partial => 'search_form', :locals => { :hint => '' } if @search_engine %> + <%= render :partial => 'search_form', :locals => { :hint => '' } %> <%= category_context(@category, params) %> <%= display_results %> diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml index e330cd4..ec950d0 100644 --- a/app/views/search/index.rhtml +++ b/app/views/search/index.rhtml @@ -5,7 +5,7 @@ <% end %> <%= search_page_title(_('Search Results'), @category) %> - <%= render :partial => 'search_form', :locals => { :hint => '' } if @search_engine %> + <%= render :partial => 'search_form', :locals => { :hint => '' } %> <%= category_context(@category, params) %> <%= display_results(@asset) %> diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index f78a1d4..f04acfe 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -351,18 +351,11 @@ class Noosfero::Plugin nil end - # -> Specifies plugin that works as a search engine - # returns = true/false - def search_engine? - false - end - # -> Finds objects by their contents # returns = {:results => [a, b, c, ...], ...} # P.S.: The plugin might add other informations on the return hash for its # own use in specific views def find_by_contents(klass, query, paginate_options={}, options={}) - {:results => []} end def method_missing(method, *args, &block) diff --git a/lib/noosfero/plugin/manager.rb b/lib/noosfero/plugin/manager.rb index d9431ff..ae51b3b 100644 --- a/lib/noosfero/plugin/manager.rb +++ b/lib/noosfero/plugin/manager.rb @@ -39,7 +39,7 @@ class Noosfero::Plugin::Manager result = plugin.send(event, *args) break if result.present? end - result || Noosfero::Plugin.new.send(event, *args) + result end def first_plugin(event, *args) diff --git a/plugins/solr/lib/solr_plugin.rb b/plugins/solr/lib/solr_plugin.rb index cd6a0a0..c814dc5 100644 --- a/plugins/solr/lib/solr_plugin.rb +++ b/plugins/solr/lib/solr_plugin.rb @@ -12,10 +12,6 @@ class SolrPlugin < Noosfero::Plugin _("Uses Solr as search engine.") end - def search_engine? - true - end - def find_by_contents(klass, query, paginate_options={}, options={}) category = options.delete(:category) solr_options = solr_options(class_asset(klass), category) diff --git a/test/unit/plugin_manager_test.rb b/test/unit/plugin_manager_test.rb index 41d0008..3a32c71 100644 --- a/test/unit/plugin_manager_test.rb +++ b/test/unit/plugin_manager_test.rb @@ -140,15 +140,5 @@ class PluginManagerTest < ActiveSupport::TestCase assert_equal Plugin2, manager.first_plugin(:random_event) end - should 'use default value defined on the base plugin class when no plugin enabled for the first method' do - class Noosfero::Plugin - def random_event - 1 - end - end - - assert_equal 1, manager.first(:random_event) - end - end -- libgit2 0.21.2