fixed search [fixes SCI-261]

This commit is contained in:
zmagod 2016-07-29 16:32:54 +02:00
parent 2a0eafeebb
commit 25b99b6570
3 changed files with 16 additions and 10 deletions

View file

@ -47,22 +47,28 @@ class SearchController < ApplicationController
@search_category = params[:category] || ''
@search_category = @search_category.to_sym
@search_page = params[:page].to_i || 1
@display_query = @search_query
# splits the search query to validate all entries
@splited_query = @search_query.split()
error = false
@search_query.split().each do |w|
if w.length < MIN_QUERY_CHARS
error = true
if @splited_query.first.length < MIN_QUERY_CHARS
flash[:error] = t'search.index.error.query_length', n: MIN_QUERY_CHARS
redirect_to :back
else
@splited_query.each_with_index do |w, i|
if @splited_query.length > 1 && w.length < MIN_QUERY_CHARS
@splited_query.slice!(i)
end
end
end
if error
flash[:error] = t'search.index.error.query_length', n: MIN_QUERY_CHARS
redirect_to :back
end
@search_query = @splited_query.join(' ')
if @search_page < 1
@search_page = 1
end
end
# Initialize markdown parser
def load_markdown
if @search_category == :results

View file

@ -1,6 +1,6 @@
<% provide(:head_title, t("search.index.head_title")) %>
<h1 class="page-header"><%= t('search.index.results_title_html', query: @search_query) %></h1>
<h1 class="page-header"><%= t('search.index.results_title_html', query: @display_query) %></h1>
<%= form_tag search_path, method: :get do %>
<%= hidden_field_tag :q, @search_query %>

View file

@ -119,7 +119,7 @@ en:
no_name: "(no name)"
error:
no_results: "No results for %{q}."
query_length: "Search query is too short. Each word should contain at least %{n} characters."
query_length: "Search query is too short. It should contain at least %{n} characters."
max_length: "Search query is too long. The query is limited to %{n} characters."
samples:
sample: "Sample: "