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
0
Merge Requests
0
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
Kazuhiko Shiozaki
gitlab-ce
Commits
87e7c3e1
Commit
87e7c3e1
authored
Mar 01, 2016
by
Yorick Peterse
Committed by
Robert Speicher
Mar 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ILIKE/LIKE for Issuable.search and full_search
parent
2076bdb6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
3 deletions
+65
-3
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+19
-2
spec/models/concerns/issuable_spec.rb
spec/models/concerns/issuable_spec.rb
+46
-1
No files found.
app/models/concerns/issuable.rb
View file @
87e7c3e1
...
@@ -61,12 +61,29 @@ module Issuable
...
@@ -61,12 +61,29 @@ module Issuable
end
end
module
ClassMethods
module
ClassMethods
# Searches for records with a matching title.
#
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
#
# query - The search query as a String
#
# Returns an ActiveRecord::Relation.
def
search
(
query
)
def
search
(
query
)
where
(
"LOWER(title) like :query"
,
query:
"%
#{
query
.
downcase
}
%"
)
where
(
arel_table
[
:title
].
matches
(
"%
#{
query
}
%"
)
)
end
end
# Searches for records with a matching title or description.
#
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
#
# query - The search query as a String
#
# Returns an ActiveRecord::Relation.
def
full_search
(
query
)
def
full_search
(
query
)
where
(
"LOWER(title) like :query OR LOWER(description) like :query"
,
query:
"%
#{
query
.
downcase
}
%"
)
t
=
arel_table
pattern
=
"%
#{
query
}
%"
where
(
t
[
:title
].
matches
(
pattern
).
or
(
t
[
:description
].
matches
(
pattern
)))
end
end
def
sort
(
method
)
def
sort
(
method
)
...
...
spec/models/concerns/issuable_spec.rb
View file @
87e7c3e1
...
@@ -32,9 +32,54 @@ describe Issue, "Issuable" do
...
@@ -32,9 +32,54 @@ describe Issue, "Issuable" do
describe
".search"
do
describe
".search"
do
let!
(
:searchable_issue
)
{
create
(
:issue
,
title:
"Searchable issue"
)
}
let!
(
:searchable_issue
)
{
create
(
:issue
,
title:
"Searchable issue"
)
}
it
"matches by title"
do
it
'returns notches with a matching title'
do
expect
(
described_class
.
search
(
searchable_issue
.
title
)).
to
eq
([
searchable_issue
])
end
it
'returns notes with a partially matching title'
do
expect
(
described_class
.
search
(
'able'
)).
to
eq
([
searchable_issue
])
expect
(
described_class
.
search
(
'able'
)).
to
eq
([
searchable_issue
])
end
end
it
'returns notes with a matching title regardless of the casing'
do
expect
(
described_class
.
search
(
searchable_issue
.
title
.
upcase
)).
to
eq
([
searchable_issue
])
end
end
describe
".full_search"
do
let!
(
:searchable_issue
)
do
create
(
:issue
,
title:
"Searchable issue"
,
description:
'kittens'
)
end
it
'returns notches with a matching title'
do
expect
(
described_class
.
full_search
(
searchable_issue
.
title
)).
to
eq
([
searchable_issue
])
end
it
'returns notes with a partially matching title'
do
expect
(
described_class
.
full_search
(
'able'
)).
to
eq
([
searchable_issue
])
end
it
'returns notes with a matching title regardless of the casing'
do
expect
(
described_class
.
full_search
(
searchable_issue
.
title
.
upcase
)).
to
eq
([
searchable_issue
])
end
it
'returns notches with a matching description'
do
expect
(
described_class
.
full_search
(
searchable_issue
.
description
)).
to
eq
([
searchable_issue
])
end
it
'returns notes with a partially matching description'
do
expect
(
described_class
.
full_search
(
searchable_issue
.
description
)).
to
eq
([
searchable_issue
])
end
it
'returns notes with a matching description regardless of the casing'
do
expect
(
described_class
.
full_search
(
searchable_issue
.
description
.
upcase
)).
to
eq
([
searchable_issue
])
end
end
end
describe
"#today?"
do
describe
"#today?"
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