From bbc2079adfb64a298eaf8328d8a4fd9504edcf81 Mon Sep 17 00:00:00 2001 From: David Carlos Date: Thu, 9 Jun 2016 16:49:10 -0300 Subject: [PATCH] Redirect search query to elasticsearch plugin. --- plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb | 8 +++++--- plugins/elasticsearch/lib/elasticsearch_plugin.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb index 3bb6fb0..853eff0 100644 --- a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb +++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb @@ -18,6 +18,8 @@ class ElasticsearchPluginController < ApplicationController end def search + puts "="*80 + puts params.inspect define_searchable_types define_search_fields_types @@ -25,7 +27,7 @@ class ElasticsearchPluginController < ApplicationController end def process_results - @query = params[:q] + @query = params[:query] if @selected_type == :all @results = search_from_all_models @@ -79,7 +81,7 @@ class ElasticsearchPluginController < ApplicationController def search_from_all_models models = [] - query = get_query params[:q] + query = get_query params[:query] SEARCHABLE_TYPES.keys.each {| model | models.append( model.to_s.classify.constantize) if model != :all } Elasticsearch::Model.search(query, models, size: default_per_page).page(params[:page]).records @@ -88,7 +90,7 @@ class ElasticsearchPluginController < ApplicationController def search_from_model model begin klass = model.to_s.classify.constantize - query = get_query params[:q], klass + query = get_query params[:query], klass klass.search(query, size: default_per_page).page(params[:page]).records rescue [] diff --git a/plugins/elasticsearch/lib/elasticsearch_plugin.rb b/plugins/elasticsearch/lib/elasticsearch_plugin.rb index 4c17a9e..f170f7c 100644 --- a/plugins/elasticsearch/lib/elasticsearch_plugin.rb +++ b/plugins/elasticsearch/lib/elasticsearch_plugin.rb @@ -1,5 +1,8 @@ class ElasticsearchPlugin < Noosfero::Plugin + # append_view_path File.join(File.dirname(__FILE__) + '/../views/elasticsearch_plugin') + + def self.plugin_name "ElasticsearchPlugin" end @@ -11,4 +14,14 @@ class ElasticsearchPlugin < Noosfero::Plugin def stylesheet? true end + + def search_controller_filters + block = proc do + redirect_to controller: 'elasticsearch_plugin', action: 'search', params: params + end + + [{ :type => 'before_filter', + :method_name => 'redirect_search_to_elastic', + :block => block }] + end end -- libgit2 0.21.2