Commit e578728c988a6f92c0bf09f21292e3ecde13762e
1 parent
a3368a23
Exists in
elasticsearch_sort
Create initial style of elasticsearch, and refectored html
Signed-off-by: DylanGuedes <djmgguedes@gmail.com> Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
7 changed files
with
95 additions
and
65 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
| 1 | 1 | class ElasticsearchPluginController < ApplicationController |
| 2 | 2 | no_design_blocks |
| 3 | 3 | |
| 4 | - SEARCHABLE_MODELS = {communities: true, articles: true, people: true} | |
| 4 | + SEARCHABLE_TYPES = { :all => { label: "All Results" }, | |
| 5 | + :community => { label: "Communities"}, | |
| 6 | + :article => { label: "Articles"}, | |
| 7 | + :event => { label: "Events"}, | |
| 8 | + :person => { label: "People"} | |
| 9 | + } | |
| 5 | 10 | |
| 6 | 11 | def index |
| 7 | 12 | search() |
| ... | ... | @@ -9,23 +14,20 @@ class ElasticsearchPluginController < ApplicationController |
| 9 | 14 | end |
| 10 | 15 | |
| 11 | 16 | def search |
| 12 | - @results = [] | |
| 17 | + @searchable_types = SEARCHABLE_TYPES | |
| 18 | + @selected_type = selected_type params | |
| 19 | + | |
| 13 | 20 | @query = params[:q] |
| 14 | - @checkbox = {} | |
| 21 | + @results = [] | |
| 15 | 22 | |
| 16 | - if params[:model].present? | |
| 17 | - params[:model].keys.each do |model| | |
| 18 | - @checkbox[model.to_sym] = true | |
| 19 | - results model | |
| 20 | - end | |
| 21 | - else | |
| 22 | - unless params[:q].blank? | |
| 23 | - SEARCHABLE_MODELS.keys.each do |model| | |
| 24 | - results model | |
| 25 | - end | |
| 26 | - end | |
| 27 | - end | |
| 23 | +# results 'article' | |
| 24 | +# results 'people' | |
| 25 | + results "community" | |
| 26 | + end | |
| 28 | 27 | |
| 28 | + def selected_type params | |
| 29 | + return :all if params[:selected_type].nil? | |
| 30 | + params[:selected_type] | |
| 29 | 31 | end |
| 30 | 32 | |
| 31 | 33 | private |
| ... | ... | @@ -68,22 +70,10 @@ class ElasticsearchPluginController < ApplicationController |
| 68 | 70 | query |
| 69 | 71 | end |
| 70 | 72 | |
| 71 | - def get_terms params | |
| 72 | - terms = {} | |
| 73 | - return terms unless params[:filter].present? | |
| 74 | - params[:filter].keys.each do |model| | |
| 75 | - terms[model] = {} | |
| 76 | - params[:filter][model].keys.each do |filter| | |
| 77 | - @checkbox[filter.to_sym] = true | |
| 78 | - terms[model][params[:filter][model.to_sym][filter]] = filter | |
| 79 | - end | |
| 80 | - end | |
| 81 | - terms | |
| 82 | - end | |
| 83 | - | |
| 84 | 73 | def results model |
| 85 | 74 | klass = model.to_s.classify.constantize |
| 86 | 75 | query = get_query params[:q], klass |
| 76 | + query = {} | |
| 87 | 77 | @results |= klass.__elasticsearch__.search(query).records.to_a |
| 88 | 78 | end |
| 89 | 79 | ... | ... |
plugins/elasticsearch/lib/elasticsearch_plugin.rb
plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb
| 1 | +<div class="article-model"> | |
| 2 | + <h3> <%= article.name %> </h3> | |
| 3 | + <div class="article-info"> | |
| 4 | + <%= article.created_at %> <strong><%= article.class %></strong> | |
| 5 | + </div> | |
| 1 | 6 | |
| 2 | -Article: <%= article.id %><%= article.name %> | |
| 7 | + <div class="article-content"> | |
| 8 | + MY BODY CONTENT | |
| 9 | + </div> | |
| 10 | +</div> | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_community_display.html.erb
plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb
plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
| 1 | -<h1> Search </h1> | |
| 2 | - | |
| 3 | -<%= form_tag controller: "elasticsearch_plugin", action: "search" do %> | |
| 4 | - <%= label_tag(:q, _("Search")) %> | |
| 5 | - <%= text_field_tag(:q, @query) %> | |
| 6 | - | |
| 7 | - <%= submit_tag _("Send") %> | |
| 8 | - | |
| 9 | - <%= check_box_tag 'model[communities]', 1, @checkbox[:communities] %> | |
| 10 | - <%= label_tag('communities', _("communities")) %> | |
| 11 | - | |
| 12 | - <%= check_box_tag 'model[people]', 1, @checkbox[:people] %> | |
| 13 | - <%= label_tag('people', _("people")) %> | |
| 14 | - | |
| 15 | - <%= check_box_tag 'model[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 %> | |
| 1 | +<div class="wrapper"> | |
| 2 | + | |
| 3 | + <div class="sidebar"> | |
| 4 | + <%= @results.count %> | |
| 5 | + <ul> | |
| 6 | + <% for type in @searchable_types.values %> | |
| 7 | + <li><a class=""> <%= type[:label] %></a></li> | |
| 8 | + <% end %> | |
| 9 | + </ul> | |
| 10 | + </div> | |
| 11 | + | |
| 12 | + <div class="search_form"> | |
| 13 | + <div class="search_field"> | |
| 14 | + <%= form_tag controller: "elasticsearch_plugin", action: "search" do %> | |
| 15 | + <%= label_tag(:q, _("Search")) %> | |
| 16 | + <%= text_field_tag(:q, @query) %> | |
| 17 | + | |
| 18 | + <%= submit_tag _("Send") %> | |
| 19 | + <% end %> | |
| 20 | + </div> | |
| 21 | + | |
| 22 | + <div class="results"> | |
| 23 | + <% for result in @results %> | |
| 24 | + <% for klass in @searchable_types.keys %> | |
| 25 | + <% next if klass.to_s.include? "all" %> | |
| 26 | + | |
| 27 | + <% if result.is_a? klass.to_s.classify.constantize %> | |
| 28 | + <%= render partial: "#{klass}_display", :locals => { klass => result} %> | |
| 29 | + <% break %> | |
| 30 | + <% end %> | |
| 31 | + | |
| 32 | + <% end %> | |
| 33 | + <% end %> | |
| 34 | + </div> | |
| 35 | + </div> | |
| 36 | + | |
| 37 | +</div> | ... | ... |