Commit 3d0cbfb1 authored by Stan Hu's avatar Stan Hu

Merge branch '11793-elasticsearch-restore-global-notes-search' into 'master'

Resolve "Elasticsearch: restore global notes search"

Closes #11793

See merge request gitlab-org/gitlab-ee!14818
parents b7fa14a6 2e3ff160
......@@ -43,7 +43,7 @@ module EE
def allowed_scopes
strong_memoize(:ee_allowed_scopes) do
super.tap do |ce_scopes|
ce_scopes.concat(%w[wiki_blobs blobs commits]) if ::Gitlab::CurrentSettings.elasticsearch_search?
ce_scopes.concat(%w[notes wiki_blobs blobs commits]) if ::Gitlab::CurrentSettings.elasticsearch_search?
end
end
end
......
- if search_service.use_elasticsearch?
%li{ class: active_when(@scope == 'notes') }
= link_to search_filter_path(scope: 'notes') do
= _("Comments")
%span.badge.badge-pill
= limited_count(@search_results.notes_count)
%li{ class: active_when(@scope == 'blobs') }
= link_to search_filter_path(scope: 'blobs') do
= _("Code")
......
---
title: Allow global search on comments
merge_request: 14818
author:
type: added
......@@ -34,6 +34,8 @@ module Gitlab
eager_load(merge_requests, page, eager: { target_project: [:route, :namespace] })
when 'milestones'
eager_load(milestones, page, eager: { project: [:route, :namespace] })
when 'notes'
eager_load(notes, page, eager: { project: [:route, :namespace] })
when 'blobs'
blobs.page(page).per(per_page)
when 'wiki_blobs'
......@@ -56,6 +58,10 @@ module Gitlab
end
alias_method :limited_projects_count, :projects_count
def notes_count
@notes_count ||= notes.total_count
end
def blobs_count
@blobs_count ||= blobs.total_count
end
......@@ -191,6 +197,12 @@ module Gitlab
end
end
def notes
strong_memoize(:notes) do
Note.elastic_search(query, options: base_options)
end
end
def blobs
return Kaminari.paginate_array([]) if query.blank?
......
......@@ -88,6 +88,26 @@ describe 'Global elastic search', :elastic do
end
end
describe 'I search through the notes and I see pagination' do
before do
issue = create(:issue, project: project, title: 'initial')
create_list(:note, 21, noteable: issue, project: project, note: 'foo')
Gitlab::Elastic::Helper.refresh_index
end
it "has a pagination" do
visit dashboard_projects_path
fill_in "search", with: "foo"
click_button "Go"
select_filter("Comments")
expect(page).to have_selector('.gl-pagination .js-pagination-page', count: 2)
end
end
describe 'I search through the blobs' do
let(:project_2) { create(:project, :repository, :wiki_repo) }
......
......@@ -144,6 +144,52 @@ describe Gitlab::Elastic::SearchResults, :elastic do
end
end
describe 'notes' do
let(:issue) { create(:issue, project: project_1, title: 'Hello') }
before do
@note_1 = create(
:note,
noteable: issue,
project: project_1,
note: 'foo bar'
)
@note_2 = create(
:note_on_issue,
noteable: issue,
project: project_1,
note: 'foo baz'
)
@note_3 = create(
:note_on_issue,
noteable: issue,
project: project_1,
note: 'bar baz'
)
Gitlab::Elastic::Helper.refresh_index
end
it_behaves_like 'a paginated object', 'notes'
it 'lists found notes' do
results = described_class.new(user, 'foo', limit_project_ids)
notes = results.objects('notes')
expect(notes).to include @note_1
expect(notes).to include @note_2
expect(notes).not_to include @note_3
expect(results.notes_count).to eq 2
end
it 'returns empty list when notes are not found' do
results = described_class.new(user, 'security', limit_project_ids)
expect(results.objects('notes')).to be_empty
expect(results.notes_count).to eq 0
end
end
describe 'confidential issues' do
let(:project_3) { create(:project) }
let(:project_4) { create(:project) }
......
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