mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 20:05:55 +08:00
Merge pull request #40 from ZmagoD/zd_SCI_261
Fixed search query [fixes SCI-261]
This commit is contained in:
commit
43230384b5
3 changed files with 15 additions and 10 deletions
|
@ -47,22 +47,27 @@ class SearchController < ApplicationController
|
||||||
@search_category = params[:category] || ''
|
@search_category = params[:category] || ''
|
||||||
@search_category = @search_category.to_sym
|
@search_category = @search_category.to_sym
|
||||||
@search_page = params[:page].to_i || 1
|
@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
|
if @splited_query.first.length < MIN_QUERY_CHARS
|
||||||
@search_query.split().each do |w|
|
|
||||||
if w.length < MIN_QUERY_CHARS
|
|
||||||
error = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if error
|
|
||||||
flash[:error] = t'search.index.error.query_length', n: MIN_QUERY_CHARS
|
flash[:error] = t'search.index.error.query_length', n: MIN_QUERY_CHARS
|
||||||
redirect_to :back
|
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
|
end
|
||||||
|
|
||||||
if @search_page < 1
|
if @search_page < 1
|
||||||
@search_page = 1
|
@search_page = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Initialize markdown parser
|
# Initialize markdown parser
|
||||||
def load_markdown
|
def load_markdown
|
||||||
if @search_category == :results
|
if @search_category == :results
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<% provide(:head_title, t("search.index.head_title")) %>
|
<% 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 %>
|
<%= form_tag search_path, method: :get do %>
|
||||||
<%= hidden_field_tag :q, @search_query %>
|
<%= hidden_field_tag :q, @search_query %>
|
||||||
|
|
|
@ -119,7 +119,7 @@ en:
|
||||||
no_name: "(no name)"
|
no_name: "(no name)"
|
||||||
error:
|
error:
|
||||||
no_results: "No results for %{q}."
|
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."
|
max_length: "Search query is too long. The query is limited to %{n} characters."
|
||||||
samples:
|
samples:
|
||||||
sample: "Sample: "
|
sample: "Sample: "
|
||||||
|
|
Loading…
Add table
Reference in a new issue