Skip to content
代码片段 群组 项目
未验证 提交 4039f588 编辑于 作者: Terri Chu's avatar Terri Chu 提交者: GitLab
浏览文件

Merge branch '439089-switch-issue-title-to-code_analyzer' into 'master'

Switch issue.title to a new analyzer

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142580



Merged-by: default avatarTerri Chu <tchu@gitlab.com>
Approved-by: default avatarMadelein van Niekerk <mvanniekerk@gitlab.com>
Approved-by: default avatarTerri Chu <tchu@gitlab.com>
Reviewed-by: default avatarTerri Chu <tchu@gitlab.com>
Co-authored-by: default avatarrkumar555 <rkumar@gitlab.com>
No related branches found
No related tags found
无相关合并请求
---
name: ReindexIssueToUpdateAnalyzerForTitle
version: '20240123181031'
description: This migration reindexes the issues index to start using new analyzer for title
group: group::global search
milestone: '16.9'
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/142580
obsolete: false
marked_obsolete_by_url:
marked_obsolete_in_milestone:
# frozen_string_literal: true
class ReindexIssueToUpdateAnalyzerForTitle < Elastic::Migration
def migrate
Elastic::ReindexingTask.create!(targets: %w[Issue], options: { skip_pending_migrations_check: true })
end
def completed?
true
end
end
......@@ -25,6 +25,11 @@ module Config
codec: 'best_compression',
analysis: {
analyzer: {
title_analyzer: {
tokenizer: 'standard',
filter: %w[word_delimiter_graph_filter asciifolding lowercase stemmer flatten_graph remove_duplicates]
},
default: {
tokenizer: 'standard',
filter: %w[lowercase stemmer]
......
......@@ -22,7 +22,7 @@ module IssueConfig
indexes :id, 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', analyzer: :code_analyzer
indexes :created_at, type: :date
indexes :updated_at, type: :date
......
# frozen_string_literal: true
require 'spec_helper'
require_relative 'migration_shared_examples'
require File.expand_path('ee/elastic/migrate/20240123181031_reindex_issue_to_update_analyzer_for_title.rb')
RSpec.describe ReindexIssueToUpdateAnalyzerForTitle, feature_category: :global_search do
let(:version) { 20240123181031 }
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[Issue])
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
......@@ -364,17 +364,7 @@
expect(results.issues_count).to eq 0
end
it 'handles plural words through algorithmic stemming', :aggregate_failures do
issue1 = create(:issue, project: project_1, title: 'remove :title attribute from submit buttons to prevent un-styled tooltips')
issue2 = create(:issue, project: project_1, title: 'smarter submit behavior for buttons groups')
ensure_elasticsearch_index!
results = described_class.new(user, 'button', limit_project_ids)
expect(results.objects('issues')).to contain_exactly(issue1, issue2)
expect(results.issues_count).to eq 2
end
it_behaves_like 'can search by title for miscellaneous cases', 'issues'
it 'executes count only queries' do
results = described_class.new(user, query, limit_project_ids)
......
......@@ -118,3 +118,66 @@
end
end
end
RSpec.shared_examples 'can search by title for miscellaneous cases' do |type|
let_it_be(:searched_project) { create(:project, :public, :repository, :wiki_repo) }
let(:records_count) { 2 }
def create_records!(type)
case type
when 'issues'
create_list(:issue, records_count, project: searched_project)
end
end
# rubocop:disable RSpec/InstanceVariable -- Want to reuse the @records
before do
@records = create_records!(type)
end
it 'handles plural words through algorithmic stemming', :aggregate_failures do
@records[0].update!(title: 'remove :title attribute from submit buttons to prevent un-styled tooltips')
@records[1].update!(title: 'smarter submit behavior for buttons groups')
ensure_elasticsearch_index!
results = described_class.new(user, 'button', [searched_project.id])
expect(results.objects(type)).to match_array(@records)
expect(results.issues_count).to eq records_count
end
it 'handles if title has umlauts', :aggregate_failures do
@records[0].update!(title: 'köln')
@records[1].update!(title: 'kǒln')
ensure_elasticsearch_index!
results = described_class.new(user, 'koln', [searched_project.id])
expect(results.objects(type)).to match_array(@records)
expect(results.issues_count).to eq records_count
end
it 'handles if title has dots', :aggregate_failures do
@records[0].update!(title: 'with.dot.title')
@records[1].update!(title: 'there is.dot')
ensure_elasticsearch_index!
results = described_class.new(user, 'dot', [searched_project.id])
expect(results.objects(type)).to match_array(@records)
expect(results.issues_count).to eq records_count
end
it 'handles if title has underscore', :aggregate_failures do
@records[0].update!(title: 'with_underscore_text')
@records[1].update!(title: 'some_underscore')
ensure_elasticsearch_index!
results = described_class.new(user, 'underscore', [searched_project.id])
expect(results.objects(type)).to match_array(@records)
expect(results.issues_count).to eq records_count
end
it 'handles if title has camelcase', :aggregate_failures do
@records[0].update!(title: 'withCamelcaseTitle')
@records[1].update!(title: 'CamelcaseText')
ensure_elasticsearch_index!
results = described_class.new(user, 'Camelcase', [searched_project.id])
expect(results.objects(type)).to match_array(@records)
expect(results.issues_count).to eq records_count
end
# rubocop:enable RSpec/InstanceVariable
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册