Skip to content
Snippets Groups Projects
Verified Commit 18057eb4 authored by Madelein van Niekerk's avatar Madelein van Niekerk :one: Committed by GitLab
Browse files

Merge branch 'add_notes_work_item_query_builder' into 'master'

Add notes fields to work item query

See merge request !173719



Merged-by: default avatarMadelein van Niekerk <mvanniekerk@gitlab.com>
Approved-by: default avatarMadelein van Niekerk <mvanniekerk@gitlab.com>
Reviewed-by: default avatarVitali Tatarintev <vtatarintev@gitlab.com>
Reviewed-by: default avatarMadelein van Niekerk <mvanniekerk@gitlab.com>
Co-authored-by: default avatarJoseph Snyder <joe.snyder@kitware.com>
parents cb03a063 d9e7a1f3
No related branches found
No related tags found
1 merge request!173719Add notes fields to work item query
Pipeline #1563062180 passed
---
name: advanced_search_work_item_uses_note_fields
feature_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/15645
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/173719
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/503220
milestone: '17.7'
group: group::global search
type: gitlab_com_derisk
default_enabled: false
......@@ -9,8 +9,7 @@ class WorkItemQueryBuilder < QueryBuilder
THRESHOLD_FOR_GENERATING_EMBEDDING = 10
def build
# iid field can be added here as lenient option will pardon format errors, like integer out of range.
options[:fields] = options[:fields].presence || %w[iid^3 title^2 description]
options[:fields] = fields
query_hash = if hybrid_work_item_search?
::Search::Elastic::Queries.by_knn(query: query, options: options)
......@@ -42,6 +41,18 @@ def build
private
def fields
return options[:fields] if options[:fields]
# iid field can be added here as lenient option will pardon format errors, like integer out of range.
fields = %w[iid^3 title^2 description]
return fields unless Feature.enabled?(:advanced_search_work_item_uses_note_fields,
options[:current_user]) && ::Elastic::DataMigrationService.migration_has_finished?(:add_notes_to_work_items)
fields + %w[notes notes_internal]
end
def get_authorization_filter(query_hash:, options:)
if options[:group_level_authorization]
return ::Search::Elastic::Filters.by_group_level_authorization(query_hash: query_hash, options: options)
......
......@@ -107,6 +107,30 @@
work_item:multi_match_phrase:search_terms])
end
end
context "when add_notes_to_work_item migration is finished" do
before do
set_elasticsearch_migration_to :add_notes_to_work_items, including: true
end
context 'when search_uses_note_fields feature flag is disabled' do
before do
stub_feature_flags(advanced_search_work_item_uses_note_fields: false)
end
it 'returns the expected query without the note fields' do
assert_fields_in_query(build,
without: %w[notes notes_internal])
end
end
context 'when search_uses_note_fields feature flag is enabled' do
it 'returns the expected query with the note fields' do
assert_fields_in_query(build,
with: %w[notes notes_internal])
end
end
end
end
end
......@@ -133,6 +157,8 @@
allow(helper).to receive(:vectors_supported?).with(:elasticsearch).and_return(true)
allow(::Elastic::DataMigrationService).to receive(:migration_has_finished?)
.with(:add_embedding_to_work_items).and_return(true)
allow(::Elastic::DataMigrationService).to receive(:migration_has_finished?)
.with(:add_notes_to_work_items).and_return(true)
end
context 'when we cannot generate embeddings' do
......@@ -193,7 +219,7 @@
simple_qs_with_boost = {
simple_query_string: {
_name: "work_item:match:search_terms",
fields: ["iid^3", "title^2", "description"],
fields: ["iid^3", "title^2", "description", "notes", "notes_internal"],
query: query,
lenient: true,
default_operator: :and,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment