OSDN Git Service

extended the search to wiki content
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Mar 2007 15:34:38 +0000 (15:34 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 10 Mar 2007 15:34:38 +0000 (15:34 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@325 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/projects_controller.rb
app/views/projects/search.rhtml

index 69d775c..f1d5c65 100644 (file)
@@ -556,7 +556,7 @@ class ProjectsController < ApplicationController
     @question = params[:q] || ""\r
     @question.strip!\r
     @all_words = params[:all_words] || (params[:submit] ? false : true)\r
-    @scope = params[:scope] || (params[:submit] ? [] : %w(issues news documents) )\r
+    @scope = params[:scope] || (params[:submit] ? [] : %w(issues news documents wiki) )\r
     if !@question.empty?\r
       # tokens must be at least 3 character long\r
       @tokens = @question.split.uniq.select {|w| w.length > 2 }\r
@@ -570,6 +570,7 @@ class ProjectsController < ApplicationController
       @results += @project.issues.find(:all, :limit => limit, :include => :author, :conditions => [ (["(LOWER(issues.subject) like ? OR LOWER(issues.description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @scope.include? 'issues'\r
       @results += @project.news.find(:all, :limit => limit, :conditions => [ (["(LOWER(news.title) like ? OR LOWER(news.description) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort], :include => :author ) if @scope.include? 'news'\r
       @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'\r
+      @results += @project.wiki.pages.find(:all, :limit => limit, :include => :content, :conditions => [ (["(LOWER(wiki_pages.title) like ? OR LOWER(wiki_contents.text) like ?)"] * like_tokens.size).join(operator), * (like_tokens * 2).sort] ) if @project.wiki && @scope.include?('wiki')\r
       @question = @tokens.join(" ")\r
     end\r
   end\r
index e699d87..d38cb3b 100644 (file)
@@ -5,7 +5,11 @@
 <p><%= text_field_tag 'q', @question, :size => 30 %>\r
 <%= check_box_tag 'scope[]', 'issues', (@scope.include? 'issues') %> <label><%= l(:label_issue_plural) %></label>\r
 <%= check_box_tag 'scope[]', 'news', (@scope.include? 'news') %> <label><%= l(:label_news_plural) %></label>\r
-<%= check_box_tag 'scope[]', 'documents', (@scope.include? 'documents') %> <label><%= l(:label_document_plural) %></label><br />\r
+<%= check_box_tag 'scope[]', 'documents', (@scope.include? 'documents') %> <label><%= l(:label_document_plural) %></label>\r
+<% if @project.wiki %>\r
+<%= check_box_tag 'scope[]', 'wiki', (@scope.include? 'wiki') %> <label><%= l(:label_wiki) %></label>\r
+<% end %>\r
+<br />\r
 <%= check_box_tag 'all_words', 1, @all_words %> <%= l(:label_all_words) %></p>\r
 <%= submit_tag l(:button_submit), :name => 'submit' %>\r
 <% end %>\r
             <%=l(:label_document)%>: <%= link_to highlight_tokens(h(e.title), @tokens), :controller => 'documents', :action => 'show', :id => e %><br />\r
             <%= highlight_tokens(e.description, @tokens) %><br />\r
             <i><%= format_time(e.created_on) %></i>\r
+        <% elsif e.is_a? WikiPage %>\r
+            <%=l(:label_wiki)%>: <%= link_to highlight_tokens(h(e.pretty_title), @tokens), :controller => 'wiki', :action => 'index', :id => @project, :page => e.title %><br />\r
+            <%= highlight_tokens(e.content.text, @tokens) %><br />\r
+            <i><%= e.content.author ? e.content.author.name : "Anonymous" %>, <%= format_time(e.content.updated_on) %></i>\r
         <% end %>\r
         </p></li>  \r
       <% end %>\r