From 8dcc041244822db6d994bc04dea94306216c4ee0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 5 Sep 2007 19:37:13 +0000 Subject: [PATCH] Issue notes are now included in search. Fixed: search results too long when there are many matches. Fixed: search results not escaped. git-svn-id: http://redmine.rubyforge.org/svn/trunk@705 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/search_controller.rb | 4 ++++ app/helpers/search_helper.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 01c72f182..2a3fe4f7c 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -51,6 +51,10 @@ class SearchController < ApplicationController @results = [] if @project @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(subject) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues' + Journal.with_scope :find => {:conditions => ["#{Issue.table_name}.project_id = ?", @project.id]} do + @results += Journal.find(:all, :include => :issue, :limit => limit, :conditions => [ (["(LOWER(notes) like ? OR LOWER(notes) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ).collect(&:issue) if @scope.include? 'issues' + end + @results.uniq! @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news' @results += @project.documents.find(:all, :limit => limit, :conditions => [ (["(LOWER(title) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'documents' @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(title) like ? OR LOWER(text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki') diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index bc408a305..676a7e8e3 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -21,7 +21,12 @@ module SearchHelper regexp = Regexp.new "(#{tokens.join('|')})", Regexp::IGNORECASE result = '' text.split(regexp).each_with_index do |words, i| - result << (i.even? ? (words.length > 100 ? "#{words[0..44]} ... #{words[-45..-1]}" : words) : content_tag('span', words, :class => 'highlight')) + if result.length > 1200 + # maximum length of the preview reached + result << '...' + break + end + result << (i.even? ? h(words.length > 100 ? "#{words[0..44]} ... #{words[-45..-1]}" : words) : content_tag('span', h(words), :class => 'highlight')) end result end -- 2.39.5