Query the notes index for related issues
What does this MR do and why?
This MR introduces the ability to search for issue notes when searching for issues. This is only backend changes, there are no UI changes or any indication that the issue was returned because of a note match.
This is being done because the alternative approach to store notes in the work_items (issues) index did not work.
Everything is behind a feature flag.
AI Summary
This change enhances GitLab's search functionality by allowing issue searches to also find issues mentioned in notes. When a user searches for content, the system will now look not only at the issue title and description but also at related notes, making search results more comprehensive.
The implementation adds a new feature flag called search_work_item_queries_notes
that controls this behavior. When enabled, the search system collects issue IDs from notes matching the search query and includes those issues in the results. The code also refactors the search query building process to make it more maintainable, extracting common functionality into helper methods.
The changes include updates to the Elasticsearch filters and queries to support this new capability, along with appropriate tests to verify the functionality works as expected. The code is structured to maintain backward compatibility while adding this new search enhancement.
References
- Search / filter issues does not search issue co... (#15645 - closed) (original issue)
- #508906 (closed) (issue detailing the issues with the other approach including a closed MR)
- Refactor lazy_user_notes and replace db index (!185362 - closed) (last MR that was closed in favor of this MR)
Screenshots or screen recordings
Before | After |
---|---|
![]() |
![]() |
How to set up and validate locally
- enable gdk for elasticsearch
- index the instance using admin ui - search - advanced search --or-- by running
gitlab:elastic:index
rake task - pick a few issues in a group or project
- add a comment to each issue (make sure the comment text isn't in the title or description)
- perform an issue search at each level, the issues should not come back in the result
- global
- group
- project
- enable the feature flag
search_work_item_queries_notes
- perform the same searches
- global (this remains the same, issues will not come back for global search)
- group (issues should come back)
- project (issues should come back)
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.