Project

General

Profile

« Previous | Next » 

Revision 705

Issue notes are now included in search.
Fixed: search results too long when there are many matches.
Fixed: search results not escaped.

View differences:

trunk/app/controllers/search_controller.rb
51 51
      @results = []
52 52
      if @project
53 53
        @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'
54
        Journal.with_scope :find => {:conditions => ["#{Issue.table_name}.project_id = ?", @project.id]} do
55
          @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'
56
        end
57
        @results.uniq!
54 58
        @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'
55 59
        @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'
56 60
        @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')
trunk/app/helpers/search_helper.rb
21 21
    regexp = Regexp.new "(#{tokens.join('|')})", Regexp::IGNORECASE    
22 22
    result = ''
23 23
    text.split(regexp).each_with_index do |words, i|
24
      result << (i.even? ? (words.length > 100 ? "#{words[0..44]} ... #{words[-45..-1]}" : words) : content_tag('span', words, :class => 'highlight'))
24
      if result.length > 1200
25
        # maximum length of the preview reached
26
        result << '...'
27
        break
28
      end
29
      result << (i.even? ? h(words.length > 100 ? "#{words[0..44]} ... #{words[-45..-1]}" : words) : content_tag('span', h(words), :class => 'highlight'))
25 30
    end
26 31
    result
27 32
  end

Also available in: Unified diff