Code search in Bitbucket

ALPHA Bitbucket Cloud Code Search is currently in Alpha.

We're excited about this and are pushing to make Code Search generally available soon!

Search for code in Bitbucket Cloud

Here's how you can use Bitbucket Cloud's search to find exactly what you're looking for. You can use either a single word or a phrase in quotes when searching. 

Search when viewing a repo

When you're already looking at a repo, use search from the sidebar. The search context is just that repo:

 

Search at the account level

When you're at the top level of an account, use search from the header. The search context is all the repos in the account:

 

Account scopes

If you signed up for Search Alpha, you'll get search results from the repos in all the accounts you are a member of, including your own personal account.

Other members of your team accounts will also be able to search in the accounts they usually have access to, even if they haven't signed up for Alpha.

 

Operators

Search operators can be used to refine the results. Operators must be in ALL CAPS.

The following search operators are available: 

  • AND
  • OR
  • NOT
  • -
  • (  )

When multiple search terms are used, they form a boolean query that implicitly uses the AND operator. So a query for bitbucket cloud is equivalent to bitbucket AND cloud.

Operator
Example query
Results
AND bitbucket AND jira Matches files that contain both bitbucket and jira.
OR bitbucket OR jira Matches files that contain either bitbucket or jira (or both).
NOT bitbucket NOT jira Matches files that contain bitbucket but don't contain jira.
- bitbucket -jira Used before a term; matches files that contain bitbucket but don't contain jira.
( ) bitbucket AND (jira OR hipchat)

Matches files that contain bitbucket and either jira or hipchat.

Phrase queries

A phrase query can be used to find multiple words that appear in a certain order. You just need to enclose the words in double quotes (").

For example, with this search query:

abstract class

Search results will include files that contain both these words anywhere.

However, using a search query with quotes:

"abstract class"

The search results will only contain files that have the word abstract followed by the word class (or part of a word). Note that this will find things such as "abstract(class" as well as "abstract class".

 

Modifiers

Modifiers can be used to further refine search results. Use a modifier in the form key:value. If there are multiple modifiers in a query they are implicitly combined using AND, and apply to the whole search expression.

Language and file extension modifiers

Code search can be restricted to only consider a particular language or a particular file extension. For some languages, adding a language criteria is equivalent to specifying the file extension. For example, lang:java  is equivalent to ext:java. For other languages, multiple file extensions are mapped to a single language. For example, the .hs.lhs and .hs-bootare file extensions are used for the Haskell programming language, and will be matched when specifying lang:haskell.

 

Modifier
Example query
Results

lang: <language> 

or 

language:<language>

jira lang:c

Matches C files with the .c or .h extensions that contain the term jira.

ext: <file extension> 

or 

extension:<file extension>

jira ext:lhs Matches Haskell files with the .lhs extension that contain the term jira.

Search query considerations

There are some things to consider regarding how searches are performed:

  • Search uses the default branch in a repo (usually the default branch will be master).
  • We index files smaller than 320 KB – you won't see search results from larger files.
  • Wildcard searches (e.g. qu?ck buil*) are not supported.
  • We strip the following characters from search terms:   !"#$%&'()*+,/;:<=>?@[\]^`{|}~
  • Regular expressions are not supported in queries, but you can search for special characters.
  • Case is not preserved (but search operators must be in ALL CAPS).
  • Queries can have up to 9 expressions (i.e. combinations of terms and operators).
  • Queries can be up to 250 characters in length.
  • We make sure that you only see the code you have permission to view in search results.

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport