Commit 2f6c86d99fbc7593729027f4f1ceb8fdc6b07013
1 parent
7eb7d4bf
Exists in
master
and in
29 other branches
find_by_contents: pass the responsability of filter to the engines
Since there are plugins that need to receive the scope clean (that is without filters applied to it) and since the plugin has the power to not apply the filter when conveys it (also rewriting the interface to keep its consistency), I decided to pass the reposability of applying any filter provided by the core to the engines. Nevertheless, if the plugin returns nil (that's the same that it would return if it was disabled) the core will deal with the filters through the default way (that is without any engine).
Showing
4 changed files
with
9 additions
and
12 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -181,8 +181,9 @@ class ApplicationController < ActionController::Base |
181 | 181 | private |
182 | 182 | |
183 | 183 | def fallback_find_by_contents(asset, scope, query, paginate_options, options) |
184 | - return {:results => scope.paginate(paginate_options)} if query.blank? | |
185 | - {:results => scope.like_search(query).paginate(paginate_options)} | |
184 | + scope = scope.like_search(query) unless query.blank? | |
185 | + scope = scope.send(options[:filter]) unless options[:filter].blank? | |
186 | + {:results => scope.paginate(paginate_options)} | |
186 | 187 | end |
187 | 188 | |
188 | 189 | end | ... | ... |
app/controllers/public/search_controller.rb
... | ... | @@ -214,13 +214,6 @@ class SearchController < PublicController |
214 | 214 | @searches[@asset] = find_by_contents(@asset, @scope, @query, paginate_options, {:category => @category, :filter => @filter}) |
215 | 215 | end |
216 | 216 | |
217 | - def find_by_contents asset, scope, query, paginate_options={:page => 1}, options={} | |
218 | - # only apply fitlers to empty query, sorting is engine specific | |
219 | - scope = scope.send(options[:filter]) if options[:filter] and @empty_query | |
220 | - | |
221 | - super asset, scope, query, paginate_options, options | |
222 | - end | |
223 | - | |
224 | 217 | private |
225 | 218 | |
226 | 219 | def visible_profiles(klass, *extra_relations) | ... | ... |
plugins/pg_search/lib/pg_search_plugin.rb
... | ... | @@ -9,8 +9,9 @@ class PgSearchPlugin < Noosfero::Plugin |
9 | 9 | end |
10 | 10 | |
11 | 11 | def find_by_contents(asset, scope, query, paginate_options={}, options={}) |
12 | - return if query.blank? | |
13 | - {:results => scope.pg_search_plugin_search(query).paginate(paginate_options)} | |
12 | + scope = scope.pg_search_plugin_search(query) unless query.blank? | |
13 | + scope = scope.send(options[:filter]) unless options[:filter] | |
14 | + {:results => scope.paginate(paginate_options)} | |
14 | 15 | end |
15 | 16 | |
16 | 17 | end | ... | ... |
plugins/solr/lib/solr_plugin.rb
... | ... | @@ -27,7 +27,9 @@ class SolrPlugin < Noosfero::Plugin |
27 | 27 | category = options[:category] |
28 | 28 | empty_query = empty_query? query, category |
29 | 29 | |
30 | - return unless solr_search? empty_query, klass | |
30 | + unless solr_search? empty_query, klass | |
31 | + return options[:filter] ? {:results => scope.send(options[:filter]).paginate(paginate_options)} : nil | |
32 | + end | |
31 | 33 | |
32 | 34 | solr_options = solr_options(class_asset(klass), category) |
33 | 35 | solr_options[:filter_queries] ||= [] | ... | ... |