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 ...@@ -306,7 +306,7 @@ class Snippet < ApplicationRecord
end end
class << self 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. # This method uses ILIKE on PostgreSQL and LIKE on MySQL.
# #
...@@ -314,7 +314,7 @@ class Snippet < ApplicationRecord ...@@ -314,7 +314,7 @@ class Snippet < ApplicationRecord
# #
# Returns an ActiveRecord::Relation. # Returns an ActiveRecord::Relation.
def search(query) def search(query)
fuzzy_search(query, [:title, :file_name]) fuzzy_search(query, [:title, :description, :file_name])
end end
# Searches for snippets with matching content. # 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 ...@@ -149,7 +149,7 @@ describe Snippet do
end end
describe '.search' do 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 it 'returns snippets with a matching title' do
expect(described_class.search(snippet.title)).to eq([snippet]) expect(described_class.search(snippet.title)).to eq([snippet])
...@@ -174,6 +174,10 @@ describe Snippet do ...@@ -174,6 +174,10 @@ describe Snippet do
it 'returns snippets with a matching file name regardless of the casing' 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]) expect(described_class.search(snippet.file_name.upcase)).to eq([snippet])
end end
it 'returns snippets with a matching description' do
expect(described_class.search(snippet.description)).to eq([snippet])
end
end end
describe '.search_code' do 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