Commit 5954b0972f784a8d59bbe996e967349fd400328d
1 parent
00620c69
Exists in
staging
and in
42 other branches
Concentrating find_by_contents on application controller
Showing
14 changed files
with
24 additions
and
56 deletions
Show diff stats
app/controllers/admin/region_validators_controller.rb
| ... | ... | @@ -33,7 +33,7 @@ class RegionValidatorsController < AdminController |
| 33 | 33 | def load_region_and_search |
| 34 | 34 | @region = environment.regions.find(params[:id]) |
| 35 | 35 | if params[:search] |
| 36 | - @search = @region.search_possible_validators(params[:search]) | |
| 36 | + @search = find_by_contents(Organization, params[:search])[:results].docs.reject {|item| @region.validator_ids.include?(item.id) } | |
| 37 | 37 | end |
| 38 | 38 | end |
| 39 | 39 | ... | ... |
app/controllers/application_controller.rb
| ... | ... | @@ -154,4 +154,9 @@ class ApplicationController < ActionController::Base |
| 154 | 154 | end |
| 155 | 155 | end |
| 156 | 156 | |
| 157 | + def find_by_contents(klass, query, paginate_options{}, options={}) | |
| 158 | + @plugins.first(:find_by_contents, klass, query, paginate_options, options) || | |
| 159 | + # Failback search using like | |
| 160 | + end | |
| 161 | + | |
| 157 | 162 | end | ... | ... |
app/controllers/my_profile/cms_controller.rb
| ... | ... | @@ -270,8 +270,7 @@ class CmsController < MyProfileController |
| 270 | 270 | |
| 271 | 271 | def search |
| 272 | 272 | query = params[:q] |
| 273 | - results = profile.files.published.find_by_contents(query)[:results] | |
| 274 | - # results = @plugins.first(:find_by_contents, profile.files.published, query)[:results] | |
| 273 | + results = find_by_contents(profile.files.published, query)[:results] | |
| 275 | 274 | render :text => article_list_to_json(results), :content_type => 'application/json' |
| 276 | 275 | end |
| 277 | 276 | ... | ... |
app/controllers/public/profile_search_controller.rb
| ... | ... | @@ -11,7 +11,7 @@ class ProfileSearchController < PublicController |
| 11 | 11 | if params[:where] == 'environment' |
| 12 | 12 | redirect_to :controller => 'search', :query => @q |
| 13 | 13 | else |
| 14 | - @results = @plugins.first(:find_by_contents, profile.articles.published, @q, {:per_page => 10, :page => params[:page]})[:results] | |
| 14 | + @results = find_by_contents(profile.articles.published, @q, {:per_page => 10, :page => params[:page]})[:results] | |
| 15 | 15 | end |
| 16 | 16 | end |
| 17 | 17 | end | ... | ... |
app/controllers/public/search_controller.rb
| ... | ... | @@ -8,7 +8,6 @@ class SearchController < PublicController |
| 8 | 8 | before_filter :load_category |
| 9 | 9 | before_filter :load_search_assets |
| 10 | 10 | before_filter :load_query |
| 11 | - before_filter :load_search_engine | |
| 12 | 11 | |
| 13 | 12 | # Backwards compatibility with old URLs |
| 14 | 13 | def redirect_asset_param |
| ... | ... | @@ -58,7 +57,7 @@ class SearchController < PublicController |
| 58 | 57 | end |
| 59 | 58 | |
| 60 | 59 | def articles |
| 61 | - if @search_engine && !@empty_query | |
| 60 | + if !@empty_query | |
| 62 | 61 | full_text_search |
| 63 | 62 | else |
| 64 | 63 | @searches[@asset] = {} |
| ... | ... | @@ -71,7 +70,7 @@ class SearchController < PublicController |
| 71 | 70 | end |
| 72 | 71 | |
| 73 | 72 | def people |
| 74 | - if @search_engine && !@empty_query | |
| 73 | + if !@empty_query | |
| 75 | 74 | full_text_search |
| 76 | 75 | else |
| 77 | 76 | @searches[@asset] = {} |
| ... | ... | @@ -80,7 +79,7 @@ class SearchController < PublicController |
| 80 | 79 | end |
| 81 | 80 | |
| 82 | 81 | def products |
| 83 | - if @search_engine | |
| 82 | + if !@empty_query | |
| 84 | 83 | full_text_search |
| 85 | 84 | else |
| 86 | 85 | @searches[@asset] = {} |
| ... | ... | @@ -89,7 +88,7 @@ class SearchController < PublicController |
| 89 | 88 | end |
| 90 | 89 | |
| 91 | 90 | def enterprises |
| 92 | - if @search_engine && !@empty_query | |
| 91 | + if !@empty_query | |
| 93 | 92 | full_text_search |
| 94 | 93 | else |
| 95 | 94 | @filter_title = _('Enterprises from network') |
| ... | ... | @@ -99,7 +98,7 @@ class SearchController < PublicController |
| 99 | 98 | end |
| 100 | 99 | |
| 101 | 100 | def communities |
| 102 | - if @search_engine && !@empty_query | |
| 101 | + if !@empty_query | |
| 103 | 102 | full_text_search |
| 104 | 103 | else |
| 105 | 104 | @searches[@asset] = {} |
| ... | ... | @@ -123,7 +122,7 @@ class SearchController < PublicController |
| 123 | 122 | environment.events.by_day(@selected_day) |
| 124 | 123 | end |
| 125 | 124 | |
| 126 | - if @search_engine && !@empty_query | |
| 125 | + if !@empty_query | |
| 127 | 126 | full_text_search |
| 128 | 127 | else |
| 129 | 128 | @searches[@asset] = {} |
| ... | ... | @@ -192,10 +191,6 @@ class SearchController < PublicController |
| 192 | 191 | end |
| 193 | 192 | end |
| 194 | 193 | |
| 195 | - def load_search_engine | |
| 196 | - @search_engine = @plugins.first_plugin(:search_engine?) | |
| 197 | - end | |
| 198 | - | |
| 199 | 194 | FILTERS = %w( |
| 200 | 195 | more_recent |
| 201 | 196 | more_active |
| ... | ... | @@ -261,7 +256,7 @@ class SearchController < PublicController |
| 261 | 256 | end |
| 262 | 257 | |
| 263 | 258 | def full_text_search |
| 264 | - @searches[@asset] = @plugins.first(:find_by_contents, asset_class(@asset), @query, paginate_options(params[:page]), {:category => @category}) | |
| 259 | + @searches[@asset] = find_by_contents(asset_class(@asset), @query, paginate_options(params[:page]), {:category => @category}) | |
| 265 | 260 | end |
| 266 | 261 | |
| 267 | 262 | private | ... | ... |
app/models/region.rb
| ... | ... | @@ -4,14 +4,6 @@ class Region < Category |
| 4 | 4 | |
| 5 | 5 | require_dependency 'enterprise' # enterprises can also be validators |
| 6 | 6 | |
| 7 | - include Noosfero::Plugin::HotSpot | |
| 8 | - | |
| 9 | - # searches for organizations that could become validators for this region. | |
| 10 | - # <tt>search</tt> is passed as is to find_by_contents on Organization. | |
| 11 | - def search_possible_validators(search) | |
| 12 | - plugins.find_by_contents(Organization, search)[:results].docs.reject {|item| self.validator_ids.include?(item.id) } | |
| 13 | - end | |
| 14 | - | |
| 15 | 7 | def has_validator? |
| 16 | 8 | validators.count > 0 |
| 17 | 9 | end | ... | ... |
app/views/layouts/application-ng.rhtml
| ... | ... | @@ -69,13 +69,11 @@ |
| 69 | 69 | <% end %> |
| 70 | 70 | |
| 71 | 71 | </span> |
| 72 | - <% if @plugins.first(:search_engine?) %> | |
| 73 | - <form action="/search" class="search_form" method="get" class="clean"> | |
| 74 | - <input name="query" size="15" title="<%=_('Search...')%>" onfocus="this.form.className='focused';" onblur="this.form.className=''" /> | |
| 75 | - <div><%=_('Press <strong>Enter</strong> to send the search query.')%></div> | |
| 76 | - <%= javascript_tag 'jQuery("#user form input").hint();' %> | |
| 77 | - </form> | |
| 78 | - <% end %> | |
| 72 | + <form action="/search" class="search_form" method="get" class="clean"> | |
| 73 | + <input name="query" size="15" title="<%=_('Search...')%>" onfocus="this.form.className='focused';" onblur="this.form.className=''" /> | |
| 74 | + <div><%=_('Press <strong>Enter</strong> to send the search query.')%></div> | |
| 75 | + <%= javascript_tag 'jQuery("#user form input").hint();' %> | |
| 76 | + </form> | |
| 79 | 77 | </div><!-- end id="user" --> |
| 80 | 78 | |
| 81 | 79 | <h1 id="site-title"> | ... | ... |
app/views/search/_profile.rhtml
| 1 | 1 | <li class="search-profile-item"> |
| 2 | -<% if @empty_query || multiple_search? || !profile.enterprise? || !@search_engine %> | |
| 2 | +<% if @empty_query || multiple_search? || !profile.enterprise? %> | |
| 3 | 3 | <%= profile_image_link profile, :portrait, 'div', |
| 4 | 4 | @filter == 'more_recent' ? profile.send(@filter + '_label') + show_date(profile.created_at) : profile.send(@filter + '_label') %> |
| 5 | 5 | <% else %> | ... | ... |
app/views/search/category_index.rhtml
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | <% end %> |
| 6 | 6 | |
| 7 | 7 | <%= search_page_title(_('Search Results'), @category) %> |
| 8 | - <%= render :partial => 'search_form', :locals => { :hint => '' } if @search_engine %> | |
| 8 | + <%= render :partial => 'search_form', :locals => { :hint => '' } %> | |
| 9 | 9 | <%= category_context(@category, params) %> |
| 10 | 10 | <%= display_results %> |
| 11 | 11 | ... | ... |
app/views/search/index.rhtml
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | <% end %> |
| 6 | 6 | |
| 7 | 7 | <%= search_page_title(_('Search Results'), @category) %> |
| 8 | - <%= render :partial => 'search_form', :locals => { :hint => '' } if @search_engine %> | |
| 8 | + <%= render :partial => 'search_form', :locals => { :hint => '' } %> | |
| 9 | 9 | <%= category_context(@category, params) %> |
| 10 | 10 | <%= display_results(@asset) %> |
| 11 | 11 | ... | ... |
lib/noosfero/plugin.rb
| ... | ... | @@ -351,18 +351,11 @@ class Noosfero::Plugin |
| 351 | 351 | nil |
| 352 | 352 | end |
| 353 | 353 | |
| 354 | - # -> Specifies plugin that works as a search engine | |
| 355 | - # returns = true/false | |
| 356 | - def search_engine? | |
| 357 | - false | |
| 358 | - end | |
| 359 | - | |
| 360 | 354 | # -> Finds objects by their contents |
| 361 | 355 | # returns = {:results => [a, b, c, ...], ...} |
| 362 | 356 | # P.S.: The plugin might add other informations on the return hash for its |
| 363 | 357 | # own use in specific views |
| 364 | 358 | def find_by_contents(klass, query, paginate_options={}, options={}) |
| 365 | - {:results => []} | |
| 366 | 359 | end |
| 367 | 360 | |
| 368 | 361 | def method_missing(method, *args, &block) | ... | ... |
lib/noosfero/plugin/manager.rb
plugins/solr/lib/solr_plugin.rb
| ... | ... | @@ -12,10 +12,6 @@ class SolrPlugin < Noosfero::Plugin |
| 12 | 12 | _("Uses Solr as search engine.") |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | - def search_engine? | |
| 16 | - true | |
| 17 | - end | |
| 18 | - | |
| 19 | 15 | def find_by_contents(klass, query, paginate_options={}, options={}) |
| 20 | 16 | category = options.delete(:category) |
| 21 | 17 | solr_options = solr_options(class_asset(klass), category) | ... | ... |
test/unit/plugin_manager_test.rb
| ... | ... | @@ -140,15 +140,5 @@ class PluginManagerTest < ActiveSupport::TestCase |
| 140 | 140 | assert_equal Plugin2, manager.first_plugin(:random_event) |
| 141 | 141 | end |
| 142 | 142 | |
| 143 | - should 'use default value defined on the base plugin class when no plugin enabled for the first method' do | |
| 144 | - class Noosfero::Plugin | |
| 145 | - def random_event | |
| 146 | - 1 | |
| 147 | - end | |
| 148 | - end | |
| 149 | - | |
| 150 | - assert_equal 1, manager.first(:random_event) | |
| 151 | - end | |
| 152 | - | |
| 153 | 143 | end |
| 154 | 144 | ... | ... |