From 17395433ad453f4af56fad700884bf2f2e66a789 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Thu, 30 Jul 2020 11:38:57 -0400 Subject: [PATCH 01/14] Enable Advanced Search for global scope searches --- ee/app/models/ee/application_setting.rb | 2 +- ...arches-for-public-groups-bronze-and-above-to-advanced.yml | 5 +++++ ee/spec/models/application_setting_spec.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 ee/changelogs/unreleased/197231-default-searches-for-public-groups-bronze-and-above-to-advanced.yml diff --git a/ee/app/models/ee/application_setting.rb b/ee/app/models/ee/application_setting.rb index 7a86933313d819..6b539a14045d76 100644 --- a/ee/app/models/ee/application_setting.rb +++ b/ee/app/models/ee/application_setting.rb @@ -238,7 +238,7 @@ def search_using_elasticsearch?(scope: nil) when Project elasticsearch_indexes_project?(scope) else - false # Never use elasticsearch for the global scope when limiting is on + true # Use elasticsearch for the global scope, even when limiting is on end end diff --git a/ee/changelogs/unreleased/197231-default-searches-for-public-groups-bronze-and-above-to-advanced.yml b/ee/changelogs/unreleased/197231-default-searches-for-public-groups-bronze-and-above-to-advanced.yml new file mode 100644 index 00000000000000..d5dd38d742497e --- /dev/null +++ b/ee/changelogs/unreleased/197231-default-searches-for-public-groups-bronze-and-above-to-advanced.yml @@ -0,0 +1,5 @@ +--- +title: Enable Advanced Search for global scope searches +merge_request: 38093 +author: +type: changed diff --git a/ee/spec/models/application_setting_spec.rb b/ee/spec/models/application_setting_spec.rb index 7d109fd96b511f..190035cde06007 100644 --- a/ee/spec/models/application_setting_spec.rb +++ b/ee/spec/models/application_setting_spec.rb @@ -434,7 +434,7 @@ def expect_is_es_licensed context 'global scope' do let(:scope) { nil } - it { is_expected.to eq(only_when_enabled_globally) } + it { is_expected.to eq(indexing && searching) } end context 'namespace (in scope)' do -- GitLab From b1dc9eefc3fb91ffc58b1fd5a950ca469d0ba339 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Thu, 30 Jul 2020 15:21:50 -0400 Subject: [PATCH 02/14] fixup! Enable Advanced Search for global scope searches --- doc/integration/elasticsearch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/integration/elasticsearch.md b/doc/integration/elasticsearch.md index 551b372d3d930f..dd890137a710e7 100644 --- a/doc/integration/elasticsearch.md +++ b/doc/integration/elasticsearch.md @@ -168,7 +168,7 @@ If you select `Limit namespaces and projects that can be indexed`, more options You can select namespaces and projects to index exclusively. Please note that if the namespace is a group it will include any sub-groups and projects belonging to those sub-groups to be indexed as well. -Elasticsearch only provides cross-group code/commit search (global) if all name-spaces are indexed. In this particular scenario where only a subset of namespaces are indexed, a global search will not provide a code or commit scope. This will be possible only in the scope of an indexed namespace. Currently there is no way to code/commit search in multiple indexed namespaces (when only a subset of namespaces has been indexed). For example if two groups are indexed, there is no way to run a single code search on both. You can only run a code search on the first group and then on the second. +Elasticsearch only provides cross-group code/commit search (global) for indexed namespaces. In this particular scenario where only a subset of namespaces are indexed, a global search will provide a code and commit scope which returns values from the subset of namespaces. If you would like to perform a search against a namespace that is not indexed, you can select the group or project in the search filter. You can filter the selection dropdown by writing part of the namespace or project name you're interested in. -- GitLab From 612204ba54e6de24d72af544057786c6b70d7d87 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Thu, 30 Jul 2020 19:08:58 -0400 Subject: [PATCH 03/14] fixup! Enable Advanced Search for global scope searches --- ee/spec/services/search/global_service_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ee/spec/services/search/global_service_spec.rb b/ee/spec/services/search/global_service_spec.rb index aa4541656080a7..e702f207507cfa 100644 --- a/ee/spec/services/search/global_service_spec.rb +++ b/ee/spec/services/search/global_service_spec.rb @@ -182,8 +182,8 @@ stub_ee_application_setting(elasticsearch_limit_indexing: true) end - it 'does not include ES-specific scopes' do - expect(described_class.new(user, {}).allowed_scopes).not_to include('commits') + it 'includes ES-specific scopes' do + expect(described_class.new(user, {}).allowed_scopes).to include('commits') end end end -- GitLab From 9faff8abd7f577cb5b97a56803836a106ff3e36f Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Mon, 3 Aug 2020 13:00:26 -0400 Subject: [PATCH 04/14] fixup! Enable Advanced Search for global scope searches --- ee/spec/requests/api/search_spec.rb | 151 +++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 1 deletion(-) diff --git a/ee/spec/requests/api/search_spec.rb b/ee/spec/requests/api/search_spec.rb index 76c4dbb5e3a1c5..059b44af92cfea 100644 --- a/ee/spec/requests/api/search_spec.rb +++ b/ee/spec/requests/api/search_spec.rb @@ -14,6 +14,12 @@ it { expect(json_response.size).to eq(size) } end + shared_examples 'no matching results returned' do + it { expect(response).to have_gitlab_http_status(:ok) } + it { expect(response).to include_limited_pagination_headers } + it { expect(json_response.size).to eq(0) } + end + shared_examples 'pagination' do |scope:, search: '*'| it 'returns a different result for each page' do get api(endpoint, user), params: { scope: scope, search: search, page: 1, per_page: 1 } @@ -58,6 +64,140 @@ end end + shared_examples 'namespace not indexed' do |level:| + context 'for merge_requests scope', :sidekiq_inline do + before do + create(:labeled_merge_request, target_branch: 'feature_1', source_project: project, labels: [create(:label), create(:label)]) + create(:merge_request, target_branch: 'feature_2', source_project: project, author: create(:user)) + create(:merge_request, target_branch: 'feature_3', source_project: project, milestone: create(:milestone, project: project)) + create(:merge_request, target_branch: 'feature_4', source_project: project) + ensure_elasticsearch_index! + + get api(endpoint, user), params: { scope: 'merge_requests', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + + context 'for wiki_blobs scope', :sidekiq_might_not_need_inline do + before do + wiki = create(:project_wiki, project: project) + create(:wiki_page, wiki: wiki, title: 'home', content: "Awesome page") + create(:wiki_page, wiki: wiki, title: 'other', content: "Another page") + + project.wiki.index_wiki_blobs + ensure_elasticsearch_index! + + get api(endpoint, user), params: { scope: 'wiki_blobs', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + + context 'for commits scope', :sidekiq_inline do + before do + project.repository.index_commits_and_blobs + ensure_elasticsearch_index! + + get api(endpoint, user), params: { scope: 'commits', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + + context 'for blobs scope', :sidekiq_might_not_need_inline do + before do + project.repository.index_commits_and_blobs + ensure_elasticsearch_index! + + get api(endpoint, user), params: { scope: 'blobs', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + + context 'for issues scope', :sidekiq_inline do + before do + create_list(:issue, 2, project: project) + ensure_elasticsearch_index! + + get api(endpoint, user), params: { scope: 'issues', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + + unless level == :project + context 'for projects scope', :sidekiq_inline do + before do + project + create(:project, :public, name: 'second project', group: group) + + ensure_elasticsearch_index! + + get api(endpoint, user), params: { scope: 'projects', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + end + + context 'for milestones scope', :sidekiq_inline do + before do + create_list(:milestone, 2, project: project) + + ensure_elasticsearch_index! + + get api(endpoint, user), params: { scope: 'milestones', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + + context 'for users scope', :sidekiq_inline do + before do + create_list(:user, 2).each do |user| + project.add_developer(user) + group.add_developer(user) + end + + get api(endpoint, user), params: { scope: 'users', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + + if level == :global + context 'for snippet_titles scope', :sidekiq_inline do + before do + create_list(:snippet, 2, :public, project: project, title: 'Some code', content: 'Check it out') + + ensure_elasticsearch_index! + + get api(endpoint, user), params: { scope: 'snippet_titles', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + end + + if level == :project + context 'for notes scope', :sidekiq_inline do + before do + create(:note_on_merge_request, project: project, note: 'awesome note') + mr = create(:merge_request, source_project: project, target_branch: 'another_branch') + create(:note, project: project, noteable: mr, note: 'another note') + + ensure_elasticsearch_index! + + get api(endpoint, user), params: { scope: 'notes', search: '*' } + end + + it_behaves_like 'no matching results returned' + end + end + end + shared_examples 'elasticsearch enabled' do |level:| context 'for merge_requests scope', :sidekiq_inline do before do @@ -292,7 +432,16 @@ stub_ee_application_setting(elasticsearch_limit_indexing: true) end - it_behaves_like 'elasticsearch disabled' + context 'and namespace is indexed' do + before do + create :elasticsearch_indexed_namespace, namespace: group + end + + it_behaves_like 'elasticsearch enabled', level: :global + end + context 'and namespace is not indexed' do + it_behaves_like 'namespace not indexed', level: :global + end end context 'when elasticsearch_limit_indexing off' do -- GitLab From 38c5e4c80b91e6f0ce7b63e8952b4880281874a7 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Mon, 3 Aug 2020 14:22:00 -0400 Subject: [PATCH 05/14] fixup! Enable Advanced Search for global scope searches --- doc/integration/elasticsearch.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/integration/elasticsearch.md b/doc/integration/elasticsearch.md index dd890137a710e7..9bccbc4c75c521 100644 --- a/doc/integration/elasticsearch.md +++ b/doc/integration/elasticsearch.md @@ -168,7 +168,10 @@ If you select `Limit namespaces and projects that can be indexed`, more options You can select namespaces and projects to index exclusively. Please note that if the namespace is a group it will include any sub-groups and projects belonging to those sub-groups to be indexed as well. -Elasticsearch only provides cross-group code/commit search (global) for indexed namespaces. In this particular scenario where only a subset of namespaces are indexed, a global search will provide a code and commit scope which returns values from the subset of namespaces. If you would like to perform a search against a namespace that is not indexed, you can select the group or project in the search filter. +NOTE: **Note:** +Elasticsearch only provides cross-group code/commit search (global) for indexed namespaces. + +In this particular scenario where only a subset of namespaces are indexed, a global search will provide code, commit, comment, and wiki scopes which return values from the subset of indexed namespaces. If you would like to perform a search against a namespace that is not indexed, you can select the group or project in the search filter. Additionally, it is possible to perform a global "basic search" by appending `&basic_search=true` to the URL in the browser bar. This search will use other data sources (ie. PostgreSQL data and Git data) and the code, commit, comment, and wiki scopes will not be displayed. You can filter the selection dropdown by writing part of the namespace or project name you're interested in. -- GitLab From f932f32c80481b0c25f53139ce129067d77100f5 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Mon, 3 Aug 2020 14:22:29 -0400 Subject: [PATCH 06/14] fixup! Enable Advanced Search for global scope searches --- doc/integration/elasticsearch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/integration/elasticsearch.md b/doc/integration/elasticsearch.md index 9bccbc4c75c521..afc70c3cc11c3c 100644 --- a/doc/integration/elasticsearch.md +++ b/doc/integration/elasticsearch.md @@ -169,7 +169,7 @@ You can select namespaces and projects to index exclusively. Please note that if any sub-groups and projects belonging to those sub-groups to be indexed as well. NOTE: **Note:** -Elasticsearch only provides cross-group code/commit search (global) for indexed namespaces. +Elasticsearch only provides cross-group code, commit, comment, and wiki search (global) for indexed namespaces. In this particular scenario where only a subset of namespaces are indexed, a global search will provide code, commit, comment, and wiki scopes which return values from the subset of indexed namespaces. If you would like to perform a search against a namespace that is not indexed, you can select the group or project in the search filter. Additionally, it is possible to perform a global "basic search" by appending `&basic_search=true` to the URL in the browser bar. This search will use other data sources (ie. PostgreSQL data and Git data) and the code, commit, comment, and wiki scopes will not be displayed. -- GitLab From dd62cfd98baeeb5c8fb0b19e276dd2c92025408b Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Mon, 3 Aug 2020 15:24:40 -0400 Subject: [PATCH 07/14] fixup! Enable Advanced Search for global scope searches --- doc/integration/elasticsearch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/integration/elasticsearch.md b/doc/integration/elasticsearch.md index afc70c3cc11c3c..880d3dacb1738c 100644 --- a/doc/integration/elasticsearch.md +++ b/doc/integration/elasticsearch.md @@ -169,7 +169,7 @@ You can select namespaces and projects to index exclusively. Please note that if any sub-groups and projects belonging to those sub-groups to be indexed as well. NOTE: **Note:** -Elasticsearch only provides cross-group code, commit, comment, and wiki search (global) for indexed namespaces. +Elasticsearch only provides cross-group code, commit, comment, and wiki search (global) for indexed namespaces. In this particular scenario where only a subset of namespaces are indexed, a global search will provide code, commit, comment, and wiki scopes which return values from the subset of indexed namespaces. If you would like to perform a search against a namespace that is not indexed, you can select the group or project in the search filter. Additionally, it is possible to perform a global "basic search" by appending `&basic_search=true` to the URL in the browser bar. This search will use other data sources (ie. PostgreSQL data and Git data) and the code, commit, comment, and wiki scopes will not be displayed. -- GitLab From cca9a1bf5625cd72eeaba93adbfd2e9ff3a7b644 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Tue, 4 Aug 2020 14:39:09 +0000 Subject: [PATCH 08/14] Apply 1 suggestion(s) to 1 file(s) --- doc/integration/elasticsearch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/integration/elasticsearch.md b/doc/integration/elasticsearch.md index 880d3dacb1738c..b2bcb264bc451e 100644 --- a/doc/integration/elasticsearch.md +++ b/doc/integration/elasticsearch.md @@ -171,7 +171,7 @@ any sub-groups and projects belonging to those sub-groups to be indexed as well. NOTE: **Note:** Elasticsearch only provides cross-group code, commit, comment, and wiki search (global) for indexed namespaces. -In this particular scenario where only a subset of namespaces are indexed, a global search will provide code, commit, comment, and wiki scopes which return values from the subset of indexed namespaces. If you would like to perform a search against a namespace that is not indexed, you can select the group or project in the search filter. Additionally, it is possible to perform a global "basic search" by appending `&basic_search=true` to the URL in the browser bar. This search will use other data sources (ie. PostgreSQL data and Git data) and the code, commit, comment, and wiki scopes will not be displayed. +In this particular scenario where only a subset of namespaces are indexed, a global search will provide code, commit, comment, and wiki scopes which return values from the subset of indexed namespaces. If you would like to perform a search against a namespace that is not indexed, you can select the group or project in the search filter. Additionally, it is possible to perform a global "basic search" by appending `&basic_search=true` to the URL in the browser bar. This search will use other data sources (that is PostgreSQL data and Git data) and the code, commit, comment, and wiki scopes will not be displayed. You can filter the selection dropdown by writing part of the namespace or project name you're interested in. -- GitLab From c52a700e6f21be84a083c07922eaa69baf9ae9c3 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Tue, 4 Aug 2020 11:11:09 -0400 Subject: [PATCH 09/14] fixup! Enable Advanced Search for global scope searches --- doc/integration/elasticsearch.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/integration/elasticsearch.md b/doc/integration/elasticsearch.md index b2bcb264bc451e..7fd0030eb8603e 100644 --- a/doc/integration/elasticsearch.md +++ b/doc/integration/elasticsearch.md @@ -169,7 +169,7 @@ You can select namespaces and projects to index exclusively. Please note that if any sub-groups and projects belonging to those sub-groups to be indexed as well. NOTE: **Note:** -Elasticsearch only provides cross-group code, commit, comment, and wiki search (global) for indexed namespaces. +Elasticsearch only provides cross-group [code, commit, comment, and wiki](../user/search/advanced_global_search.md#overview) global search for indexed namespaces. In this particular scenario where only a subset of namespaces are indexed, a global search will provide code, commit, comment, and wiki scopes which return values from the subset of indexed namespaces. If you would like to perform a search against a namespace that is not indexed, you can select the group or project in the search filter. Additionally, it is possible to perform a global "basic search" by appending `&basic_search=true` to the URL in the browser bar. This search will use other data sources (that is PostgreSQL data and Git data) and the code, commit, comment, and wiki scopes will not be displayed. -- GitLab From ec44e794d4069cd3f5cd1cbd5b6fa9bde3e7ba9f Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Tue, 4 Aug 2020 13:48:27 -0400 Subject: [PATCH 10/14] fixup! Enable Advanced Search for global scope searches --- ee/spec/requests/api/search_spec.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ee/spec/requests/api/search_spec.rb b/ee/spec/requests/api/search_spec.rb index 059b44af92cfea..1684e92b06069b 100644 --- a/ee/spec/requests/api/search_spec.rb +++ b/ee/spec/requests/api/search_spec.rb @@ -201,10 +201,11 @@ shared_examples 'elasticsearch enabled' do |level:| context 'for merge_requests scope', :sidekiq_inline do before do - create(:labeled_merge_request, target_branch: 'feature_1', source_project: project, labels: [create(:label), create(:label)]) - create(:merge_request, target_branch: 'feature_2', source_project: project, author: create(:user)) - create(:merge_request, target_branch: 'feature_3', source_project: project, milestone: create(:milestone, project: project)) - create(:merge_request, target_branch: 'feature_4', source_project: project) + create_list(:merge_request, 3, :unique_branches, source_project: project, author: create(:user), milestone: create(:milestone, project: project), labels: [create(:label)]) + # create(:labeled_merge_request, target_branch: 'feature_1', source_project: project, labels: [create(:label), create(:label)]) + # create(:merge_request, target_branch: 'feature_2', source_project: project, author: create(:user)) + # create(:merge_request, target_branch: 'feature_3', source_project: project, milestone: create(:milestone, project: project)) + # create(:merge_request, target_branch: 'feature_4', source_project: project) ensure_elasticsearch_index! end @@ -213,10 +214,11 @@ it 'avoids N+1 queries' do control = ActiveRecord::QueryRecorder.new { get api(endpoint, user), params: { scope: 'merge_requests', search: '*' } } - create(:labeled_merge_request, target_branch: 'feature_5', source_project: project, labels: [create(:label), create(:label)]) - create(:merge_request, target_branch: 'feature_6', source_project: project, author: create(:user)) - create(:merge_request, target_branch: 'feature_7', source_project: project, milestone: create(:milestone, project: project)) - create(:merge_request, target_branch: 'feature_8', source_project: project) + create_list(:merge_request, 3, :unique_branches, source_project: project, author: create(:user), milestone: create(:milestone, project: project), labels: [create(:label)]) + # create(:labeled_merge_request, target_branch: 'feature_5', source_project: project, labels: [create(:label), create(:label)]) + # create(:merge_request, target_branch: 'feature_6', source_project: project, author: create(:user)) + # create(:merge_request, target_branch: 'feature_7', source_project: project, milestone: create(:milestone, project: project)) + # create(:merge_request, target_branch: 'feature_8', source_project: project) ensure_elasticsearch_index! -- GitLab From c2353acffa985a7ff7537bd8720c788e021cbf49 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Tue, 4 Aug 2020 13:55:37 -0400 Subject: [PATCH 11/14] fixup! Enable Advanced Search for global scope searches --- ee/spec/requests/api/search_spec.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ee/spec/requests/api/search_spec.rb b/ee/spec/requests/api/search_spec.rb index 1684e92b06069b..d38a70a7867a2a 100644 --- a/ee/spec/requests/api/search_spec.rb +++ b/ee/spec/requests/api/search_spec.rb @@ -202,10 +202,6 @@ context 'for merge_requests scope', :sidekiq_inline do before do create_list(:merge_request, 3, :unique_branches, source_project: project, author: create(:user), milestone: create(:milestone, project: project), labels: [create(:label)]) - # create(:labeled_merge_request, target_branch: 'feature_1', source_project: project, labels: [create(:label), create(:label)]) - # create(:merge_request, target_branch: 'feature_2', source_project: project, author: create(:user)) - # create(:merge_request, target_branch: 'feature_3', source_project: project, milestone: create(:milestone, project: project)) - # create(:merge_request, target_branch: 'feature_4', source_project: project) ensure_elasticsearch_index! end @@ -213,13 +209,7 @@ it 'avoids N+1 queries' do control = ActiveRecord::QueryRecorder.new { get api(endpoint, user), params: { scope: 'merge_requests', search: '*' } } - create_list(:merge_request, 3, :unique_branches, source_project: project, author: create(:user), milestone: create(:milestone, project: project), labels: [create(:label)]) - # create(:labeled_merge_request, target_branch: 'feature_5', source_project: project, labels: [create(:label), create(:label)]) - # create(:merge_request, target_branch: 'feature_6', source_project: project, author: create(:user)) - # create(:merge_request, target_branch: 'feature_7', source_project: project, milestone: create(:milestone, project: project)) - # create(:merge_request, target_branch: 'feature_8', source_project: project) - ensure_elasticsearch_index! expect { get api(endpoint, user), params: { scope: 'merge_requests', search: '*' } }.not_to exceed_query_limit(control) -- GitLab From 58a0967cd883dfb35e9a3f53aac1df465ea3f56b Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Thu, 6 Aug 2020 14:58:34 -0400 Subject: [PATCH 12/14] fixup! Enable Advanced Search for global scope searches --- ee/spec/requests/api/search_spec.rb | 234 ++++++---------------------- 1 file changed, 46 insertions(+), 188 deletions(-) diff --git a/ee/spec/requests/api/search_spec.rb b/ee/spec/requests/api/search_spec.rb index d38a70a7867a2a..d3065bd2ed7d1d 100644 --- a/ee/spec/requests/api/search_spec.rb +++ b/ee/spec/requests/api/search_spec.rb @@ -14,12 +14,6 @@ it { expect(json_response.size).to eq(size) } end - shared_examples 'no matching results returned' do - it { expect(response).to have_gitlab_http_status(:ok) } - it { expect(response).to include_limited_pagination_headers } - it { expect(json_response.size).to eq(0) } - end - shared_examples 'pagination' do |scope:, search: '*'| it 'returns a different result for each page' do get api(endpoint, user), params: { scope: scope, search: search, page: 1, per_page: 1 } @@ -64,140 +58,6 @@ end end - shared_examples 'namespace not indexed' do |level:| - context 'for merge_requests scope', :sidekiq_inline do - before do - create(:labeled_merge_request, target_branch: 'feature_1', source_project: project, labels: [create(:label), create(:label)]) - create(:merge_request, target_branch: 'feature_2', source_project: project, author: create(:user)) - create(:merge_request, target_branch: 'feature_3', source_project: project, milestone: create(:milestone, project: project)) - create(:merge_request, target_branch: 'feature_4', source_project: project) - ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'merge_requests', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - - context 'for wiki_blobs scope', :sidekiq_might_not_need_inline do - before do - wiki = create(:project_wiki, project: project) - create(:wiki_page, wiki: wiki, title: 'home', content: "Awesome page") - create(:wiki_page, wiki: wiki, title: 'other', content: "Another page") - - project.wiki.index_wiki_blobs - ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'wiki_blobs', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - - context 'for commits scope', :sidekiq_inline do - before do - project.repository.index_commits_and_blobs - ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'commits', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - - context 'for blobs scope', :sidekiq_might_not_need_inline do - before do - project.repository.index_commits_and_blobs - ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'blobs', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - - context 'for issues scope', :sidekiq_inline do - before do - create_list(:issue, 2, project: project) - ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'issues', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - - unless level == :project - context 'for projects scope', :sidekiq_inline do - before do - project - create(:project, :public, name: 'second project', group: group) - - ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'projects', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - end - - context 'for milestones scope', :sidekiq_inline do - before do - create_list(:milestone, 2, project: project) - - ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'milestones', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - - context 'for users scope', :sidekiq_inline do - before do - create_list(:user, 2).each do |user| - project.add_developer(user) - group.add_developer(user) - end - - get api(endpoint, user), params: { scope: 'users', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - - if level == :global - context 'for snippet_titles scope', :sidekiq_inline do - before do - create_list(:snippet, 2, :public, project: project, title: 'Some code', content: 'Check it out') - - ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'snippet_titles', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - end - - if level == :project - context 'for notes scope', :sidekiq_inline do - before do - create(:note_on_merge_request, project: project, note: 'awesome note') - mr = create(:merge_request, source_project: project, target_branch: 'another_branch') - create(:note, project: project, noteable: mr, note: 'another note') - - ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'notes', search: '*' } - end - - it_behaves_like 'no matching results returned' - end - end - end - shared_examples 'elasticsearch enabled' do |level:| context 'for merge_requests scope', :sidekiq_inline do before do @@ -216,7 +76,7 @@ end end - context 'for wiki_blobs scope', :sidekiq_might_not_need_inline do + context 'for wiki_blobs scope', :sidekiq_inline do before do wiki = create(:project_wiki, project: project) create(:wiki_page, wiki: wiki, title: 'home', content: "Awesome page") @@ -233,71 +93,72 @@ it_behaves_like 'pagination', scope: 'wiki_blobs' end - context 'for commits scope', :sidekiq_inline do + context 'for commits and blobs', :sidekiq_inline do before do project.repository.index_commits_and_blobs ensure_elasticsearch_index! - - get api(endpoint, user), params: { scope: 'commits', search: 'folder' } end - it_behaves_like 'response is correct', schema: 'public_api/v4/commits_details', size: 2 - - it_behaves_like 'pagination', scope: 'commits' + context 'for commits scope' do + before do + get api(endpoint, user), params: { scope: 'commits', search: 'folder' } + end - it 'avoids N+1 queries' do - control = ActiveRecord::QueryRecorder.new { get api(endpoint, user), params: { scope: 'commits', search: 'folder' } } + it_behaves_like 'response is correct', schema: 'public_api/v4/commits_details', size: 2 - project_2 = create(:project, :public, :repository, :wiki_repo, name: 'awesome project 2') - project_3 = create(:project, :public, :repository, :wiki_repo, name: 'awesome project 3') - project_2.repository.index_commits_and_blobs - project_3.repository.index_commits_and_blobs + it_behaves_like 'pagination', scope: 'commits' - ensure_elasticsearch_index! + it 'avoids N+1 queries' do + control = ActiveRecord::QueryRecorder.new { get api(endpoint, user), params: { scope: 'commits', search: 'folder' } } - # Some N+1 queries still exist - expect { get api(endpoint, user), params: { scope: 'commits', search: 'folder' } }.not_to exceed_query_limit(control).with_threshold(9) - end - end + project_2 = create(:project, :public, :repository, :wiki_repo, name: 'awesome project 2') + project_3 = create(:project, :public, :repository, :wiki_repo, name: 'awesome project 3') + project_2.repository.index_commits_and_blobs + project_3.repository.index_commits_and_blobs - context 'for blobs scope', :sidekiq_might_not_need_inline do - before do - project.repository.index_commits_and_blobs - ensure_elasticsearch_index! + ensure_elasticsearch_index! - get api(endpoint, user), params: { scope: 'blobs', search: 'monitors' } + # Some N+1 queries still exist + expect { get api(endpoint, user), params: { scope: 'commits', search: 'folder' } }.not_to exceed_query_limit(control).with_threshold(9) + end end - it_behaves_like 'response is correct', schema: 'public_api/v4/blobs' + context 'for blobs scope', :sidekiq_inline do + before do + get api(endpoint, user), params: { scope: 'blobs', search: 'monitors' } + end - it_behaves_like 'pagination', scope: 'blobs' + it_behaves_like 'response is correct', schema: 'public_api/v4/blobs' - context 'filters' do - it 'by filename' do - get api("/projects/#{project.id}/search", user), params: { scope: 'blobs', search: 'mon* filename:PROCESS.md' } + it_behaves_like 'pagination', scope: 'blobs' - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.size).to eq(1) - expect(json_response.first['path']).to eq('PROCESS.md') - end + context 'filters' do + it 'by filename' do + get api("/projects/#{project.id}/search", user), params: { scope: 'blobs', search: 'mon* filename:PROCESS.md' } + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.size).to eq(1) + expect(json_response.first['path']).to eq('PROCESS.md') + end - it 'by path' do - get api("/projects/#{project.id}/search", user), params: { scope: 'blobs', search: 'mon* path:markdown' } + it 'by path' do + get api("/projects/#{project.id}/search", user), params: { scope: 'blobs', search: 'mon* path:markdown' } - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.size).to eq(1) - json_response.each do |file| - expect(file['path']).to match(%r[/markdown/]) + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.size).to eq(1) + json_response.each do |file| + expect(file['path']).to match(%r[/markdown/]) + end end - end - it 'by extension' do - get api("/projects/#{project.id}/search", user), params: { scope: 'blobs', search: 'mon* extension:md' } + it 'by extension' do + get api("/projects/#{project.id}/search", user), params: { scope: 'blobs', search: 'mon* extension:md' } - expect(response).to have_gitlab_http_status(:ok) - expect(json_response.size).to eq(3) - json_response.each do |file| - expect(file['path']).to match(/\A.+\.md\z/) + expect(response).to have_gitlab_http_status(:ok) + expect(json_response.size).to eq(3) + json_response.each do |file| + expect(file['path']).to match(/\A.+\.md\z/) + end end end end @@ -431,9 +292,6 @@ it_behaves_like 'elasticsearch enabled', level: :global end - context 'and namespace is not indexed' do - it_behaves_like 'namespace not indexed', level: :global - end end context 'when elasticsearch_limit_indexing off' do -- GitLab From d28607d73ff83c97ba2bcef8d041cd50a20c1581 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Thu, 6 Aug 2020 15:05:29 -0400 Subject: [PATCH 13/14] fixup! Enable Advanced Search for global scope searches --- ee/spec/requests/api/search_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/spec/requests/api/search_spec.rb b/ee/spec/requests/api/search_spec.rb index d3065bd2ed7d1d..6dd424c85c25df 100644 --- a/ee/spec/requests/api/search_spec.rb +++ b/ee/spec/requests/api/search_spec.rb @@ -123,7 +123,7 @@ end end - context 'for blobs scope', :sidekiq_inline do + context 'for blobs scope' do before do get api(endpoint, user), params: { scope: 'blobs', search: 'monitors' } end -- GitLab From 8e2fa52f1d1480f59a5038525930c4f8180329b3 Mon Sep 17 00:00:00 2001 From: Terri Chu Date: Thu, 6 Aug 2020 15:36:41 -0400 Subject: [PATCH 14/14] fixup! Enable Advanced Search for global scope searches --- ee/spec/requests/api/search_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/spec/requests/api/search_spec.rb b/ee/spec/requests/api/search_spec.rb index 6dd424c85c25df..6dec01cd5bf235 100644 --- a/ee/spec/requests/api/search_spec.rb +++ b/ee/spec/requests/api/search_spec.rb @@ -229,7 +229,7 @@ end end - context 'for users scope', :sidekiq_inline do + context 'for users scope', :sidekiq_might_not_need_inline do before do create_list(:user, 2).each do |user| project.add_developer(user) -- GitLab