summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-11-29 18:33:42 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-11-29 18:33:42 +0000
commitbf6e02c7394a468ac4a385c179e2eb7c3769eb52 (patch)
tree6f00f79b6a10bf8edfe65d49efac3986af9ca227 /app
parent233990dac389ad7b6924703a3752fcfb858e5060 (diff)
downloadredmine-bf6e02c7394a468ac4a385c179e2eb7c3769eb52.tar.gz
redmine-bf6e02c7394a468ac4a385c179e2eb7c3769eb52.zip
Search engine: search can be restricted to an exact phrase by using quotation marks (eg. hello "bye bye" can be used to search for "hello" and "bye bye" strings).
git-svn-id: http://redmine.rubyforge.org/svn/trunk@935 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/search_controller.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb
index 7c50d4dcb..ee4f863aa 100644
--- a/app/controllers/search_controller.rb
+++ b/app/controllers/search_controller.rb
@@ -52,8 +52,11 @@ class SearchController < ApplicationController
@object_types = @scope = %w(projects)
end
+ # extract tokens from the question
+ # eg. hello "bye bye" => ["hello", "bye bye"]
+ @tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
# tokens must be at least 3 character long
- @tokens = @question.split.uniq.select {|w| w.length > 2 }
+ @tokens = @tokens.uniq.select {|w| w.length > 2 }
if !@tokens.empty?
# no more than 5 tokens to search for
@@ -93,7 +96,6 @@ class SearchController < ApplicationController
# if only one project is found, user is redirected to its overview
redirect_to :controller => 'projects', :action => 'show', :id => @results.first and return if @results.size == 1
end
- @question = @tokens.join(" ")
else
@question = ""
end