Searches for a literal string in the file content of repository branches, returning the paths and line numbers it was found on. The index behind it is entirely content addressed - see {@link RepoSearchStore} - which is what keeps it consistent with the repository without a transaction of its own. A directory hash is derived from its whole subtree (see DataSession.recalcHashes), so a branch's root hash identifies its complete set of files exactly, and the flattened file list is stored against that root hash rather than against the branch. The branch to root hash pointer is read from the database through the caller's own Hibernate session, so a search sees exactly what that transaction sees. A search first makes sure every branch in scope is indexed, building any that are not before answering, so results are always complete rather than reflecting whatever the index happened to have caught up with. Once indexed, a query reads posting lists for the rarest trigrams of the search text and only ever opens the handful of files those point at - it never walks a tree or reads content in bulk, so a cold server answers as quickly as a warm one.
Group: Managers
Properties
| Property | Returns | Description |
|---|---|---|
| indexedFileCount | long | The number of distinct file contents in the index, for reporting and diagnostics. |
| indexedTrigramCount | long | The number of distinct trigrams in the index, for reporting and diagnostics. |
| maxResults | int | The most matches a single search will return. A search stops once it has this many, so a caller which gets this many back has been given a truncated view and should say so rather than presenting it as the complete set. Exposed so callers can test against it instead of repeating the number, which would drift the moment this one changed. |
| warmingStatus | String | What the background warming thread is doing, for the maintenance pages. |
Methods
search(String searchText, String repoNameRegex, boolean liveOnly)
Returns: List<PathMatch>
Searches the branches of every repository in the current organisation whose name matches the given pattern. The pattern is treated as a regular expression, matched anywhere in the repository name. If it is not a valid regular expression it is treated as a glob instead, so a pattern like *-lib works as written. An empty pattern matches every repository.
| Parameter | Description |
|---|---|
searchText | the literal text to look for in file content, case insensitively. Must be at least three characters, which is the size of the index's trigrams; anything shorter returns no results |
repoNameRegex | a regular expression or glob matched against repository names, or empty for all of them |
liveOnly | when true only each repository's live branch is searched, otherwise all of its branches are |
search(String searchText, Branch branch)
Returns: List<PathMatch>
Searches the file content of a single branch.
| Parameter | Description |
|---|---|
searchText | the literal text to look for in file content, case insensitively |
branch | the branch to search |
search(String searchText, Branch branch, String dirPath)
Returns: List<PathMatch>
Searches the file content of a single branch, restricted to one directory and everything below it.
| Parameter | Description |
|---|---|
searchText | the literal text to look for in file content, case insensitively |
branch | the branch to search |
dirPath | the directory to search within, or empty for the whole branch |
sync(Branch branch)
Returns: int
Indexes a branch's current head if it is not already indexed, so that a later search of it does no build work. Searching does this itself when it needs to, so calling this is never required for correctness. It exists so a commit hook can move the cost off the next search.
| Parameter | Description |
|---|---|
branch | the branch to index |
getMaxResults()
Returns: int
The most matches a single search will return. A search stops once it has this many, so a caller which gets this many back has been given a truncated view and should say so rather than presenting it as the complete set. Exposed so callers can test against it instead of repeating the number, which would drift the moment this one changed.
getIndexedFileCount()
Returns: long
The number of distinct file contents in the index, for reporting and diagnostics.
getIndexedTrigramCount()
Returns: long
The number of distinct trigrams in the index, for reporting and diagnostics.
getWarmingStatus()
Returns: String
What the background warming thread is doing, for the maintenance pages.