From 5c234b63207730f7ac9bedf66b402d597c271c71 Mon Sep 17 00:00:00 2001 From: Dmitry Gruzd Date: Mon, 10 Aug 2020 06:12:26 +0000 Subject: [PATCH] Revert "Merge branch..." This reverts merge request !38093 --- doc/integration/elasticsearch.md | 5 +- ee/app/models/ee/application_setting.rb | 2 +- ...ic-groups-bronze-and-above-to-advanced.yml | 5 - ee/spec/models/application_setting_spec.rb | 2 +- ee/spec/requests/api/search_spec.rb | 113 +++++++++--------- .../services/search/global_service_spec.rb | 4 +- 6 files changed, 62 insertions(+), 69 deletions(-) delete mode 100644 ee/changelogs/unreleased/197231-default-searches-for-public-groups-bronze-and-above-to-advanced.yml diff --git a/doc/integration/elasticsearch.md b/doc/integration/elasticsearch.md index 87df9822dc7b6e..8d4c8b3cf97cc4 100644 --- a/doc/integration/elasticsearch.md +++ b/doc/integration/elasticsearch.md @@ -168,10 +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. -NOTE: **Note:** -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. +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. You can filter the selection dropdown by writing part of the namespace or project name you're interested in. diff --git a/ee/app/models/ee/application_setting.rb b/ee/app/models/ee/application_setting.rb index 3cc28a178aaba1..bc59475b14fc52 100644 --- a/ee/app/models/ee/application_setting.rb +++ b/ee/app/models/ee/application_setting.rb @@ -239,7 +239,7 @@ def search_using_elasticsearch?(scope: nil) when Project elasticsearch_indexes_project?(scope) else - true # Use elasticsearch for the global scope, even when limiting is on + false # Never use elasticsearch for the global scope 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 deleted file mode 100644 index d5dd38d742497e..00000000000000 --- a/ee/changelogs/unreleased/197231-default-searches-for-public-groups-bronze-and-above-to-advanced.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -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 190035cde06007..7d109fd96b511f 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(indexing && searching) } + it { is_expected.to eq(only_when_enabled_globally) } end context 'namespace (in scope)' do diff --git a/ee/spec/requests/api/search_spec.rb b/ee/spec/requests/api/search_spec.rb index 6dec01cd5bf235..76c4dbb5e3a1c5 100644 --- a/ee/spec/requests/api/search_spec.rb +++ b/ee/spec/requests/api/search_spec.rb @@ -61,7 +61,10 @@ shared_examples 'elasticsearch enabled' do |level:| 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 @@ -69,14 +72,19 @@ 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) end end - context 'for wiki_blobs scope', :sidekiq_inline do + 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") @@ -93,72 +101,71 @@ it_behaves_like 'pagination', scope: 'wiki_blobs' end - context 'for commits and blobs', :sidekiq_inline do + context 'for commits scope', :sidekiq_inline do before do project.repository.index_commits_and_blobs ensure_elasticsearch_index! - end - context 'for commits scope' do - before do - get api(endpoint, user), params: { scope: 'commits', search: 'folder' } - end + 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 'response is correct', schema: 'public_api/v4/commits_details', size: 2 - it_behaves_like 'pagination', scope: 'commits' + it_behaves_like 'pagination', scope: 'commits' - it 'avoids N+1 queries' do - control = ActiveRecord::QueryRecorder.new { get api(endpoint, user), params: { scope: 'commits', search: 'folder' } } + it 'avoids N+1 queries' do + control = ActiveRecord::QueryRecorder.new { get api(endpoint, user), params: { scope: 'commits', search: 'folder' } } - 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 + 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 - ensure_elasticsearch_index! + ensure_elasticsearch_index! - # 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 + # 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 - context 'for blobs scope' do - before do - get api(endpoint, user), params: { scope: 'blobs', search: 'monitors' } - end + context 'for blobs scope', :sidekiq_might_not_need_inline do + before do + project.repository.index_commits_and_blobs + ensure_elasticsearch_index! - it_behaves_like 'response is correct', schema: 'public_api/v4/blobs' + 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' } - 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) + expect(json_response.first['path']).to eq('PROCESS.md') + end - 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 + 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/]) 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/) - end + 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 @@ -229,7 +236,7 @@ end end - context 'for users scope', :sidekiq_might_not_need_inline do + context 'for users scope', :sidekiq_inline do before do create_list(:user, 2).each do |user| project.add_developer(user) @@ -285,13 +292,7 @@ stub_ee_application_setting(elasticsearch_limit_indexing: true) end - context 'and namespace is indexed' do - before do - create :elasticsearch_indexed_namespace, namespace: group - end - - it_behaves_like 'elasticsearch enabled', level: :global - end + it_behaves_like 'elasticsearch disabled' end context 'when elasticsearch_limit_indexing off' do diff --git a/ee/spec/services/search/global_service_spec.rb b/ee/spec/services/search/global_service_spec.rb index e702f207507cfa..aa4541656080a7 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 'includes ES-specific scopes' do - expect(described_class.new(user, {}).allowed_scopes).to include('commits') + it 'does not include ES-specific scopes' do + expect(described_class.new(user, {}).allowed_scopes).not_to include('commits') end end end -- GitLab