Skip to content
代码片段 群组 项目
未验证 提交 014d6c3f 编辑于 作者: Ravi Kumar's avatar Ravi Kumar 提交者: GitLab
浏览文件

Update the analyzer for merge_request title and description

New analyzers allows to better search the code syntax in the
merge request title and description. Also, adding an elastic migration
to use Zero downtime reindexing to reindex all epics.

Changelog: added
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142550
EE: true
上级 906b5c14
No related branches found
No related tags found
无相关合并请求
---
name: ReindexMergeRequestToUpdateAnalyzer
version: '20240201164432'
description: This migration reindexes the merge_requests index to start using new analyzers for description and title
group: group::global search
milestone: '16.9'
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142550
obsolete: false
marked_obsolete_by_url:
marked_obsolete_in_milestone:
# frozen_string_literal: true
class ReindexMergeRequestToUpdateAnalyzer < Elastic::Migration
def migrate
Elastic::ReindexingTask.create!(targets: %w[MergeRequest], options: { skip_pending_migrations_check: true })
end
def completed?
true
end
end
...@@ -21,8 +21,8 @@ module MergeRequestConfig ...@@ -21,8 +21,8 @@ module MergeRequestConfig
indexes :id, type: :integer indexes :id, type: :integer
indexes :iid, type: :integer indexes :iid, type: :integer
indexes :title, type: :text, index_options: 'positions' indexes :title, type: :text, index_options: 'positions', analyzer: :title_analyzer
indexes :description, type: :text, index_options: 'positions' indexes :description, type: :text, index_options: 'positions', analyzer: :code_analyzer
indexes :state, type: :keyword indexes :state, type: :keyword
indexes :project_id, type: :integer indexes :project_id, type: :integer
indexes :author_id, type: :integer indexes :author_id, type: :integer
......
# frozen_string_literal: true
require 'spec_helper'
require_relative 'migration_shared_examples'
require File.expand_path('ee/elastic/migrate/20240201164432_reindex_merge_request_to_update_analyzer.rb')
RSpec.describe ReindexMergeRequestToUpdateAnalyzer, feature_category: :global_search do
let(:version) { 20240201164432 }
let(:migration) { described_class.new(version) }
it 'does not have migration options set', :aggregate_failures do
expect(migration).not_to be_batched
expect(migration).not_to be_retry_on_failure
end
describe '#migrate' do
it 'creates reindexing task with correct target and options' do
expect { migration.migrate }.to change { Elastic::ReindexingTask.count }.by(1)
task = Elastic::ReindexingTask.last
expect(task.targets).to eq(%w[MergeRequest])
expect(task.options).to eq({ 'skip_pending_migrations_check' => true })
end
end
describe '#completed?' do
it 'always returns true' do
expect(migration.completed?).to eq(true)
end
end
end
...@@ -776,6 +776,30 @@ ...@@ -776,6 +776,30 @@
expect(results.merge_requests_count).to eq 2 expect(results.merge_requests_count).to eq 2
end end
it_behaves_like 'can search by title for miscellaneous cases', 'merge_requests'
context 'when description has code snippets' do
include_context 'with code examples' do
before do
code_examples.values.uniq.each.with_index do |code, idx|
sha = Digest::SHA256.hexdigest(code)
create :merge_request, target_branch: "feature#{idx}", source_project: project_1, target_project: project_1,
title: sha, description: code
end
ensure_elasticsearch_index!
end
it 'finds all examples' do
code_examples.each do |query, description|
sha = Digest::SHA256.hexdigest(description)
merge_requests = described_class.new(user, query, limit_project_ids).objects('merge_requests')
expect(merge_requests.map(&:title)).to include(sha)
end
end
end
end
it 'returns empty list when merge requests are not found' do it 'returns empty list when merge requests are not found' do
results = described_class.new(user, 'security', limit_project_ids) results = described_class.new(user, 'security', limit_project_ids)
......
...@@ -126,10 +126,14 @@ ...@@ -126,10 +126,14 @@
def create_records!(type) def create_records!(type)
case type case type
when 'issues'
create_list(:issue, records_count, project: searched_project)
when 'epics' when 'epics'
create_list(:epic, records_count, group: searched_group) create_list(:epic, records_count, group: searched_group)
when 'issues'
create_list(:issue, records_count, project: searched_project)
when 'merge_requests'
records = []
records_count.times { |i| records << create(:merge_request, source_branch: i, source_project: searched_project) }
records
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册