Skip to content

search: add ability to get description match ranges in `RepoSearchJob`

Administrator requested to merge tl/description-match-ranges into main

Created by: tbliu98

This PR adds code that enables getting match ranges for repo descriptions as part of RepoSearchJob, which will enable description match highlighting in the web app. This code is currently unused. I plan to actually add this step to RepoSearchJob after determining the best way to plug this into the web app. At that time, this extra step will only happen if repo:has.description was included in the original query.

Changes in this PR:

  • Add GetRepoDescriptionsByIDs() method to repoStore
    • This method takes a list of repo IDs, fetches those repo IDs and their descriptions from the database, and returns a map of repo ID to description. It's probably preferable to fetch this extra info here, only where we need it, and avoid doing something like growing the amount of information fetched during repo resolution.
  • Add repoDescriptions() method to RepoSearchJob
    • This method wraps GetRepoDescriptionsByIDs() so we can get repo descriptions and match against them during RepoSearchJob.
  • Add descriptionMatchRanges() method to jobutil/repos.go
    • This method actually does the work of matching repo descriptions against the description pattern in the original query. It takes a map of repo ID to description and a list of description patterns to match against, and returns a map of repo ID to []result.Range. I'm optimistic we can just treat repo descriptions coming from the database as a single-line string (in other words, Line on result.Range will always be zero and we'll just obtain a starting and an ending index for the matched range), but TBD if that will play nice with the web app.

Test plan

Added unit tests. This code is currently not used anywhere.

Merge request reports

Loading