Commit 86b54309 authored by Terri Chu's avatar Terri Chu Committed by Dylan Griffith

Enable advanced search by default for global search scope

parent 1d704420
......@@ -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) 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.
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.
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
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
......
---
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(only_when_enabled_globally) }
it { is_expected.to eq(indexing && searching) }
end
context 'namespace (in scope)' do
......
......@@ -61,10 +61,7 @@ RSpec.describe API::Search do
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)])
ensure_elasticsearch_index!
end
......@@ -72,19 +69,14 @@ 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(: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)])
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_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")
......@@ -101,11 +93,14 @@ RSpec.describe API::Search do
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!
end
context 'for commits scope' do
before do
get api(endpoint, user), params: { scope: 'commits', search: 'folder' }
end
......@@ -128,11 +123,8 @@ RSpec.describe API::Search do
end
end
context 'for blobs scope', :sidekiq_might_not_need_inline do
context 'for blobs scope' do
before do
project.repository.index_commits_and_blobs
ensure_elasticsearch_index!
get api(endpoint, user), params: { scope: 'blobs', search: 'monitors' }
end
......@@ -170,6 +162,7 @@ RSpec.describe API::Search do
end
end
end
end
context 'for issues scope', :sidekiq_inline do
before do
......@@ -236,7 +229,7 @@ RSpec.describe API::Search do
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)
......@@ -292,7 +285,13 @@ RSpec.describe API::Search do
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
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 '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
......
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