Commit acb9e825 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch '199220-snippet-search' into 'master'

Allow searching of snippet description

See merge request gitlab-org/gitlab!25961
parents 6c413bd8 2da54484
......@@ -307,7 +307,7 @@ class Snippet < ApplicationRecord
end
class << self
# Searches for snippets with a matching title or file name.
# Searches for snippets with a matching title, description or file name.
#
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
#
......@@ -315,7 +315,7 @@ class Snippet < ApplicationRecord
#
# Returns an ActiveRecord::Relation.
def search(query)
fuzzy_search(query, [:title, :file_name])
fuzzy_search(query, [:title, :description, :file_name])
end
# Searches for snippets with matching content.
......
---
title: Include snippet description as part of snippet title search (when Elasticsearch is not enabled)
merge_request: 25961
author:
type: added
......@@ -149,7 +149,7 @@ describe Snippet do
end
describe '.search' do
let(:snippet) { create(:snippet, title: 'test snippet') }
let(:snippet) { create(:snippet, title: 'test snippet', description: 'description') }
it 'returns snippets with a matching title' do
expect(described_class.search(snippet.title)).to eq([snippet])
......@@ -174,6 +174,10 @@ describe Snippet do
it 'returns snippets with a matching file name regardless of the casing' do
expect(described_class.search(snippet.file_name.upcase)).to eq([snippet])
end
it 'returns snippets with a matching description' do
expect(described_class.search(snippet.description)).to eq([snippet])
end
end
describe '.search_code' do
......
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