Commit dd29b57505329a55bfdfbc2b9429ff6421a5afa5
1 parent
05a2153a
Exists in
elasticsearch_sort
Adding event to models and adding styles
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com>
Showing
6 changed files
with
78 additions
and
50 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
| ... | ... | @@ -3,14 +3,14 @@ class ElasticsearchPluginController < ApplicationController |
| 3 | 3 | |
| 4 | 4 | SEARCHABLE_TYPES = { :all => { label: _("All Results")}, |
| 5 | 5 | :community => { label: _("Communities")}, |
| 6 | - :article => { label: _("Articles")}, | |
| 7 | 6 | :event => { label: _("Events")}, |
| 8 | 7 | :person => { label: _("People")} |
| 9 | - } | |
| 10 | - SEARCH_FILTERS = { :lexical => { label: _("Alphabetical Order")}, | |
| 11 | - :recent => { label: _("More Recent Order")}, | |
| 12 | - :access => { label: _("More accessed")} | |
| 13 | - } | |
| 8 | + } | |
| 9 | + | |
| 10 | + SEARCH_FILTERS = { :lexical => { label: _("Alphabetical Order")}, | |
| 11 | + :recent => { label: _("More Recent Order")}, | |
| 12 | + :access => { label: _("More accessed")} | |
| 13 | + } | |
| 14 | 14 | |
| 15 | 15 | def index |
| 16 | 16 | search() |
| ... | ... | @@ -18,22 +18,21 @@ class ElasticsearchPluginController < ApplicationController |
| 18 | 18 | end |
| 19 | 19 | |
| 20 | 20 | def search |
| 21 | - @searchable_types = SEARCHABLE_TYPES | |
| 22 | - @selected_type = selected_type params | |
| 23 | - @search_filter_types = SEARCH_FILTERS | |
| 21 | + define_searchable_types | |
| 22 | + define_search_fields_types | |
| 24 | 23 | |
| 25 | 24 | @query = params[:q] |
| 26 | 25 | @results = [] |
| 27 | 26 | |
| 28 | -# results 'article' | |
| 29 | - results 'people' | |
| 30 | - # results "community" | |
| 27 | + if @selected_type == :all | |
| 28 | + SEARCHABLE_TYPES.keys.each do |type| | |
| 29 | + results type.to_s | |
| 30 | + end | |
| 31 | + else | |
| 32 | + results @selected_type | |
| 33 | + end | |
| 31 | 34 | end |
| 32 | 35 | |
| 33 | - def selected_type params | |
| 34 | - return :all if params[:selected_type].nil? | |
| 35 | - params[:selected_type] | |
| 36 | - end | |
| 37 | 36 | |
| 38 | 37 | private |
| 39 | 38 | |
| ... | ... | @@ -76,10 +75,23 @@ class ElasticsearchPluginController < ApplicationController |
| 76 | 75 | end |
| 77 | 76 | |
| 78 | 77 | def results model |
| 79 | - klass = model.to_s.classify.constantize | |
| 78 | + begin | |
| 79 | + klass = model.to_s.classify.constantize | |
| 80 | + rescue | |
| 81 | + return | |
| 82 | + end | |
| 80 | 83 | query = get_query params[:q], klass |
| 81 | - query = {} | |
| 82 | 84 | @results |= klass.__elasticsearch__.search(query).records.to_a |
| 83 | 85 | end |
| 84 | 86 | |
| 87 | + def define_searchable_types | |
| 88 | + @searchable_types = SEARCHABLE_TYPES | |
| 89 | + @selected_type = params[:selected_type].nil? ? :all : params[:selected_type].to_sym | |
| 90 | + end | |
| 91 | + | |
| 92 | + def define_search_fields_types | |
| 93 | + @search_filter_types = SEARCH_FILTERS | |
| 94 | + @selected_filter_field = params[:selected_filter_field].nil? ? SEARCH_FILTERS.keys.first : params[:selected_filter_field].to_sym | |
| 95 | + end | |
| 96 | + | |
| 85 | 97 | end | ... | ... |
plugins/elasticsearch/public/style.css
| 1 | -.wrapper { | |
| 1 | +.controller-elasticsearch_plugin .wrapper { | |
| 2 | 2 | display: flex; |
| 3 | 3 | } |
| 4 | -.sidebar { | |
| 4 | + | |
| 5 | +.controller-elasticsearch_plugin .sidebar { | |
| 5 | 6 | width: 150px; |
| 6 | 7 | } |
| 7 | 8 | |
| 8 | -.search_form { | |
| 9 | +.controller-elasticsearch_plugin .search_form { | |
| 9 | 10 | flex: 1; |
| 10 | 11 | } |
| 11 | 12 | |
| 13 | +.controller-elasticsearch_plugin .search_form .search_field { | |
| 14 | + margin-top: 5px; | |
| 15 | +} | |
| 16 | +.controller-elasticsearch_plugin .search_form .search_field #q { | |
| 17 | + width: 500px; | |
| 18 | +} | |
| 19 | + | |
| 20 | +.controller-elasticsearch_plugin .results-count { | |
| 21 | + margin-top: 7px; | |
| 22 | + margin-right: 15px; | |
| 23 | + text-align: right; | |
| 24 | +} | |
| 25 | + | |
| 12 | 26 | .controller-elasticsearch_plugin ul { |
| 13 | 27 | list-style: none; |
| 14 | 28 | list-style-position: inside; |
| ... | ... | @@ -38,8 +52,7 @@ |
| 38 | 52 | color: black; |
| 39 | 53 | } |
| 40 | 54 | |
| 41 | -.controller-elasticsearch_plugin .search-item .right-side .model-label, | |
| 42 | -.controller-elasticsearch_plugin .community-header .model-label { | |
| 55 | +.controller-elasticsearch_plugin .search-item .model-label { | |
| 43 | 56 | background: #ddd; |
| 44 | 57 | color: black; |
| 45 | 58 | font-weight: 900; |
| ... | ... | @@ -49,6 +62,9 @@ |
| 49 | 62 | .controller-elasticsearch_plugin .search-item { |
| 50 | 63 | margin-bottom: 25px; |
| 51 | 64 | margin-top: 25px; |
| 65 | +} | |
| 66 | + | |
| 67 | +.controller-elasticsearch_plugin .search-item .person-item { | |
| 52 | 68 | display: flex; |
| 53 | 69 | } |
| 54 | 70 | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/_article_display.html.erb
plugins/elasticsearch/views/elasticsearch_plugin/_event_display.html.erb
0 → 100644
plugins/elasticsearch/views/elasticsearch_plugin/_person_display.html.erb
| 1 | -<div class="left-side"> | |
| 2 | - <%= profile_image person %> | |
| 3 | -</div> | |
| 4 | -<div class="right-side"> | |
| 5 | - <%= person.created_at.strftime("%d %B %Y at %H:%M") %> - <%= person.name %> <span class="model-label"><%= _("PERSON") %></span> | |
| 6 | - <div class="body"> | |
| 7 | - <h2><%= person.name %></h2> | |
| 8 | - <p><%= person.description %></p> | |
| 1 | +<div class="person-item"> | |
| 2 | + <div class="left-side"> | |
| 3 | + <%= profile_image person %> | |
| 4 | + </div> | |
| 5 | + <div class="right-side"> | |
| 6 | + <%= person.created_at.strftime("%d %B %Y at %H:%M") %> - <%= person.name %> <span class="model-label"><%= _("PERSON") %></span> | |
| 7 | + <div class="body"> | |
| 8 | + <h2><%= person.name %></h2> | |
| 9 | + <p><%= person.description %></p> | |
| 10 | + </div> | |
| 9 | 11 | </div> |
| 10 | 12 | </div> |
| 11 | - | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
| 1 | 1 | <div class="wrapper"> |
| 2 | 2 | |
| 3 | 3 | <div class="sidebar"> |
| 4 | - <%= @results.count %> | |
| 4 | + <div class="results-count"> | |
| 5 | + <%= @results.count %> <%= _(" results by") %> : | |
| 6 | + </div> | |
| 5 | 7 | <ul> |
| 6 | - <li class="select-search-type active"><a href="#"> <%= @searchable_types.values[0][:label] %></a></li> | |
| 7 | - <% for type in @searchable_types.values %> | |
| 8 | - <li class="select-search-type"><a href="#"> <%= type[:label] %></a></li> | |
| 8 | + <% for type,value in @searchable_types %> | |
| 9 | + <li class="select-search-type <%= "active" if type == @selected_type %>"> | |
| 10 | + <%= link_to value[:label], "?selected_type=#{type}&q=#{@query}&selected_filter_field=#{@selected_filter_field}"%> | |
| 11 | + </li> | |
| 9 | 12 | <% end %> |
| 10 | 13 | </ul> |
| 11 | 14 | |
| ... | ... | @@ -23,7 +26,8 @@ |
| 23 | 26 | <div class="search_field"> |
| 24 | 27 | <%= form_tag controller: "elasticsearch_plugin", action: "search" do %> |
| 25 | 28 | <%= text_field_tag(:q, @query) %> |
| 26 | - | |
| 29 | + <%= hidden_field_tag 'selected_type', @selected_type %> | |
| 30 | + <%= hidden_field_tag 'selected_filter_field', @selected_filter_field %> | |
| 27 | 31 | <%= submit_tag _("Send") %> |
| 28 | 32 | <% end %> |
| 29 | 33 | </div> |
| ... | ... | @@ -32,17 +36,14 @@ |
| 32 | 36 | <% for result in @results %> |
| 33 | 37 | <% for klass in @searchable_types.keys %> |
| 34 | 38 | <% next if klass.to_s.include? "all" %> |
| 35 | - | |
| 36 | 39 | <% if result.is_a? klass.to_s.classify.constantize %> |
| 37 | 40 | <div class="search-item"> |
| 38 | 41 | <%= render partial: "#{klass}_display", :locals => { klass => result} %> |
| 39 | 42 | </div> |
| 40 | 43 | <% break %> |
| 41 | 44 | <% end %> |
| 42 | - | |
| 43 | 45 | <% end %> |
| 44 | 46 | <% end %> |
| 45 | 47 | </div> |
| 46 | 48 | </div> |
| 47 | - | |
| 48 | 49 | </div> | ... | ... |