From 83c96d4f3ef2adb8ec3226f82bc68e8f1accd6d9 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 28 Feb 2007 22:35:22 +0000 Subject: search engine improvements and simple test git-svn-id: http://redmine.rubyforge.org/svn/trunk@285 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/projects_controller.rb | 8 +++++--- app/helpers/projects_helper.rb | 6 +++++- app/views/projects/search.rhtml | 16 +++++++++------- 3 files changed, 19 insertions(+), 11 deletions(-) (limited to 'app') 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| %>
  • <% if e.is_a? Issue %> - <%= link_to "#{e.tracker.name} ##{e.id}", :controller => 'issues', :action => 'show', :id => e %>: <%= highlight(h(e.subject), @token) %>
    - <%= e.author.name %>, <%= format_time(e.created_on) %> + <%= link_to "#{e.tracker.name} ##{e.id}", :controller => 'issues', :action => 'show', :id => e %>: <%= highlight(h(e.subject), @token) %>
    + <%= result_overview(e.description, @token) %>
    + <%= e.author.name %>, <%= format_time(e.created_on) %> <% elsif e.is_a? News %> - <%=l(:label_news)%>: <%= link_to highlight(h(e.title), @token), :controller => 'news', :action => 'show', :id => e %>
    - <% unless e.summary.empty? %><%=h e.summary %>
    <% end %> - <%= e.author.name %>, <%= format_time(e.created_on) %> + <%=l(:label_news)%>: <%= link_to highlight(h(e.title), @token), :controller => 'news', :action => 'show', :id => e %>
    + <%= result_overview(e.description, @token) %>
    + <%= e.author.name %>, <%= format_time(e.created_on) %> <% elsif e.is_a? Document %> - <%=l(:label_document)%>: <%= link_to highlight(h(e.title), @token), :controller => 'documents', :action => 'show', :id => e %>
    - <%= format_time(e.created_on) %> + <%=l(:label_document)%>: <%= link_to highlight(h(e.title), @token), :controller => 'documents', :action => 'show', :id => e %>
    + <%= result_overview(e.description, @token) %>
    + <%= format_time(e.created_on) %> <% end %>

  • <% end %> -- cgit v1.2.3