Commit 8b00d01c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Search by issue/mr title and description

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 7e59a8fe
...@@ -20,7 +20,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -20,7 +20,7 @@ class Projects::IssuesController < Projects::ApplicationController
terms = params['issue_search'] terms = params['issue_search']
@issues = issues_filtered @issues = issues_filtered
@issues = @issues.where("title LIKE ? OR description LIKE ?", "%#{terms}%", "%#{terms}%") if terms.present? @issues = @issues.full_search(terms) if terms.present?
@issues = @issues.page(params[:page]).per(20) @issues = @issues.page(params[:page]).per(20)
assignee_id, milestone_id = params[:assignee_id], params[:milestone_id] assignee_id, milestone_id = params[:assignee_id], params[:milestone_id]
......
...@@ -49,6 +49,10 @@ module Issuable ...@@ -49,6 +49,10 @@ module Issuable
where("LOWER(title) like :query", query: "%#{query.downcase}%") where("LOWER(title) like :query", query: "%#{query.downcase}%")
end end
def full_search(query)
where("LOWER(title) like :query OR LOWER(description) like :query", query: "%#{query.downcase}%")
end
def sort(method) def sort(method)
case method.to_s case method.to_s
when 'newest' then reorder("#{table_name}.created_at DESC") when 'newest' then reorder("#{table_name}.created_at DESC")
......
...@@ -177,11 +177,11 @@ class Project < ActiveRecord::Base ...@@ -177,11 +177,11 @@ class Project < ActiveRecord::Base
joins(:issues, :notes, :merge_requests).order("issues.created_at, notes.created_at, merge_requests.created_at DESC") joins(:issues, :notes, :merge_requests).order("issues.created_at, notes.created_at, merge_requests.created_at DESC")
end end
def search query def search(query)
joins(:namespace).where("projects.archived = ?", false).where("projects.name LIKE :query OR projects.path LIKE :query OR namespaces.name LIKE :query OR projects.description LIKE :query", query: "%#{query}%") joins(:namespace).where("projects.archived = ?", false).where("projects.name LIKE :query OR projects.path LIKE :query OR namespaces.name LIKE :query OR projects.description LIKE :query", query: "%#{query}%")
end end
def search_by_title query def search_by_title(query)
where("projects.archived = ?", false).where("LOWER(projects.name) LIKE :query", query: "%#{query.downcase}%") where("projects.archived = ?", false).where("LOWER(projects.name) LIKE :query", query: "%#{query.downcase}%")
end end
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
= link_to [issue.project, issue] do = link_to [issue.project, issue] do
%span.term.str-truncated= issue.title %span.term.str-truncated= issue.title
.pull-right ##{issue.iid} .pull-right ##{issue.iid}
.description.term
= preserve do
= search_md_sanitize(markdown(issue.description))
%span.light %span.light
#{issue.project.name_with_namespace} #{issue.project.name_with_namespace}
- if issue.closed? - if issue.closed?
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
= link_to [merge_request.target_project, merge_request] do = link_to [merge_request.target_project, merge_request] do
%span.term.str-truncated= merge_request.title %span.term.str-truncated= merge_request.title
.pull-right ##{merge_request.iid} .pull-right ##{merge_request.iid}
.description.term
= preserve do
= search_md_sanitize(markdown(merge_request.description))
%span.light %span.light
#{merge_request.project.name_with_namespace} #{merge_request.project.name_with_namespace}
.pull-right .pull-right
......
...@@ -51,11 +51,11 @@ module Gitlab ...@@ -51,11 +51,11 @@ module Gitlab
end end
def issues def issues
Issue.where(project_id: limit_project_ids).search(query).order('updated_at DESC') Issue.where(project_id: limit_project_ids).full_search(query).order('updated_at DESC')
end end
def merge_requests def merge_requests
MergeRequest.in_projects(limit_project_ids).search(query).order('updated_at DESC') MergeRequest.in_projects(limit_project_ids).full_search(query).order('updated_at DESC')
end end
def default_scope def default_scope
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment