Merge pull request #40 from ZmagoD/zd_SCI_261

Fixed search query [fixes SCI-261]
This commit is contained in:
Zmago Devetak 2016-08-02 11:44:00 +02:00 committed by GitHub
commit 43230384b5
3 changed files with 15 additions and 10 deletions

View file

@ -47,22 +47,27 @@ 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
end
end
if error
if @splited_query.first.length < MIN_QUERY_CHARS
flash[:error] = t'search.index.error.query_length', n: MIN_QUERY_CHARS
redirect_to :back
elsif @splited_query.length > 1
@search_query = ''
@splited_query.each_with_index do |w, i|
@search_query += "#{@splited_query[i]} " if w.length >= MIN_QUERY_CHARS
end
else
@search_query = @splited_query.join(' ')
end
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: "