Skip to content
Snippets Groups Projects
Verified Commit 8b00d01c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Search by issue/mr title and description

parent 7e59a8fe
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -20,7 +20,7 @@ class Projects::IssuesController < Projects::ApplicationController
terms = params['issue_search']
 
@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)
 
assignee_id, milestone_id = params[:assignee_id], params[:milestone_id]
Loading
Loading
Loading
Loading
@@ -49,6 +49,10 @@ module Issuable
where("LOWER(title) like :query", query: "%#{query.downcase}%")
end
 
def full_search(query)
where("LOWER(title) like :query OR LOWER(description) like :query", query: "%#{query.downcase}%")
end
def sort(method)
case method.to_s
when 'newest' then reorder("#{table_name}.created_at DESC")
Loading
Loading
Loading
Loading
@@ -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")
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}%")
end
 
def search_by_title query
def search_by_title(query)
where("projects.archived = ?", false).where("LOWER(projects.name) LIKE :query", query: "%#{query.downcase}%")
end
 
Loading
Loading
Loading
Loading
@@ -3,6 +3,9 @@
= link_to [issue.project, issue] do
%span.term.str-truncated= issue.title
.pull-right ##{issue.iid}
.description.term
= preserve do
= search_md_sanitize(markdown(issue.description))
%span.light
#{issue.project.name_with_namespace}
- if issue.closed?
Loading
Loading
Loading
Loading
@@ -3,6 +3,9 @@
= link_to [merge_request.target_project, merge_request] do
%span.term.str-truncated= merge_request.title
.pull-right ##{merge_request.iid}
.description.term
= preserve do
= search_md_sanitize(markdown(merge_request.description))
%span.light
#{merge_request.project.name_with_namespace}
.pull-right
Loading
Loading
Loading
Loading
@@ -51,11 +51,11 @@ module Gitlab
end
 
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
 
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
 
def default_scope
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment