Commit bbc2079adfb64a298eaf8328d8a4fd9504edcf81

Authored by David Silva
1 parent 7008ae67
Exists in elasticsearch_api

Redirect search query to elasticsearch plugin.

  - Related with #322
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
@@ -18,6 +18,8 @@ class ElasticsearchPluginController < ApplicationController @@ -18,6 +18,8 @@ class ElasticsearchPluginController < ApplicationController
18 end 18 end
19 19
20 def search 20 def search
  21 + puts "="*80
  22 + puts params.inspect
21 define_searchable_types 23 define_searchable_types
22 define_search_fields_types 24 define_search_fields_types
23 25
@@ -25,7 +27,7 @@ class ElasticsearchPluginController < ApplicationController @@ -25,7 +27,7 @@ class ElasticsearchPluginController < ApplicationController
25 end 27 end
26 28
27 def process_results 29 def process_results
28 - @query = params[:q] 30 + @query = params[:query]
29 31
30 if @selected_type == :all 32 if @selected_type == :all
31 @results = search_from_all_models 33 @results = search_from_all_models
@@ -79,7 +81,7 @@ class ElasticsearchPluginController < ApplicationController @@ -79,7 +81,7 @@ class ElasticsearchPluginController < ApplicationController
79 81
80 def search_from_all_models 82 def search_from_all_models
81 models = [] 83 models = []
82 - query = get_query params[:q] 84 + query = get_query params[:query]
83 85
84 SEARCHABLE_TYPES.keys.each {| model | models.append( model.to_s.classify.constantize) if model != :all } 86 SEARCHABLE_TYPES.keys.each {| model | models.append( model.to_s.classify.constantize) if model != :all }
85 Elasticsearch::Model.search(query, models, size: default_per_page).page(params[:page]).records 87 Elasticsearch::Model.search(query, models, size: default_per_page).page(params[:page]).records
@@ -88,7 +90,7 @@ class ElasticsearchPluginController < ApplicationController @@ -88,7 +90,7 @@ class ElasticsearchPluginController < ApplicationController
88 def search_from_model model 90 def search_from_model model
89 begin 91 begin
90 klass = model.to_s.classify.constantize 92 klass = model.to_s.classify.constantize
91 - query = get_query params[:q], klass 93 + query = get_query params[:query], klass
92 klass.search(query, size: default_per_page).page(params[:page]).records 94 klass.search(query, size: default_per_page).page(params[:page]).records
93 rescue 95 rescue
94 [] 96 []
plugins/elasticsearch/lib/elasticsearch_plugin.rb
1 class ElasticsearchPlugin < Noosfero::Plugin 1 class ElasticsearchPlugin < Noosfero::Plugin
2 2
  3 + # append_view_path File.join(File.dirname(__FILE__) + '/../views/elasticsearch_plugin')
  4 +
  5 +
3 def self.plugin_name 6 def self.plugin_name
4 "ElasticsearchPlugin" 7 "ElasticsearchPlugin"
5 end 8 end
@@ -11,4 +14,14 @@ class ElasticsearchPlugin &lt; Noosfero::Plugin @@ -11,4 +14,14 @@ class ElasticsearchPlugin &lt; Noosfero::Plugin
11 def stylesheet? 14 def stylesheet?
12 true 15 true
13 end 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 end 27 end