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
df4eb7db
Commit
df4eb7db
authored
Nov 23, 2019
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable searching of projects by full path
This affects projects search and dropdowns across GitLab
parent
5e913ddd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
6 deletions
+60
-6
app/models/project.rb
app/models/project.rb
+5
-1
changelogs/unreleased/hly-search-by-project-full-path.yml
changelogs/unreleased/hly-search-by-project-full-path.yml
+5
-0
lib/gitlab/sql/pattern.rb
lib/gitlab/sql/pattern.rb
+6
-4
spec/lib/gitlab/sql/pattern_spec.rb
spec/lib/gitlab/sql/pattern_spec.rb
+10
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+34
-1
No files found.
app/models/project.rb
View file @
df4eb7db
...
...
@@ -542,7 +542,11 @@ class Project < ApplicationRecord
#
# query - The search query as a String.
def
search
(
query
)
fuzzy_search
(
query
,
[
:path
,
:name
,
:description
])
if
Feature
.
enabled?
(
:project_search_by_full_path
,
default_enabled:
true
)
joins
(
:route
).
fuzzy_search
(
query
,
[
Route
.
arel_table
[
:path
],
:name
,
:description
])
else
fuzzy_search
(
query
,
[
:path
,
:name
,
:description
])
end
end
def
search_by_title
(
query
)
...
...
changelogs/unreleased/hly-search-by-project-full-path.yml
0 → 100644
View file @
df4eb7db
---
title
:
Allow searching of projects by full path
merge_request
:
20659
author
:
type
:
added
lib/gitlab/sql/pattern.rb
View file @
df4eb7db
...
...
@@ -35,7 +35,7 @@ module Gitlab
query
.
length
>=
min_chars_for_partial_matching
end
# column - The column name to search in.
# column - The column name
/ Arel column
to search in.
# query - The text to search for.
# lower_exact_match - When set to `true` we'll fall back to using
# `LOWER(column) = query` instead of using `ILIKE`.
...
...
@@ -43,19 +43,21 @@ module Gitlab
query
=
query
.
squish
return
unless
query
.
present?
arel_column
=
column
.
is_a?
(
Arel
::
Attributes
::
Attribute
)
?
column
:
arel_table
[
column
]
words
=
select_fuzzy_words
(
query
,
use_minimum_char_limit:
use_minimum_char_limit
)
if
words
.
any?
words
.
map
{
|
word
|
arel_
table
[
column
]
.
matches
(
to_pattern
(
word
,
use_minimum_char_limit:
use_minimum_char_limit
))
}.
reduce
(
:and
)
words
.
map
{
|
word
|
arel_
column
.
matches
(
to_pattern
(
word
,
use_minimum_char_limit:
use_minimum_char_limit
))
}.
reduce
(
:and
)
else
# No words of at least 3 chars, but we can search for an exact
# case insensitive match with the query as a whole
if
lower_exact_match
Arel
::
Nodes
::
NamedFunction
.
new
(
'LOWER'
,
[
arel_
table
[
column
]
])
.
new
(
'LOWER'
,
[
arel_
column
])
.
eq
(
query
)
else
arel_
table
[
column
]
.
matches
(
sanitize_sql_like
(
query
))
arel_
column
.
matches
(
sanitize_sql_like
(
query
))
end
end
end
...
...
spec/lib/gitlab/sql/pattern_spec.rb
View file @
df4eb7db
...
...
@@ -207,5 +207,15 @@ describe Gitlab::SQL::Pattern do
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
context
'when passing an Arel column'
do
let
(
:query
)
{
'foo'
}
subject
(
:fuzzy_arel_match
)
{
Project
.
fuzzy_arel_match
(
Route
.
arel_table
[
:path
],
query
)
}
it
'returns a condition with the table and column name'
do
expect
(
fuzzy_arel_match
.
to_sql
).
to
match
(
/"routes"."path".*ILIKE '\%foo\%'/
)
end
end
end
end
spec/models/project_spec.rb
View file @
df4eb7db
...
...
@@ -1661,7 +1661,7 @@ describe Project do
end
describe
'.search'
do
let
(
:project
)
{
create
(
:project
,
description:
'kitten mittens'
)
}
let
_it_be
(
:project
)
{
create
(
:project
,
description:
'kitten mittens'
)
}
it
'returns projects with a matching name'
do
expect
(
described_class
.
search
(
project
.
name
)).
to
eq
([
project
])
...
...
@@ -1699,6 +1699,39 @@ describe Project do
expect
(
described_class
.
search
(
project
.
path
.
upcase
)).
to
eq
([
project
])
end
context
'by full path'
do
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:project
)
{
create
(
:project
,
group:
group
)
}
context
'when feature is enabled'
do
before
do
stub_feature_flags
(
project_search_by_full_path:
true
)
end
it
'returns projects that match the group path'
do
expect
(
described_class
.
search
(
group
.
path
)).
to
eq
([
project
])
end
it
'returns projects that match the full path'
do
expect
(
described_class
.
search
(
project
.
full_path
)).
to
eq
([
project
])
end
end
context
'when feature is disabled'
do
before
do
stub_feature_flags
(
project_search_by_full_path:
false
)
end
it
'returns no results when searching by group path'
do
expect
(
described_class
.
search
(
group
.
path
)).
to
be_empty
end
it
'returns no results when searching by full path'
do
expect
(
described_class
.
search
(
project
.
full_path
)).
to
be_empty
end
end
end
describe
'with pending_delete project'
do
let
(
:pending_delete_project
)
{
create
(
:project
,
pending_delete:
true
)
}
...
...
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