Commit 03d1f25eb9b5ac7f4688d40764cb07ddcbe0b30f
Committed by
Macartur Sousa
1 parent
94975e43
Exists in
elasticsearch_filter
and in
1 other branch
Elasticsearch: Redirect search query
Showing
2 changed files
with
18 additions
and
3 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
... | ... | @@ -18,6 +18,8 @@ class ElasticsearchPluginController < ApplicationController |
18 | 18 | end |
19 | 19 | |
20 | 20 | def search |
21 | + puts "="*80 | |
22 | + puts params.inspect | |
21 | 23 | define_searchable_types |
22 | 24 | define_search_fields_types |
23 | 25 | |
... | ... | @@ -25,7 +27,7 @@ class ElasticsearchPluginController < ApplicationController |
25 | 27 | end |
26 | 28 | |
27 | 29 | def process_results |
28 | - @query = params[:q] | |
30 | + @query = params[:query] | |
29 | 31 | |
30 | 32 | if @selected_type == :all |
31 | 33 | @results = search_from_all_models |
... | ... | @@ -79,7 +81,7 @@ class ElasticsearchPluginController < ApplicationController |
79 | 81 | |
80 | 82 | def search_from_all_models |
81 | 83 | models = [] |
82 | - query = get_query params[:q] | |
84 | + query = get_query params[:query] | |
83 | 85 | |
84 | 86 | SEARCHABLE_TYPES.keys.each {| model | models.append( model.to_s.classify.constantize) if model != :all } |
85 | 87 | Elasticsearch::Model.search(query, models, size: default_per_page).page(params[:page]).records |
... | ... | @@ -88,7 +90,7 @@ class ElasticsearchPluginController < ApplicationController |
88 | 90 | def search_from_model model |
89 | 91 | begin |
90 | 92 | klass = model.to_s.classify.constantize |
91 | - query = get_query params[:q], klass | |
93 | + query = get_query params[:query], klass | |
92 | 94 | klass.search(query, size: default_per_page).page(params[:page]).records |
93 | 95 | rescue |
94 | 96 | [] | ... | ... |
plugins/elasticsearch/lib/elasticsearch_plugin.rb
1 | 1 | class ElasticsearchPlugin < Noosfero::Plugin |
2 | 2 | |
3 | + # append_view_path File.join(File.dirname(__FILE__) + '/../views/elasticsearch_plugin') | |
4 | + | |
5 | + | |
3 | 6 | def self.plugin_name |
4 | 7 | "ElasticsearchPlugin" |
5 | 8 | end |
... | ... | @@ -11,4 +14,14 @@ class ElasticsearchPlugin < Noosfero::Plugin |
11 | 14 | def stylesheet? |
12 | 15 | true |
13 | 16 | end |
17 | + | |
18 | + def search_controller_filters | |
19 | + block = proc do | |
20 | + redirect_to controller: 'elasticsearch_plugin', action: 'search', params: params | |
21 | + end | |
22 | + | |
23 | + [{ :type => 'before_filter', | |
24 | + :method_name => 'redirect_search_to_elastic', | |
25 | + :block => block }] | |
26 | + end | |
14 | 27 | end | ... | ... |