Commit 6e4878bba88d259bf5b93a6e057542fb245121c6
1 parent
efd3d7b9
Exists in
elasticsearch_view
Adding category search filter to elasticsearch
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Macartur Sousa <macartur.sc@gmail.com> Signed-off-by: Daniel Henrique <danielhmarinho@gmail.com>
Showing
7 changed files
with
56 additions
and
10 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
| 1 | 1 | class ElasticsearchPluginController < ApplicationController |
| 2 | 2 | |
| 3 | - def communities | |
| 4 | - @communities = environment.communities | |
| 3 | + no_design_blocks | |
| 4 | + | |
| 5 | + def search | |
| 6 | + @results = [] | |
| 7 | + | |
| 8 | + @checkbox = {:articles => params[:articles].present?, | |
| 9 | + :communities => params[:communities].present?, | |
| 10 | + :people => params[:people].present? | |
| 11 | + } | |
| 12 | + | |
| 13 | + @results += Article.__elasticsearch__.search('{}').records.to_a if params[:articles] | |
| 14 | + @results += Community.__elasticsearch__.search('{}').records.to_a if params[:communities] | |
| 15 | + @results += Person.__elasticsearch__.search('{}').records.to_a if params[:people] | |
| 5 | 16 | end |
| 17 | + | |
| 6 | 18 | end | ... | ... |
plugins/elasticsearch/lib/elasticsearch_plugin.rb
| ... | ... | @@ -12,6 +12,9 @@ class ElasticsearchPlugin < Noosfero::Plugin |
| 12 | 12 | |
| 13 | 13 | Noosfero::Application.class_eval do |
| 14 | 14 | config.after_initialize do |
| 15 | + | |
| 16 | + Rails.application.eager_load! #TODO: REMOVE THIS LINE | |
| 17 | + | |
| 15 | 18 | models = ActiveRecord::Base.descendants.select do |model| |
| 16 | 19 | model.const_defined?("SEARCHABLE_FIELDS") |
| 17 | 20 | end | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb
0 → 100644
plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1 @@ |
| 1 | +Community: <%= community.name %> | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb
0 → 100644
plugins/elasticsearch/views/elasticsearch_plugin/communities.html.erb
plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1,34 @@ |
| 1 | +<h1> Search </h1> | |
| 2 | + | |
| 3 | +<%= form_tag controller: "elasticsearch_plugin", action: "search" do %> | |
| 4 | + <%= label_tag(:q, _("Search")) %> | |
| 5 | + <%= text_field_tag(:q) %> | |
| 6 | + | |
| 7 | + <%= submit_tag _("Send") %> | |
| 8 | + | |
| 9 | + <%= check_box_tag 'communities', 1, @checkbox[:communities] %> | |
| 10 | + <%= label_tag('communities', _("communities")) %> | |
| 11 | + | |
| 12 | + <%= check_box_tag 'people', 1, @checkbox[:people] %> | |
| 13 | + <%= label_tag('people', _("people")) %> | |
| 14 | + | |
| 15 | + <%= check_box_tag 'articles', 1, @checkbox[:articles] %> | |
| 16 | + <%= label_tag('articles', _("articles")) %> | |
| 17 | + | |
| 18 | +<% end %> | |
| 19 | + | |
| 20 | +<% for result in @results %> | |
| 21 | + <% if result.is_a? Article %> | |
| 22 | + <%= render partial: "article_display", :locals => {:article => result} %> | |
| 23 | + <br> | |
| 24 | + <% end %> | |
| 25 | + | |
| 26 | + <% if result.is_a? Person %> | |
| 27 | + <%= render partial: "person_display", :locals => {:person => result} %> | |
| 28 | + <br> | |
| 29 | + <% end %> | |
| 30 | + <% if result.is_a? Community %> | |
| 31 | + <%= render partial: "community_display", :locals => {:community => result} %> | |
| 32 | + <br> | |
| 33 | + <% end %> | |
| 34 | +<% end %> | ... | ... |