Commit 7561e2e7 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'revert-7d9a74db' into 'master'

Revert "Enable advanced search by default for global search scope"

See merge request gitlab-org/gitlab!39063
parents 403ba8ee 5c234b63
......@@ -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.
......
......@@ -239,7 +239,7 @@ module EE
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
......
---
title: Enable Advanced Search for global scope searches
merge_request: 38093
author:
type: changed
......@@ -434,7 +434,7 @@ RSpec.describe ApplicationSetting do
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
......
......@@ -61,7 +61,10 @@ RSpec.describe API::Search do
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 @@ RSpec.describe API::Search do
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 @@ RSpec.describe API::Search do
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 @@ RSpec.describe API::Search do
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 @@ RSpec.describe API::Search do
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
......
......@@ -182,8 +182,8 @@ RSpec.describe Search::GlobalService do
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment