Skip to content

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.

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

  1. enable zoekt for gdk
  2. enable ff zoekt_cross_namespace_search for global search
  3. setup a group (I used flightjs for this) and ensure it has one group with a repository

validating the highlights field

  1. test in graphql explorer to test global, group and project search
  2. 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.

  1. test in graphql explorer with the search term not
  2. 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

Merge request reports

Loading