diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/search_controller.rb | 7 | ||||
-rw-r--r-- | app/helpers/search_helper.rb | 16 | ||||
-rw-r--r-- | app/models/issue.rb | 5 | ||||
-rw-r--r-- | app/models/journal.rb | 6 | ||||
-rw-r--r-- | app/views/search/index.rhtml | 10 |
5 files changed, 33 insertions, 11 deletions
diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index d4ef01bf8..50e42f088 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -72,15 +72,20 @@ class SearchController < ApplicationController @tokens.slice! 5..-1 if @tokens.size > 5 # strings used in sql like statement like_tokens = @tokens.collect {|w| "%#{w.downcase}%"} + @results = [] + @results_by_type = Hash.new {|h,k| h[k] = 0} + limit = 10 @scope.each do |s| - @results += s.singularize.camelcase.constantize.search(like_tokens, projects_to_search, + r, c = s.singularize.camelcase.constantize.search(like_tokens, projects_to_search, :all_words => @all_words, :titles_only => @titles_only, :limit => (limit+1), :offset => offset, :before => params[:previous].nil?) + @results += r + @results_by_type[s] += c end @results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime} if params[:previous].nil? diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index d6a2fb949..92f2da8a5 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -36,6 +36,10 @@ module SearchHelper result end + def type_label(t) + l("label_#{t.singularize}_plural") + end + def project_select_tag options = [[l(:label_project_all), 'all']] options << [l(:label_my_projects), 'my_projects'] unless User.current.memberships.empty? @@ -43,4 +47,16 @@ module SearchHelper options << [@project.name, ''] unless @project.nil? select_tag('scope', options_for_select(options, params[:scope].to_s)) if options.size > 1 end + + def render_results_by_type(results_by_type) + links = [] + # Sorts types by results count + results_by_type.keys.sort {|a, b| results_by_type[b] <=> results_by_type[a]}.each do |t| + c = results_by_type[t] + next if c == 0 + text = "#{type_label(t)} (#{c})" + links << link_to(text, :q => params[:q], :titles_only => params[:title_only], :all_words => params[:all_words], :scope => params[:scope], t => 1) + end + ('<ul>' + links.map {|link| content_tag('li', link)}.join(' ') + '</ul>') unless links.empty? + end end diff --git a/app/models/issue.rb b/app/models/issue.rb index b19e64883..cae603dd8 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -35,7 +35,10 @@ class Issue < ActiveRecord::Base acts_as_customizable acts_as_watchable - acts_as_searchable :columns => ['subject', "#{table_name}.description"], :include => :project, :with => {:journal => :issue} + acts_as_searchable :columns => ['subject', "#{table_name}.description", "#{Journal.table_name}.notes"], + :include => [:project, :journals], + # sort by id so that limited eager loading doesn't break with postgresql + :order_column => "#{table_name}.id" acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"}, :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}} diff --git a/app/models/journal.rb b/app/models/journal.rb index 8583f63de..a427f84e3 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -25,12 +25,6 @@ class Journal < ActiveRecord::Base has_many :details, :class_name => "JournalDetail", :dependent => :delete_all attr_accessor :indice - acts_as_searchable :columns => 'notes', - :include => {:issue => :project}, - :project_key => "#{Issue.table_name}.project_id", - :date_column => "#{Issue.table_name}.created_on", - :permission => :view_issues - acts_as_event :title => Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.id}#{status}: #{o.issue.subject}" }, :description => :notes, :author => :user, diff --git a/app/views/search/index.rhtml b/app/views/search/index.rhtml index b5cea4645..cb5b70a4c 100644 --- a/app/views/search/index.rhtml +++ b/app/views/search/index.rhtml @@ -10,7 +10,7 @@ </p>
<p>
<% @object_types.each do |t| %>
-<label><%= check_box_tag t, 1, @scope.include?(t) %> <%= l("label_#{t.singularize}_plural")%></label>
+<label><%= check_box_tag t, 1, @scope.include?(t) %> <%= type_label(t) %></label>
<% end %>
</p>
@@ -19,12 +19,16 @@ </div>
<% if @results %>
- <h3><%= l(:label_result_plural) %></h3>
+ <div id="search-results-counts">
+ <%= render_results_by_type(@results_by_type) unless @scope.size == 1 %>
+ </div>
+
+ <h3><%= l(:label_result_plural) %> (<%= @results_by_type.values.sum %>)</h3>
<dl id="search-results">
<% @results.each do |e| %>
<dt class="<%= e.event_type %>"><%= content_tag('span', h(e.project), :class => 'project') unless @project == e.project %> <%= link_to highlight_tokens(truncate(e.event_title, 255), @tokens), e.event_url %></dt>
<dd><span class="description"><%= highlight_tokens(e.event_description, @tokens) %></span>
- <span class="author"><%= format_time(e.event_datetime) %></span><dd>
+ <span class="author"><%= format_time(e.event_datetime) %></span></dd>
<% end %>
</dl>
<% end %>
|