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
847b0b60
Commit
847b0b60
authored
Sep 14, 2020
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a FF for ES default_operator change
parent
3630fe77
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
14 deletions
+78
-14
ee/config/feature_flags/development/elasticsearch_use_or_default_operator.yml
...ags/development/elasticsearch_use_or_default_operator.yml
+7
-0
ee/lib/elastic/latest/application_class_proxy.rb
ee/lib/elastic/latest/application_class_proxy.rb
+7
-1
ee/spec/models/concerns/elastic/project_spec.rb
ee/spec/models/concerns/elastic/project_spec.rb
+62
-11
ee/spec/services/search/group_service_spec.rb
ee/spec/services/search/group_service_spec.rb
+2
-2
No files found.
ee/config/feature_flags/development/elasticsearch_use_or_default_operator.yml
0 → 100644
View file @
847b0b60
---
name
:
elasticsearch_use_or_default_operator
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41664
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/246500
group
:
group::global search
type
:
development
default_enabled
:
false
ee/lib/elastic/latest/application_class_proxy.rb
View file @
847b0b60
...
@@ -33,6 +33,12 @@ module Elastic
...
@@ -33,6 +33,12 @@ module Elastic
private
private
def
default_operator
return
:or
if
Feature
.
enabled?
(
:elasticsearch_use_or_default_operator
)
:and
end
def
highlight_options
(
fields
)
def
highlight_options
(
fields
)
es_fields
=
fields
.
map
{
|
field
|
field
.
split
(
'^'
).
first
}.
each_with_object
({})
do
|
field
,
memo
|
es_fields
=
fields
.
map
{
|
field
|
field
.
split
(
'^'
).
first
}.
each_with_object
({})
do
|
field
,
memo
|
memo
[
field
.
to_sym
]
=
{}
memo
[
field
.
to_sym
]
=
{}
...
@@ -51,7 +57,7 @@ module Elastic
...
@@ -51,7 +57,7 @@ module Elastic
simple_query_string:
{
simple_query_string:
{
fields:
fields
,
fields:
fields
,
query:
query
,
query:
query
,
default_operator:
:and
default_operator:
default_operator
}
}
}],
}],
filter:
[{
filter:
[{
...
...
ee/spec/models/concerns/elastic/project_spec.rb
View file @
847b0b60
...
@@ -8,7 +8,7 @@ RSpec.describe Project, :elastic do
...
@@ -8,7 +8,7 @@ RSpec.describe Project, :elastic do
end
end
context
'when limited indexing is on'
do
context
'when limited indexing is on'
do
let_it_be
(
:project
)
{
create
:project
,
name:
'
test1
'
}
let_it_be
(
:project
)
{
create
:project
,
name:
'
main_project
'
}
before
do
before
do
stub_ee_application_setting
(
elasticsearch_limit_indexing:
true
)
stub_ee_application_setting
(
elasticsearch_limit_indexing:
true
)
...
@@ -47,14 +47,14 @@ RSpec.describe Project, :elastic do
...
@@ -47,14 +47,14 @@ RSpec.describe Project, :elastic do
it
'only indexes enabled projects'
do
it
'only indexes enabled projects'
do
Sidekiq
::
Testing
.
inline!
do
Sidekiq
::
Testing
.
inline!
do
create
:project
,
path:
'test
2
'
,
description:
'awesome project'
create
:project
,
path:
'test
_two
'
,
description:
'awesome project'
create
:project
create
:project
ensure_elasticsearch_index!
ensure_elasticsearch_index!
end
end
expect
(
described_class
.
elastic_search
(
'
test
*'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'
main_pro
*'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'test
2
'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
0
)
expect
(
described_class
.
elastic_search
(
'test
_two
'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
0
)
end
end
end
end
...
@@ -84,9 +84,60 @@ RSpec.describe Project, :elastic do
...
@@ -84,9 +84,60 @@ RSpec.describe Project, :elastic do
end
end
expect
(
described_class
.
elastic_search
(
'group_test*'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
2
)
expect
(
described_class
.
elastic_search
(
'group_test*'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
2
)
expect
(
described_class
.
elastic_search
(
'group_test3'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'"group_test3"'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'group_test2'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
0
)
expect
(
described_class
.
elastic_search
(
'"group_test2"'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
0
)
expect
(
described_class
.
elastic_search
(
'group_test4'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
0
)
expect
(
described_class
.
elastic_search
(
'"group_test4"'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
0
)
end
context
'default_operator'
do
RSpec
.
shared_examples
'use correct default_operator'
do
|
operator
|
before
do
Sidekiq
::
Testing
.
inline!
do
create
:project
,
name:
'project1'
,
group:
group
,
description:
'test foo'
create
:project
,
name:
'project2'
,
group:
group
,
description:
'test'
create
:project
,
name:
'project3'
,
group:
group
,
description:
'foo'
ensure_elasticsearch_index!
end
end
it
'uses correct operator'
do
count_for_or
=
described_class
.
elastic_search
(
'test | foo'
,
options:
{
project_ids: :any
}).
total_count
expect
(
count_for_or
).
to
be
>
0
count_for_and
=
described_class
.
elastic_search
(
'test + foo'
,
options:
{
project_ids: :any
}).
total_count
expect
(
count_for_and
).
to
be
>
0
expect
(
count_for_or
).
not_to
be
equal
(
count_for_and
)
expected_count
=
case
operator
when
:or
count_for_or
when
:and
count_for_and
else
raise
ArgumentError
,
'Invalid operator'
end
expect
(
described_class
.
elastic_search
(
'test foo'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
expected_count
)
end
end
context
'feature flag is enabled'
do
before
do
stub_feature_flags
(
elasticsearch_use_or_default_operator:
true
)
end
include_examples
'use correct default_operator'
,
:or
end
context
'feature flag is disabled'
do
before
do
stub_feature_flags
(
elasticsearch_use_or_default_operator:
false
)
end
include_examples
'use correct default_operator'
,
:and
end
end
end
end
end
end
end
...
@@ -125,12 +176,12 @@ RSpec.describe Project, :elastic do
...
@@ -125,12 +176,12 @@ RSpec.describe Project, :elastic do
ensure_elasticsearch_index!
ensure_elasticsearch_index!
end
end
expect
(
described_class
.
elastic_search
(
'
test1
'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'
"test1"
'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'
test2
'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'
"test2"
'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'
awesome
'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'
"awesome"
'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
1
)
expect
(
described_class
.
elastic_search
(
'test*'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
2
)
expect
(
described_class
.
elastic_search
(
'test*'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
2
)
expect
(
described_class
.
elastic_search
(
'test*'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
3
)
expect
(
described_class
.
elastic_search
(
'test*'
,
options:
{
project_ids: :any
}).
total_count
).
to
eq
(
3
)
expect
(
described_class
.
elastic_search
(
'
someone_elses_project
'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
0
)
expect
(
described_class
.
elastic_search
(
'
"someone_elses_project"
'
,
options:
{
project_ids:
project_ids
}).
total_count
).
to
eq
(
0
)
end
end
it
"finds partial matches in project names"
do
it
"finds partial matches in project names"
do
...
...
ee/spec/services/search/group_service_spec.rb
View file @
847b0b60
...
@@ -20,13 +20,13 @@ RSpec.describe Search::GroupService, :elastic do
...
@@ -20,13 +20,13 @@ RSpec.describe Search::GroupService, :elastic do
end
end
describe
'group search'
do
describe
'group search'
do
let
(
:term
)
{
"
Project
Name"
}
let
(
:term
)
{
"
Random
Name"
}
let
(
:nested_group
)
{
create
(
:group
,
:nested
)
}
let
(
:nested_group
)
{
create
(
:group
,
:nested
)
}
# These projects shouldn't be found
# These projects shouldn't be found
let
(
:outside_project
)
{
create
(
:project
,
:public
,
name:
"Outside
#{
term
}
"
)
}
let
(
:outside_project
)
{
create
(
:project
,
:public
,
name:
"Outside
#{
term
}
"
)
}
let
(
:private_project
)
{
create
(
:project
,
:private
,
namespace:
nested_group
,
name:
"Private
#{
term
}
"
)}
let
(
:private_project
)
{
create
(
:project
,
:private
,
namespace:
nested_group
,
name:
"Private
#{
term
}
"
)}
let
(
:other_project
)
{
create
(
:project
,
:public
,
namespace:
nested_group
,
name:
term
.
reverse
)
}
let
(
:other_project
)
{
create
(
:project
,
:public
,
namespace:
nested_group
,
name:
'OtherProject'
)
}
# These projects should be found
# These projects should be found
let
(
:project1
)
{
create
(
:project
,
:internal
,
namespace:
nested_group
,
name:
"Inner
#{
term
}
1"
)
}
let
(
:project1
)
{
create
(
:project
,
:internal
,
namespace:
nested_group
,
name:
"Inner
#{
term
}
1"
)
}
...
...
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