Code search

Note

Helix TeamHub supports code searching for Mercurial, Git, and Helix Git repositories.

The code is indexed from each repository's default branch. You can configure the default branch for each repository from the repository settings view.

Code search can be performed on the following levels:

  • Company level (all repositories within the company)
  • Project level (all repositories within one or multiple projects)
  • Repository level (one or multiple repositories)

Enabling code search

You must have company administrator privileges to enable code search.

Note

On-premise customers will first need to setup and configure Elasticsearch to their Helix TeamHub instance. To learn more, see Code search in Instance administration. If you require further assistance, please don't hesitate to contact support.

To enable code search:

  1. Access the Company Settings view using the user dropdown list in the header or from the My Dashboard tab.

    Avatar dropdown

  2. In the Features tab, turn on Code Search and click Save.

    Company settings

Once code search is enabled, TeamHub indexes all repositories within the company. Depending on the amount of data to process, the indexing operation might take a while. You can monitor the current progress on the My Dashboard tab. When done, the indicator on the right displays Indexing complete.

Tip

Code search can be disabled for individual repositories in the company if required, see Code Search in the Maintenance tab of the Repository settings form.

Company stats

For information on other features that company admins can configure, see Feature settings.

Searching

You can begin a code search from any view. To search the code:

Tip

You can limit code searches by path/filename, make advanced searches, and filter your search results, see Limiting a code search, Advanced searches, and Filtering search results.

  1. Click the search icon in the site header.

  2. In the search field, enter your search term and press Enter.

    Search bar

    TeamHub displays the search results in a separate view.

    Search results

    By default, TeamHub displays only the matching code lines.

    Search controls

  3. To view the full search context, click the arrow icon beneath the result.

  4. To see more results, use the pagination controls at the bottom of the page.

Limiting a code search

You can limit code searches to a path, a filename, or a filename in a path by entering your search term followed by the path, filename, or path and filename.

Tip

More than one path and filename can be entered for a search term.

Limit a code search to a path

For example, String.prototype.includes path:app/utilities followed by Enter, TeamHub creates the path as a tag:

Wildcards are supported in the path.

Limit a code search to a filename

For example, String.prototype.includes filename:test.js followed by Enter, TeamHub creates the filename as a tag:

The filename is only searched if an exact match is found. Wildcards are not supported for filenames.

Limit a code search to a filename in a path

For example, String.prototype.includes filename:test.js path:app/utilities followed by Enter, TeamHub creates the filename as a tag and path as a tag:

The filename is only searched if an exact match is found and the filename is in the path. Wildcards are not supported for filenames.

Advanced searches

You can use special characters to make your results more relevant.

Search for an exact match

To search for an exact match, surround your search term with quotes ". For example, to find results that exactly match String.prototype.includes enter the following search term:

"String.prototype.includes"

Note

In most cases, wrapping your search term in quotes will result in exact matches for your search query. However, due to the way that Elasticsearch indexes and creates its "phrase query" for your search term, it can result in unexpected search results.

For example: searching for "String.prototype.includes" could result in the following being displayed in the search results:

  • String.prototype.includes - expected
  • String.PrototypeObject.includes - not expected
  • StringTheory.prototype.includes - not expected

Search for term-x and term-y (AND)

To find results that contain term-x and term-y, separate your search terms with a space. For example, to find results that contain String and prototype enter the following search term:

String prototype

Search for term-x, term-y, or both (OR)

To find results that contain term-x, term-y, or both, separate your search terms with a pipe | character. For example, to find results that contain String, prototype, or both enter the following search term:

String | prototype

Search for term-x but exclude results that also contain term-y

To find results that contain term-x but exclude those that also contain term-y, use the minus - character in front of the term you want to exclude it. For example, to find results that contain String but not prototype enter the following search term:

String -prototype

Filtering search results

You can narrow down search results by specifying which projects and repositories to include.

TeamHub applies the following filters automatically based on the view from which you invoke the search:

  • Browsing a project sets the current project as the filter.
  • Browsing repository views or the project's wiki sets the repository as the filter.

You can clear these filters in the results view.

Invoking a search from the company scope does not set any filters. Instead, TeamHub searches within all projects and repositories to which you have access. To make sure you are at the company scope level, click the company name or logo in the top left corner.

Search filters

In addition to the project and repository filters, you can define whether to include or omit results from forked repositories using the dropdown list on the right.

The numbers next to the filters indicate the number of results for each project and repository. Note that by selecting a project, you are effectively searching in all repositories within that project. To restrict the search to specific repositories, first remove the project filter.

If you have multiple repositories with the same name in several projects, you can narrow down the search using the following syntax: project:repository. For example, to search repositories starting with bat in a project called Amazing, enter the following string in the search field: amazing:bat

Searching repositories inside a project

To view a project's identifier, go to the Projects tab or move your pointer over the project name.