Commit 2da54484 authored by Mark Chao's avatar Mark Chao

Allow searching on snippet description

Only covers basic search
parent b7fa9dc4
......@@ -306,7 +306,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.
#
......@@ -314,7 +314,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