Text search added on messages.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@533 e93f8b46-1217-0410-a6f0-8f06a7374b81
pull/351/head
Jean-Philippe Lang 18 years ago
parent b11dd1f213
commit 7b13b58a2f
  1. 8
      app/controllers/search_controller.rb
  2. 7
      app/views/search/index.rhtml

@ -18,11 +18,14 @@
class SearchController < ApplicationController
layout 'base'
helper :messages
include MessagesHelper
def index
@question = params[:q] || ""
@question.strip!
@all_words = params[:all_words] || (params[:submit] ? false : true)
@scope = params[:scope] || (params[:submit] ? [] : %w(projects issues changesets news documents wiki) )
@scope = params[:scope] || (params[:submit] ? [] : %w(projects issues changesets news documents wiki messages) )
# quick jump to an issue
if @scope.include?('issues') && @question.match(/^#?(\d+)$/) && Issue.find_by_id($1, :include => :project, :conditions => Project.visible_by(logged_in_user))
@ -52,6 +55,9 @@ class SearchController < ApplicationController
@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')
@results += @project.repository.changesets.find(:all, :limit => limit, :conditions => [ (["(LOWER(comments) like ?)"] * like_tokens.size).join(operator), * (like_tokens).sort] ) if @project.repository && @scope.include?('changesets')
Message.with_scope :find => {:conditions => ["#{Board.table_name}.project_id = ?", @project.id]} do
@results += Message.find(:all, :include => :board, :limit => limit, :conditions => [ (["(LOWER(subject) like ? OR LOWER(content) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'messages'
end
else
Project.with_scope(:find => {:conditions => Project.visible_by(logged_in_user)}) do
@results += Project.find(:all, :limit => limit, :conditions => [ (["(LOWER(name) like ? OR LOWER(description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'projects'

@ -14,6 +14,9 @@
<% if @project.wiki %>
<%= check_box_tag 'scope[]', 'wiki', (@scope.include? 'wiki') %> <label><%= l(:label_wiki) %></label>
<% end %>
<% if @project.boards.any? %>
<%= check_box_tag 'scope[]', 'messages', (@scope.include? 'messages') %> <label><%= l(:label_message_plural) %></label>
<% end %>
<% else %>
<%= check_box_tag 'scope[]', 'projects', (@scope.include? 'projects') %> <label><%= l(:label_project_plural) %></label>
<% end %>
@ -51,6 +54,10 @@
<%=l(:label_revision)%> <%= link_to h(e.revision), :controller => 'repositories', :action => 'revision', :id => @project, :rev => e.revision %><br />
<%= highlight_tokens(e.comments, @tokens) %><br />
<em><%= e.committer.blank? ? e.committer : "Anonymous" %>, <%= format_time(e.committed_on) %></em>
<% elsif e.is_a? Message %>
<%=h e.board.name %>: <%= link_to_message e %><br />
<%= highlight_tokens(e.content, @tokens) %><br />
<em><%= e.author ? e.author.name : "Anonymous" %>, <%= format_time(e.created_on) %></em>
<% end %>
</p></li>
<% end %>

Loading…
Cancel
Save