cirandas.net

ref: master

plugins/elasticsearch/lib/elasticsearch_plugin.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class ElasticsearchPlugin < Noosfero::Plugin

  def self.plugin_name
    "ElasticsearchPlugin"
  end

  def self.api_mount_points
    [ElasticsearchPlugin::API]
  end

  def self.plugin_description
    _("This plugin is used to communicate with elasticsearch engine.")
  end

  def stylesheet?
    true
  end

  def js_files
    ['categories', 'jstree.min'].map{ |file_name| "javascripts/#{file_name}" }
  end

  def search_controller_filters
    block = proc do

      case action_name
        when 'contents'
          params[:selected_type] = :text_article
        when 'index'
        when 'articles'
          params[:selected_type] = :text_article
        else
          params[:selected_type] = action_name.singularize.to_sym
      end

      redirect_to controller: 'elasticsearch_plugin', action: 'search', params: params
    end

    [{ :type => 'before_filter',
      :method_name => 'redirect_search_to_elastic',
      :block => block }]
  end

end