search: add ability to get description match ranges in `RepoSearchJob`
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 torepoStore
- 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 toRepoSearchJob
- This method wraps
GetRepoDescriptionsByIDs()
so we can get repo descriptions and match against them duringRepoSearchJob
.
- This method wraps
- Add
descriptionMatchRanges()
method tojobutil/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
onresult.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.
- 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
Test plan
Added unit tests. This code is currently not used anywhere.