Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2da54484
Commit
2da54484
authored
Feb 27, 2020
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow searching on snippet description
Only covers basic search
parent
b7fa9dc4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
3 deletions
+12
-3
app/models/snippet.rb
app/models/snippet.rb
+2
-2
changelogs/unreleased/199220-snippet-search.yml
changelogs/unreleased/199220-snippet-search.yml
+5
-0
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+5
-1
No files found.
app/models/snippet.rb
View file @
2da54484
...
@@ -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.
...
...
changelogs/unreleased/199220-snippet-search.yml
0 → 100644
View file @
2da54484
---
title
:
Include snippet description as part of snippet title search (when Elasticsearch is not enabled)
merge_request
:
25961
author
:
type
:
added
spec/models/snippet_spec.rb
View file @
2da54484
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment