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
+5 -3
View File
@@ -544,10 +544,12 @@ class ProjectsController < ApplicationController
@scope = params[:scope] || (params[:submit] ? [] : %w(issues news documents) )
if @token and @token.length > 2
@token.strip!
like_token = "%#{@token}%"
@results = []
@results += @project.issues.find(:all, :include => :author, :conditions => ["issues.subject like ?", "%#{@token}%"] ) if @scope.include? 'issues'
@results += @project.news.find(:all, :conditions => ["news.title like ?", "%#{@token}%"], :include => :author ) if @scope.include? 'news'
@results += @project.documents.find(:all, :conditions => ["title like ?", "%#{@token}%"] ) if @scope.include? 'documents'
@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 ? or news.description like ?", like_token, like_token], :include => :author ) if @scope.include? 'news'
@results += @project.documents.find(:all, :conditions => ["title like ? or description like ?", like_token, like_token] ) if @scope.include? 'documents'
end
end
+5 -1
View File
@@ -15,5 +15,9 @@
# along with this program; if not, write to the Free Software
# 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
+9 -7
View File
@@ -16,15 +16,17 @@
<% @results.each do |e| %>
<li><p>
<% if e.is_a? Issue %>
<%= 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>
<%= link_to "#{e.tracker.name} ##{e.id}", :controller => 'issues', :action => 'show', :id => e %>: <%= highlight(h(e.subject), @token) %><br />
<%= result_overview(e.description, @token) %><br />
<i><%= e.author.name %>, <%= format_time(e.created_on) %></i>
<% elsif e.is_a? News %>
<%=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 %>
<i><%= e.author.name %>, <%= format_time(e.created_on) %></i>
<%=l(:label_news)%>: <%= link_to highlight(h(e.title), @token), :controller => 'news', :action => 'show', :id => e %><br />
<%= result_overview(e.description, @token) %><br />
<i><%= e.author.name %>, <%= format_time(e.created_on) %></i>
<% elsif e.is_a? Document %>
<%=l(:label_document)%>: <%= link_to highlight(h(e.title), @token), :controller => 'documents', :action => 'show', :id => e %><br />
<i><%= format_time(e.created_on) %></i>
<%=l(:label_document)%>: <%= link_to highlight(h(e.title), @token), :controller => 'documents', :action => 'show', :id => e %><br />
<%= result_overview(e.description, @token) %><br />
<i><%= format_time(e.created_on) %></i>
<% end %>
</p></li>
<% end %>