diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 6e15d288c..979e335ab 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -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 diff --git a/app/views/search/index.html.erb b/app/views/search/index.html.erb index 4c2c6e2f3..5574f8c8e 100644 --- a/app/views/search/index.html.erb +++ b/app/views/search/index.html.erb @@ -1,6 +1,6 @@ <% provide(:head_title, t("search.index.head_title")) %> -