summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-15 16:53:39 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-10-15 16:53:39 +0000
commitb9cc65db61016f88cb63ce639df078f541a3e5a1 (patch)
tree7f615c79d93d00967980ab5c153e07ab72a46636 /app
parent74ecb37be657611fdc239d808d96f6932d61d3d0 (diff)
downloadredmine-b9cc65db61016f88cb63ce639df078f541a3e5a1.tar.gz
redmine-b9cc65db61016f88cb63ce639df078f541a3e5a1.zip
Search engine: added a checkbox to search titles only (usefull when searching on common words).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@842 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/search_controller.rb13
-rw-r--r--app/views/search/index.rhtml6
2 files changed, 13 insertions, 6 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 292472fba..2c00b3d74 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -25,6 +25,7 @@ class SearchController < ApplicationController
@question = params[:q] || ""
@question.strip!
@all_words = params[:all_words] || (params[:submit] ? false : true)
+ @titles_only = !params[:titles_only].nil?
offset = nil
begin; offset = params[:offset].to_time if params[:offset]; rescue; end
@@ -58,14 +59,17 @@ class SearchController < ApplicationController
# no more than 5 tokens to search for
@tokens.slice! 5..-1 if @tokens.size > 5
# strings used in sql like statement
- like_tokens = @tokens.collect {|w| "%#{w.downcase}%"}
- operator = @all_words ? " AND " : " OR "
+ like_tokens = @tokens.collect {|w| "%#{w.downcase}%"}
@results = []
limit = 10
if @project
@scope.each do |s|
- @results += s.singularize.camelcase.constantize.search(like_tokens, @all_words, @project,
- :limit => (limit+1), :offset => offset, :before => params[:previous].nil?)
+ @results += s.singularize.camelcase.constantize.search(like_tokens, @project,
+ :all_words => @all_words,
+ :titles_only => @titles_only,
+ :limit => (limit+1),
+ :offset => offset,
+ :before => params[:previous].nil?)
end
@results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime}
if params[:previous].nil?
@@ -82,6 +86,7 @@ class SearchController < ApplicationController
end
end
else
+ operator = @all_words ? ' AND ' : ' OR '
Project.with_scope(:find => {:conditions => Project.visible_by(logged_in_user)}) do
@results += Project.find(:all, :limit => limit, :conditions => [ (["(LOWER(name) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'projects'
end
diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml
index 4bf80f054..695107fe8 100644
--- a/app/views/search/index.rhtml
+++ b/app/views/search/index.rhtml
@@ -2,14 +2,16 @@
<div class="box">
<% form_tag({}, :method => :get) do %>
-<p><%= text_field_tag 'q', @question, :size => 30, :id => 'search-input' %>
+<p><%= text_field_tag 'q', @question, :size => 60, :id => 'search-input' %>
<%= javascript_tag "Field.focus('search-input')" %>
<% @object_types.each do |t| %>
<label><%= check_box_tag t, 1, @scope.include?(t) %> <%= l("label_#{t.singularize}_plural")%></label>
<% end %>
<br />
-<label><%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></label></p>
+<label><%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></label>
+<label><%= check_box_tag 'titles_only', 1, @titles_only %> <%= l(:label_search_titles_only) %></label>
+</p>
<%= submit_tag l(:button_submit), :name => 'submit' %>
<% end %>
</div>