summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2007-02-28 22:35:22 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2007-02-28 22:35:22 +0000
commit83c96d4f3ef2adb8ec3226f82bc68e8f1accd6d9 (patch)
treed6033e6baf7f8d4a7f17259c73fc14ab7cd65d02 /app
parent1fcc9e977f55cd3bf1c327751b9b3d86c283e1aa (diff)
downloadredmine-83c96d4f3ef2adb8ec3226f82bc68e8f1accd6d9.tar.gz
redmine-83c96d4f3ef2adb8ec3226f82bc68e8f1accd6d9.zip
search engine improvements and simple test
git-svn-id: http://redmine.rubyforge.org/svn/trunk@285 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects_controller.rb8
-rw-r--r--app/helpers/projects_helper.rb6
-rw-r--r--app/views/projects/search.rhtml16
3 files changed, 19 insertions, 11 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index ab1cb3e1b..a8d943426 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -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
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 0c85ce24c..a6c033d0f 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -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
diff --git a/app/views/projects/search.rhtml b/app/views/projects/search.rhtml
index 32e486fee..df95ee3ae 100644
--- a/app/views/projects/search.rhtml
+++ b/app/views/projects/search.rhtml
@@ -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 %>