Commit c7571504d4de9bd6b511b233889559b475352682
1 parent
9adc4947
Exists in
elasticsearch_sort
Fixing search using sort by
Signed-off-by: Macartur Sousa <macartur.sc@gmail.com> Signed-off-by: Arthur Jahn <stutrzbecher@gmail.com>
Showing
3 changed files
with
14 additions
and
12 deletions
Show diff stats
plugins/elasticsearch/controllers/elasticsearch_plugin_controller.rb
| ... | ... | @@ -27,6 +27,6 @@ class ElasticsearchPluginController < ApplicationController |
| 27 | 27 | |
| 28 | 28 | def define_search_fields_types |
| 29 | 29 | @search_filter_types = ElasticsearchHelper::search_filters |
| 30 | - @selected_filter_field = (params[:selected_filter_field]) | |
| 30 | + @selected_filter_field = (params[:selected_filter_field] || :relevance).to_sym | |
| 31 | 31 | end |
| 32 | 32 | end | ... | ... |
plugins/elasticsearch/helpers/elasticsearch_helper.rb
| ... | ... | @@ -13,9 +13,9 @@ module ElasticsearchHelper |
| 13 | 13 | |
| 14 | 14 | def self.search_filters |
| 15 | 15 | { |
| 16 | - :lexical => { label: _("Alphabetical Order")}, | |
| 17 | - :recent => { label: _("More Recent Order")}, | |
| 18 | - :access => { label: _("More accessed")} | |
| 16 | + :relevance => { label: _("Relevance")}, | |
| 17 | + :lexical => { label: _("Alphabetical")}, | |
| 18 | + :recent => { label: _("More Recent")}, | |
| 19 | 19 | } |
| 20 | 20 | end |
| 21 | 21 | |
| ... | ... | @@ -35,10 +35,10 @@ module ElasticsearchHelper |
| 35 | 35 | |
| 36 | 36 | def get_sort_by sort_by |
| 37 | 37 | case sort_by |
| 38 | - when "lexical" | |
| 39 | - "name.raw" | |
| 40 | - when "recent" | |
| 41 | - "created_at" | |
| 38 | + when "lexical" | |
| 39 | + { "name.raw" => {"order" => "asc" }} | |
| 40 | + when "recent" | |
| 41 | + { "created_at" => {"order" => "desc"}} | |
| 42 | 42 | end |
| 43 | 43 | end |
| 44 | 44 | |
| ... | ... | @@ -105,9 +105,9 @@ module ElasticsearchHelper |
| 105 | 105 | query = { |
| 106 | 106 | query: query_method(text, fields) |
| 107 | 107 | } |
| 108 | - if sort_by | |
| 109 | - query[:sort] = sort_by | |
| 110 | - end | |
| 108 | + | |
| 109 | + query[:sort] = [sort_by,"_score"] if sort_by | |
| 110 | + | |
| 111 | 111 | query |
| 112 | 112 | end |
| 113 | 113 | ... | ... |
plugins/elasticsearch/views/elasticsearch_plugin/search.html.erb
| ... | ... | @@ -14,7 +14,9 @@ |
| 14 | 14 | <h3 class="box-title"><%= _("Sort by") %></h3> |
| 15 | 15 | <ul> |
| 16 | 16 | <% for type, value in @search_filter_types %> |
| 17 | - <li><%= link_to value[:label], "?selected_type=#{@selected_type}&query=#{@query}&selected_filter_field=#{type}" %></li> | |
| 17 | + <li class="select-search-type <%= "active" if type == @selected_filter_field %>"> | |
| 18 | + <%= link_to value[:label], "?selected_type=#{@selected_type}&query=#{@query}&selected_filter_field=#{type}" %> | |
| 19 | + </li> | |
| 18 | 20 | <% end %> |
| 19 | 21 | </ul> |
| 20 | 22 | </div> | ... | ... |