diff --git a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb index 77e4307..db11963 100644 --- a/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb +++ b/plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb @@ -1,7 +1,12 @@ class ElasticsearchPluginController < ApplicationController no_design_blocks - SEARCHABLE_MODELS = {communities: true, articles: true, people: true} + SEARCHABLE_TYPES = { :all => { label: "All Results" }, + :community => { label: "Communities"}, + :article => { label: "Articles"}, + :event => { label: "Events"}, + :person => { label: "People"} + } def index search() @@ -9,23 +14,20 @@ class ElasticsearchPluginController < ApplicationController end def search - @results = [] + @searchable_types = SEARCHABLE_TYPES + @selected_type = selected_type params + @query = params[:q] - @checkbox = {} + @results = [] - if params[:model].present? - params[:model].keys.each do |model| - @checkbox[model.to_sym] = true - results model - end - else - unless params[:q].blank? - SEARCHABLE_MODELS.keys.each do |model| - results model - end - end - end +# results 'article' +# results 'people' + results "community" + end + def selected_type params + return :all if params[:selected_type].nil? + params[:selected_type] end private @@ -68,22 +70,10 @@ class ElasticsearchPluginController < ApplicationController query end - def get_terms params - terms = {} - return terms unless params[:filter].present? - params[:filter].keys.each do |model| - terms[model] = {} - params[:filter][model].keys.each do |filter| - @checkbox[filter.to_sym] = true - terms[model][params[:filter][model.to_sym][filter]] = filter - end - end - terms - end - def results model klass = model.to_s.classify.constantize query = get_query params[:q], klass + query = {} @results |= klass.__elasticsearch__.search(query).records.to_a end diff --git a/plugins/elasticsearch/lib/elasticsearch_plugin.rb b/plugins/elasticsearch/lib/elasticsearch_plugin.rb index f2485db..4c17a9e 100644 --- a/plugins/elasticsearch/lib/elasticsearch_plugin.rb +++ b/plugins/elasticsearch/lib/elasticsearch_plugin.rb @@ -8,4 +8,7 @@ class ElasticsearchPlugin < Noosfero::Plugin _("This plugin is used to communicate a elasticsearch to privide a search.") end + def stylesheet? + true + end end diff --git a/plugins/elasticsearch/public/style.css b/plugins/elasticsearch/public/style.css new file mode 100644 index 0000000..7d0f365 --- /dev/null +++ b/plugins/elasticsearch/public/style.css @@ -0,0 +1,12 @@ +.wrapper { + display: flex; +} +.sidebar { + width: 150px; +} + +.search_form { + flex: 1; +} + + diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb index fec9b85..68c2331 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb @@ -1,2 +1,10 @@ +
+

<%= article.name %>

+
+ <%= article.created_at %> <%= article.class %> +
-Article: <%= article.id %><%= article.name %> +
+ MY BODY CONTENT +
+
diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb index f35c383..82a4541 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb @@ -1 +1,6 @@ -Community: <%= community.name %> +
+

<%= community.name %>

+
+ SAMPLE DESCRIPTION +
+
diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb index cfa742d..2d46c66 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb @@ -1,2 +1,11 @@ +
+

PERSON

+

+ <%= person.created_at %> <%= person.class %> +

+ + Name: <%= person.name %> + + +
-Person: <%= person.name %> diff --git a/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb b/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb index 61317c0..d3791a3 100644 --- a/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb +++ b/plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb @@ -1,34 +1,37 @@ -

Search

- -<%= form_tag controller: "elasticsearch_plugin", action: "search" do %> - <%= label_tag(:q, _("Search")) %> - <%= text_field_tag(:q, @query) %> - - <%= submit_tag _("Send") %> - - <%= check_box_tag 'model[communities]', 1, @checkbox[:communities] %> - <%= label_tag('communities', _("communities")) %> - - <%= check_box_tag 'model[people]', 1, @checkbox[:people] %> - <%= label_tag('people', _("people")) %> - - <%= check_box_tag 'model[articles]', 1, @checkbox[:articles] %> - <%= label_tag('articles', _("articles")) %> - -<% end %> - -<% for result in @results %> - <% if result.is_a? Article %> - <%= render partial: "article_display", :locals => {:article => result} %> -
- <% end %> - - <% if result.is_a? Person %> - <%= render partial: "person_display", :locals => {:person => result} %> -
- <% end %> - <% if result.is_a? Community %> - <%= render partial: "community_display", :locals => {:community => result} %> -
- <% end %> -<% end %> +
+ + + +
+
+ <%= form_tag controller: "elasticsearch_plugin", action: "search" do %> + <%= label_tag(:q, _("Search")) %> + <%= text_field_tag(:q, @query) %> + + <%= submit_tag _("Send") %> + <% end %> +
+ +
+ <% for result in @results %> + <% for klass in @searchable_types.keys %> + <% next if klass.to_s.include? "all" %> + + <% if result.is_a? klass.to_s.classify.constantize %> + <%= render partial: "#{klass}_display", :locals => { klass => result} %> + <% break %> + <% end %> + + <% end %> + <% end %> +
+
+ +
-- libgit2 0.21.2