##// END OF EJS Templates
remove trailing white-spaces from app/controllers/search_controller.rb....
Toshi MARUYAMA -
r6686:7b3c92ae05de
parent child
Show More
@@ -5,12 +5,12
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -26,7 +26,7 class SearchController < ApplicationController
26 @question.strip!
26 @question.strip!
27 @all_words = params[:all_words] ? params[:all_words].present? : true
27 @all_words = params[:all_words] ? params[:all_words].present? : true
28 @titles_only = params[:titles_only] ? params[:titles_only].present? : false
28 @titles_only = params[:titles_only] ? params[:titles_only].present? : false
29
29
30 projects_to_search =
30 projects_to_search =
31 case params[:scope]
31 case params[:scope]
32 when 'all'
32 when 'all'
@@ -38,16 +38,16 class SearchController < ApplicationController
38 else
38 else
39 @project
39 @project
40 end
40 end
41
41
42 offset = nil
42 offset = nil
43 begin; offset = params[:offset].to_time if params[:offset]; rescue; end
43 begin; offset = params[:offset].to_time if params[:offset]; rescue; end
44
44
45 # quick jump to an issue
45 # quick jump to an issue
46 if @question.match(/^#?(\d+)$/) && Issue.visible.find_by_id($1.to_i)
46 if @question.match(/^#?(\d+)$/) && Issue.visible.find_by_id($1.to_i)
47 redirect_to :controller => "issues", :action => "show", :id => $1
47 redirect_to :controller => "issues", :action => "show", :id => $1
48 return
48 return
49 end
49 end
50
50
51 @object_types = Redmine::Search.available_search_types.dup
51 @object_types = Redmine::Search.available_search_types.dup
52 if projects_to_search.is_a? Project
52 if projects_to_search.is_a? Project
53 # don't search projects
53 # don't search projects
@@ -55,23 +55,23 class SearchController < ApplicationController
55 # only show what the user is allowed to view
55 # only show what the user is allowed to view
56 @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, projects_to_search)}
56 @object_types = @object_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, projects_to_search)}
57 end
57 end
58
58
59 @scope = @object_types.select {|t| params[t]}
59 @scope = @object_types.select {|t| params[t]}
60 @scope = @object_types if @scope.empty?
60 @scope = @object_types if @scope.empty?
61
61
62 # extract tokens from the question
62 # extract tokens from the question
63 # eg. hello "bye bye" => ["hello", "bye bye"]
63 # eg. hello "bye bye" => ["hello", "bye bye"]
64 @tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
64 @tokens = @question.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m| m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')}
65 # tokens must be at least 2 characters long
65 # tokens must be at least 2 characters long
66 @tokens = @tokens.uniq.select {|w| w.length > 1 }
66 @tokens = @tokens.uniq.select {|w| w.length > 1 }
67
67
68 if !@tokens.empty?
68 if !@tokens.empty?
69 # no more than 5 tokens to search for
69 # no more than 5 tokens to search for
70 @tokens.slice! 5..-1 if @tokens.size > 5
70 @tokens.slice! 5..-1 if @tokens.size > 5
71
71
72 @results = []
72 @results = []
73 @results_by_type = Hash.new {|h,k| h[k] = 0}
73 @results_by_type = Hash.new {|h,k| h[k] = 0}
74
74
75 limit = 10
75 limit = 10
76 @scope.each do |s|
76 @scope.each do |s|
77 r, c = s.singularize.camelcase.constantize.search(@tokens, projects_to_search,
77 r, c = s.singularize.camelcase.constantize.search(@tokens, projects_to_search,
@@ -87,13 +87,13 class SearchController < ApplicationController
87 if params[:previous].nil?
87 if params[:previous].nil?
88 @pagination_previous_date = @results[0].event_datetime if offset && @results[0]
88 @pagination_previous_date = @results[0].event_datetime if offset && @results[0]
89 if @results.size > limit
89 if @results.size > limit
90 @pagination_next_date = @results[limit-1].event_datetime
90 @pagination_next_date = @results[limit-1].event_datetime
91 @results = @results[0, limit]
91 @results = @results[0, limit]
92 end
92 end
93 else
93 else
94 @pagination_next_date = @results[-1].event_datetime if offset && @results[-1]
94 @pagination_next_date = @results[-1].event_datetime if offset && @results[-1]
95 if @results.size > limit
95 if @results.size > limit
96 @pagination_previous_date = @results[-(limit)].event_datetime
96 @pagination_previous_date = @results[-(limit)].event_datetime
97 @results = @results[-(limit), limit]
97 @results = @results[-(limit), limit]
98 end
98 end
99 end
99 end
@@ -103,7 +103,7 class SearchController < ApplicationController
103 render :layout => false if request.xhr?
103 render :layout => false if request.xhr?
104 end
104 end
105
105
106 private
106 private
107 def find_optional_project
107 def find_optional_project
108 return true unless params[:id]
108 return true unless params[:id]
109 @project = Project.find(params[:id])
109 @project = Project.find(params[:id])
General Comments 0
You need to be logged in to leave comments. Login now