search engine improvements and simple test

git-svn-id: http://redmine.rubyforge.org/svn/trunk@285 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-02-28 22:35:22 +00:00
parent 1fcc9e977f
commit 83c96d4f3e
5 changed files with 195 additions and 15 deletions

View File

@ -544,10 +544,12 @@ class ProjectsController < ApplicationController
@scope = params[:scope] || (params[:submit] ? [] : %w(issues news documents) ) @scope = params[:scope] || (params[:submit] ? [] : %w(issues news documents) )
if @token and @token.length > 2 if @token and @token.length > 2
@token.strip!
like_token = "%#{@token}%"
@results = [] @results = []
@results += @project.issues.find(:all, :include => :author, :conditions => ["issues.subject like ?", "%#{@token}%"] ) if @scope.include? 'issues' @results += @project.issues.find(:all, :include => :author, :conditions => ["issues.subject like ? or issues.description like ?", like_token, like_token] ) if @scope.include? 'issues'
@results += @project.news.find(:all, :conditions => ["news.title like ?", "%#{@token}%"], :include => :author ) if @scope.include? 'news' @results += @project.news.find(:all, :conditions => ["news.title like ? or news.description like ?", like_token, like_token], :include => :author ) if @scope.include? 'news'
@results += @project.documents.find(:all, :conditions => ["title like ?", "%#{@token}%"] ) if @scope.include? 'documents' @results += @project.documents.find(:all, :conditions => ["title like ? or description like ?", like_token, like_token] ) if @scope.include? 'documents'
end end
end end

View File

@ -15,5 +15,9 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module ProjectsHelper module ProjectsHelper
def result_overview(text, token)
match = excerpt(text, token)
match ? highlight(match, token) : truncate(text, 150)
end
end end

View File

@ -16,15 +16,17 @@
<% @results.each do |e| %> <% @results.each do |e| %>
<li><p> <li><p>
<% if e.is_a? Issue %> <% if e.is_a? Issue %>
<%= link_to "#{e.tracker.name} ##{e.id}", :controller => 'issues', :action => 'show', :id => e %>: <%= highlight(h(e.subject), @token) %><br /> <%= link_to "#{e.tracker.name} ##{e.id}", :controller => 'issues', :action => 'show', :id => e %>: <%= highlight(h(e.subject), @token) %><br />
<i><%= e.author.name %>, <%= format_time(e.created_on) %></i> <%= result_overview(e.description, @token) %><br />
<i><%= e.author.name %>, <%= format_time(e.created_on) %></i>
<% elsif e.is_a? News %> <% elsif e.is_a? News %>
<%=l(:label_news)%>: <%= link_to highlight(h(e.title), @token), :controller => 'news', :action => 'show', :id => e %><br /> <%=l(:label_news)%>: <%= link_to highlight(h(e.title), @token), :controller => 'news', :action => 'show', :id => e %><br />
<% unless e.summary.empty? %><%=h e.summary %><br /><% end %> <%= result_overview(e.description, @token) %><br />
<i><%= e.author.name %>, <%= format_time(e.created_on) %></i> <i><%= e.author.name %>, <%= format_time(e.created_on) %></i>
<% elsif e.is_a? Document %> <% elsif e.is_a? Document %>
<%=l(:label_document)%>: <%= link_to highlight(h(e.title), @token), :controller => 'documents', :action => 'show', :id => e %><br /> <%=l(:label_document)%>: <%= link_to highlight(h(e.title), @token), :controller => 'documents', :action => 'show', :id => e %><br />
<i><%= format_time(e.created_on) %></i> <%= result_overview(e.description, @token) %><br />
<i><%= format_time(e.created_on) %></i>
<% end %> <% end %>
</p></li> </p></li>
<% end %> <% end %>

View File

@ -1,11 +1,20 @@
--- ---
permissions_052:
action: destroy_comment
id: 52
description: label_comment_delete
controller: news
mail_enabled: false
mail_option: false
sort: 1133
is_public: false
permissions_041: permissions_041:
action: add_file action: add_file
id: 41 id: 41
description: button_add description: button_add
controller: projects controller: projects
mail_enabled: false mail_enabled: false
mail_option: false mail_option: true
sort: 1320 sort: 1320
is_public: false is_public: false
permissions_030: permissions_030:
@ -35,6 +44,15 @@ permissions_008:
mail_option: false mail_option: false
sort: 221 sort: 221
is_public: false is_public: false
permissions_053:
action: add_query
id: 53
description: button_create
controller: projects
mail_enabled: false
mail_option: false
sort: 600
is_public: false
permissions_042: permissions_042:
action: destroy_file action: destroy_file
id: 42 id: 42
@ -71,6 +89,24 @@ permissions_009:
mail_option: false mail_option: false
sort: 222 sort: 222
is_public: false is_public: false
permissions_054:
action: show
id: 54
description: button_view
controller: repositories
mail_enabled: false
mail_option: false
sort: 1450
is_public: true
permissions_043:
action: move_issues
id: 43
description: button_move
controller: projects
mail_enabled: false
mail_option: false
sort: 1061
is_public: false
permissions_032: permissions_032:
action: show action: show
id: 32 id: 32
@ -98,6 +134,24 @@ permissions_010:
mail_option: false mail_option: false
sort: 320 sort: 320
is_public: false is_public: false
permissions_055:
action: browse
id: 55
description: label_browse
controller: repositories
mail_enabled: false
mail_option: false
sort: 1460
is_public: true
permissions_044:
action: add_note
id: 44
description: label_add_note
controller: issues
mail_enabled: false
mail_option: true
sort: 1057
is_public: false
permissions_033: permissions_033:
action: download action: download
id: 33 id: 33
@ -125,13 +179,31 @@ permissions_011:
mail_option: false mail_option: false
sort: 321 sort: 321
is_public: false is_public: false
permissions_056:
action: entry
id: 56
description: entry
controller: repositories
mail_enabled: false
mail_option: false
sort: 1462
is_public: true
permissions_045:
action: export_issues_pdf
id: 45
description: label_export_pdf
controller: projects
mail_enabled: false
mail_option: false
sort: 1002
is_public: true
permissions_034: permissions_034:
action: add_document action: add_document
id: 34 id: 34
description: button_add description: button_add
controller: projects controller: projects
mail_enabled: false mail_enabled: false
mail_option: false mail_option: true
sort: 1220 sort: 1220
is_public: false is_public: false
permissions_023: permissions_023:
@ -161,6 +233,24 @@ permissions_001:
mail_option: false mail_option: false
sort: 100 sort: 100
is_public: true is_public: true
permissions_057:
action: revisions
id: 57
description: label_view_revisions
controller: repositories
mail_enabled: false
mail_option: false
sort: 1470
is_public: true
permissions_046:
action: export_pdf
id: 46
description: label_export_pdf
controller: issues
mail_enabled: false
mail_option: false
sort: 1015
is_public: true
permissions_035: permissions_035:
action: edit action: edit
id: 35 id: 35
@ -176,7 +266,7 @@ permissions_024:
description: label_attachment_new description: label_attachment_new
controller: issues controller: issues
mail_enabled: false mail_enabled: false
mail_option: false mail_option: true
sort: 1070 sort: 1070
is_public: false is_public: false
permissions_013: permissions_013:
@ -197,6 +287,24 @@ permissions_002:
mail_option: false mail_option: false
sort: 105 sort: 105
is_public: true is_public: true
permissions_058:
action: revision
id: 58
description: label_view_revisions
controller: repositories
mail_enabled: false
mail_option: false
sort: 1472
is_public: true
permissions_047:
action: activity
id: 47
description: label_activity
controller: projects
mail_enabled: false
mail_option: false
sort: 160
is_public: true
permissions_036: permissions_036:
action: destroy action: destroy
id: 36 id: 36
@ -233,13 +341,31 @@ permissions_003:
mail_option: false mail_option: false
sort: 110 sort: 110
is_public: true is_public: true
permissions_059:
action: diff
id: 59
description: diff
controller: repositories
mail_enabled: false
mail_option: false
sort: 1480
is_public: true
permissions_048:
action: calendar
id: 48
description: label_calendar
controller: projects
mail_enabled: false
mail_option: false
sort: 165
is_public: true
permissions_037: permissions_037:
action: add_attachment action: add_attachment
id: 37 id: 37
description: label_attachment_new description: label_attachment_new
controller: documents controller: documents
mail_enabled: false mail_enabled: false
mail_option: false mail_option: true
sort: 1223 sort: 1223
is_public: false is_public: false
permissions_026: permissions_026:
@ -269,6 +395,24 @@ permissions_004:
mail_option: false mail_option: false
sort: 150 sort: 150
is_public: false is_public: false
permissions_060:
action: search
id: 61
description: label_search
controller: projects
mail_enabled: false
mail_option: false
sort: 130
is_public: true
permissions_049:
action: gantt
id: 49
description: label_gantt
controller: projects
mail_enabled: false
mail_option: false
sort: 166
is_public: true
permissions_038: permissions_038:
action: destroy_attachment action: destroy_attachment
id: 38 id: 38
@ -305,6 +449,15 @@ permissions_005:
mail_option: false mail_option: false
sort: 151 sort: 151
is_public: false is_public: false
permissions_050:
action: history
id: 50
description: label_history
controller: issues
mail_enabled: false
mail_option: false
sort: 1006
is_public: true
permissions_039: permissions_039:
action: list_files action: list_files
id: 39 id: 39
@ -341,6 +494,15 @@ permissions_006:
mail_option: false mail_option: false
sort: 200 sort: 200
is_public: true is_public: true
permissions_051:
action: add_comment
id: 51
description: label_comment_add
controller: news
mail_enabled: false
mail_option: false
sort: 1130
is_public: false
permissions_040: permissions_040:
action: download action: download
id: 40 id: 40

View File

@ -111,4 +111,14 @@ class ProjectsControllerTest < Test::Unit::TestCase
assert_template 'changelog' assert_template 'changelog'
assert_not_nil assigns(:fixed_issues) assert_not_nil assigns(:fixed_issues)
end end
def test_search
get :search, :id => 1
assert_response :success
assert_template 'search'
get :search, :id => 1, :token => "can", :scope => ["issues", "news", "documents"]
assert_response :success
assert_template 'search'
end
end end