# HG changeset patch # User Chris Cannam # Date 1310557524 -3600 # Node ID 87bfac1079fd1aad043f5ceeea16ce7937da2c9f # Parent 1333582e34c4aacfe91cf0dba240482516e59d86 If a search matches any project titles (and projects are in scope for the search), show those projects separately at the start of the search results provided there are no more than 5 of them (further fix to bug #94) diff -r 1333582e34c4 -r 87bfac1079fd app/controllers/search_controller.rb --- a/app/controllers/search_controller.rb Tue Mar 29 11:13:50 2011 +0100 +++ b/app/controllers/search_controller.rb Wed Jul 13 12:45:24 2011 +0100 @@ -69,6 +69,7 @@ # no more than 5 tokens to search for @tokens.slice! 5..-1 if @tokens.size > 5 + @project_matches = [] @results = [] @results_by_type = Hash.new {|h,k| h[k] = 0} @@ -82,6 +83,12 @@ :before => params[:previous].nil?) @results += r @results_by_type[s] += c + if s == 'projects' + r, c = s.singularize.camelcase.constantize.search(@tokens, nil, + :all_words => @all_words, + :titles_only => 1) + @project_matches += r + end end @results = @results.sort {|a,b| b.event_datetime <=> a.event_datetime} if params[:previous].nil? diff -r 1333582e34c4 -r 87bfac1079fd app/views/search/index.rhtml --- a/app/views/search/index.rhtml Tue Mar 29 11:13:50 2011 +0100 +++ b/app/views/search/index.rhtml Wed Jul 13 12:45:24 2011 +0100 @@ -18,6 +18,16 @@ <% end %> +<% if @project_matches and !@project_matches.empty? and (@project_matches.count < 6) and !@pagination_previous_date %> +

<%= l(:label_matching_project_plural) %> (<%= @project_matches.count %>)

+
+ <% @project_matches.each do |e| %> +
<%= content_tag('span', h(e.project), :class => 'project') unless @project == e.project %> <%= link_to highlight_tokens(truncate(e.event_title, :length => 255), @tokens), e.event_url %>
+
<%= e.short_description %> + <% end %> +
+<% end %> + <% if @results %>

<%= l(:label_result_plural) %> (<%= @results_by_type.values.sum %>)

diff -r 1333582e34c4 -r 87bfac1079fd config/locales/en.yml --- a/config/locales/en.yml Tue Mar 29 11:13:50 2011 +0100 +++ b/config/locales/en.yml Wed Jul 13 12:45:24 2011 +0100 @@ -672,7 +672,8 @@ label_roadmap_overdue: "{{value}} late" label_roadmap_no_issues: No issues for this version label_search: Search - label_result_plural: Results + label_result_plural: Search results + label_matching_project_plural: Matching project names label_all_words: All words label_wiki: Wiki label_wiki_edit: Wiki edit