Add highlights to blob search graphql response
What does this MR do and why?
Highlighting is being moved from the backend to frontend for exact code search due to performance issues.
This MR has a few changes:
- Add the array of match start/end characters as
highlights
to the response. frontend will use this for match highlighting - Add language to each file response. frontend will use this for syntax highlighting
- Fixes errors when empty search results class is returned to multi match (ran into this while testing locally)
References
Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.
- Related to #508567
- #501284 (closed)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
N/A
How to set up and validate locally
- enable zoekt for gdk
- enable ff
zoekt_cross_namespace_search
for global search - setup a group (I used flightjs for this) and ensure it has one group with a repository
validating the highlights field
- test in graphql explorer to test global, group and project search
- ensure highlights come back appropriately. they should contain the start/end characters for highlight. The highlights can also be seen in the
richText
field surrounded by<b>
and</b>
tags
You can test using the query below (project level). Remove projectId
to test group level and both projectId
and groupId
to test global level.
validating empty search results.
- test in graphql explorer with the search term
not
- if you run the same search on the
master
branch, it will throw a method not found
{
blobSearch(search: "test",
groupId: "gid://gitlab/Group/33")
projectId: "gid://gitlab/Project/7") {
matchCount
perPage
fileCount
searchType
searchLevel
files {
path
fileUrl
language
chunks {
matchCountInChunk
lines {
lineNumber
highlights
text
richText
}
}
}
}
}
Edited by Terri Chu