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
b2c5363d
Commit
b2c5363d
authored
Nov 24, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename to_fuzzy_arel to fuzzy_arel_match
parent
aedd2cfa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
10 deletions
+10
-10
app/models/concerns/issuable.rb
app/models/concerns/issuable.rb
+3
-3
lib/gitlab/sql/pattern.rb
lib/gitlab/sql/pattern.rb
+1
-1
spec/lib/gitlab/sql/pattern_spec.rb
spec/lib/gitlab/sql/pattern_spec.rb
+6
-6
No files found.
app/models/concerns/issuable.rb
View file @
b2c5363d
...
...
@@ -122,7 +122,7 @@ module Issuable
#
# Returns an ActiveRecord::Relation.
def
search
(
query
)
title
=
to_fuzzy_arel
(
:title
,
query
)
title
=
fuzzy_arel_match
(
:title
,
query
)
where
(
title
)
end
...
...
@@ -135,8 +135,8 @@ module Issuable
#
# Returns an ActiveRecord::Relation.
def
full_search
(
query
)
title
=
to_fuzzy_arel
(
:title
,
query
)
description
=
to_fuzzy_arel
(
:description
,
query
)
title
=
fuzzy_arel_match
(
:title
,
query
)
description
=
fuzzy_arel_match
(
:description
,
query
)
where
(
title
&
.
or
(
description
))
end
...
...
lib/gitlab/sql/pattern.rb
View file @
b2c5363d
...
...
@@ -19,7 +19,7 @@ module Gitlab
query
.
length
>=
MIN_CHARS_FOR_PARTIAL_MATCHING
end
def
to_fuzzy_arel
(
column
,
query
)
def
fuzzy_arel_match
(
column
,
query
)
words
=
select_fuzzy_words
(
query
)
matches
=
words
.
map
{
|
word
|
arel_table
[
column
].
matches
(
to_pattern
(
word
))
}
...
...
spec/lib/gitlab/sql/pattern_spec.rb
View file @
b2c5363d
...
...
@@ -137,14 +137,14 @@ describe Gitlab::SQL::Pattern do
end
end
describe
'.
to_fuzzy_arel
'
do
subject
(
:
to_fuzzy_arel
)
{
Issue
.
to_fuzzy_arel
(
:title
,
query
)
}
describe
'.
fuzzy_arel_match
'
do
subject
(
:
fuzzy_arel_match
)
{
Issue
.
fuzzy_arel_match
(
:title
,
query
)
}
context
'with a word equal to 3 chars'
do
let
(
:query
)
{
'foo'
}
it
'returns a single ILIKE condition'
do
expect
(
to_fuzzy_arel
.
to_sql
).
to
match
(
/title.*I?LIKE '\%foo\%'/
)
expect
(
fuzzy_arel_match
.
to_sql
).
to
match
(
/title.*I?LIKE '\%foo\%'/
)
end
end
...
...
@@ -152,7 +152,7 @@ describe Gitlab::SQL::Pattern do
let
(
:query
)
{
'fo'
}
it
'returns nil'
do
expect
(
to_fuzzy_arel
).
to
be_nil
expect
(
fuzzy_arel_match
).
to
be_nil
end
end
...
...
@@ -160,7 +160,7 @@ describe Gitlab::SQL::Pattern do
let
(
:query
)
{
'foo baz'
}
it
'returns a joining LIKE condition using a AND'
do
expect
(
to_fuzzy_arel
.
to_sql
).
to
match
(
/title.+I?LIKE '\%foo\%' AND .*title.*I?LIKE '\%baz\%'/
)
expect
(
fuzzy_arel_match
.
to_sql
).
to
match
(
/title.+I?LIKE '\%foo\%' AND .*title.*I?LIKE '\%baz\%'/
)
end
end
...
...
@@ -168,7 +168,7 @@ describe Gitlab::SQL::Pattern do
let
(
:query
)
{
'foo "really bar" baz'
}
it
'returns a joining LIKE condition using a AND'
do
expect
(
to_fuzzy_arel
.
to_sql
).
to
match
(
/title.+I?LIKE '\%foo\%' AND .*title.*I?LIKE '\%baz\%' AND .*title.*I?LIKE '\%really bar\%'/
)
expect
(
fuzzy_arel_match
.
to_sql
).
to
match
(
/title.+I?LIKE '\%foo\%' AND .*title.*I?LIKE '\%baz\%' AND .*title.*I?LIKE '\%really bar\%'/
)
end
end
end
...
...
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