From d419a59c5e8f8f1c6a444cb030292e724241703f Mon Sep 17 00:00:00 2001 From: Henri Colas Date: Mon, 4 Nov 2013 14:21:05 +0100 Subject: [PATCH 1/2] Add ability to search in issue description and issue comments * edit queries in serach context * edit template for result --- app/contexts/search_context.rb | 4 +++- app/controllers/search_controller.rb | 1 + app/views/search/_result.html.haml | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/contexts/search_context.rb b/app/contexts/search_context.rb index 2f9438f6bb..fa41da6823 100644 --- a/app/contexts/search_context.rb +++ b/app/contexts/search_context.rb @@ -24,7 +24,8 @@ class SearchContext result[:blobs] = project.repository.search_files(query, params[:repository_ref]) unless project.empty_repo? else result[:merge_requests] = MergeRequest.in_projects(project_ids).search(query).order('updated_at DESC').limit(20) - result[:issues] = Issue.where(project_id: project_ids).search(query).order('updated_at DESC').limit(20) + result[:issues] = Issue.where(project_id: project_ids).where("title like :query OR description like :query ", query: "%#{query}%").order('updated_at DESC').limit(20) + result[:notes] = Note.where(noteable_type: 'issue').where(project_id: project_ids).where("note like :query", query: "%#{query}%").order('updated_at DESC').limit(20) result[:wiki_pages] = [] end end @@ -34,6 +35,7 @@ class SearchContext projects: [], merge_requests: [], issues: [], + notes: [], wiki_pages: [], blobs: [] } diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index f5c3bb133e..6eaa976f75 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -19,6 +19,7 @@ class SearchController < ApplicationController @projects = result[:projects] @merge_requests = result[:merge_requests] @issues = result[:issues] + @notes = result[:notes] @wiki_pages = result[:wiki_pages] @blobs = Kaminari.paginate_array(result[:blobs]).page(params[:page]).per(20) @total_results = @projects.count + @merge_requests.count + @issues.count + @wiki_pages.count + @blobs.total_count diff --git a/app/views/search/_result.html.haml b/app/views/search/_result.html.haml index 5f7540d1b1..a55ac1a759 100644 --- a/app/views/search/_result.html.haml +++ b/app/views/search/_result.html.haml @@ -44,6 +44,17 @@ - if issue.closed? %span.label Closed + - @notes.each do |note| + %li + note on issue: + = link_to [note.project, note.noteable] do + %span ##{note.noteable.iid} + %strong.term + = truncate note.noteable.title, length: 50 + %span.light (#{note.project.name_with_namespace}) + - if note.noteable.closed? + %span.label Closed + - @wiki_pages.each do |wiki_page| %li wiki: From 15e0ab498dc9f680dc6995c46a8ba7b76fc1f081 Mon Sep 17 00:00:00 2001 From: NotSqrt Date: Thu, 15 May 2014 19:54:19 +0200 Subject: [PATCH 2/2] Update ability to search in issue descriptions and comments --- app/services/search/global_service.rb | 1 + app/services/search/project_service.rb | 6 ++++-- app/views/search/_project_results.html.haml | 1 + app/views/search/results/_note.html.haml | 9 +++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 app/views/search/results/_note.html.haml diff --git a/app/services/search/global_service.rb b/app/services/search/global_service.rb index 8a1fce17ce..d4fb3598bf 100644 --- a/app/services/search/global_service.rb +++ b/app/services/search/global_service.rb @@ -28,6 +28,7 @@ module Search projects: [], merge_requests: [], issues: [], + notes: [], total_results: 0, } end diff --git a/app/services/search/project_service.rb b/app/services/search/project_service.rb index 3ebaafc752..493dee95f9 100644 --- a/app/services/search/project_service.rb +++ b/app/services/search/project_service.rb @@ -18,8 +18,9 @@ module Search result[:total_results] = blobs.total_count else result[:merge_requests] = project.merge_requests.search(query).order('updated_at DESC').limit(20) - result[:issues] = project.issues.search(query).order('updated_at DESC').limit(20) - result[:total_results] = %w(issues merge_requests).sum { |items| result[items.to_sym].size } + result[:issues] = project.issues.where("title like :query OR description like :query ", query: "%#{query}%").order('updated_at DESC').limit(20) + result[:notes] = Note.where(noteable_type: 'issue').where(project_id: project.id).where("note like :query", query: "%#{query}%").order('updated_at DESC').limit(20) + result[:total_results] = %w(issues merge_requests notes).sum { |items| result[items.to_sym].size } end result @@ -30,6 +31,7 @@ module Search merge_requests: [], issues: [], blobs: [], + notes: [], total_results: 0, } end diff --git a/app/views/search/_project_results.html.haml b/app/views/search/_project_results.html.haml index f285bda573..af3b97879c 100644 --- a/app/views/search/_project_results.html.haml +++ b/app/views/search/_project_results.html.haml @@ -15,3 +15,4 @@ %ul.bordered-list = render partial: "search/results/merge_request", collection: @search_results[:merge_requests] = render partial: "search/results/issue", collection: @search_results[:issues] + = render partial: "search/results/note", collection: @search_results[:notes] diff --git a/app/views/search/results/_note.html.haml b/app/views/search/results/_note.html.haml new file mode 100644 index 0000000000..97e892bdd4 --- /dev/null +++ b/app/views/search/results/_note.html.haml @@ -0,0 +1,9 @@ +%li + note on issue: + = link_to [note.project, note.noteable] do + %span ##{note.noteable.iid} + %strong.term + = truncate note.noteable.title, length: 50 + %span.light (#{note.project.name_with_namespace}) + - if note.noteable.closed? + %span.label Closed