Mercurial > hg > soundsoftware-site
changeset 498:87bfac1079fd bug_94
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)
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Wed, 13 Jul 2011 12:45:24 +0100 |
parents | 1333582e34c4 |
children | 85fd403a7daa be557d78a11b |
files | app/controllers/search_controller.rb app/views/search/index.rhtml config/locales/en.yml |
diffstat | 3 files changed, 19 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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?
--- 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 %> </div> +<% if @project_matches and !@project_matches.empty? and (@project_matches.count < 6) and !@pagination_previous_date %> + <h3><%= l(:label_matching_project_plural) %> (<%= @project_matches.count %>)</h3> + <dl id="search-results"> + <% @project_matches.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, :length => 255), @tokens), e.event_url %></dt> + <dd><span class="description"><%= e.short_description %></span> + <% end %> + </dl> +<% end %> + <% if @results %> <h3><%= l(:label_result_plural) %> (<%= @results_by_type.values.sum %>)</h3>
--- 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