Code search in Bitbucket

What's cool in Bitbucket Cloud code search

  • Search is code aware – search results are ranked so that function and type definitions are displayed before other results.
  • Operators and modifiers – you can use operators and modifiers to help you to refine search results.

Search in Bitbucket Cloud

Here's how you can use Bitbucket Cloud's search to find exactly what you're looking for – just click on the search icon under the Bitbucket icon:

As you'd expect, you can use either a single word or a phrase (in double quotes) when searching. 

 

Search scopes

The scope of a search changes according to where you are searching from:

Search context Search scope
An account Scope is all the repos in that account.
リポジトリ Scope is just that repo.

By the way, to search in public repos that don't belong to any of the accounts you have access to, just go to that repo and search there.

 

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, 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 also find things such as "abstract(class".

However, with this search query (no quotes):

abstract class

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

 

Search operators

Search operators can be used to refine the results:

  • Operators must be in ALL CAPS.
  • Operators can only be used with accompanying search terms.
  • Multiple search terms are implicitly combined using the AND operator. For example, a query for bitbucket cloud is equivalent to bitbucket AND cloud.

The following search operators are available: 

Operator
Example query
結果
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.

The following table contains examples of valid ((tick)) and invalid ((error)) search syntax:

Validity クエリ 結果
(tick) MyClass MyComponent
Finds files that contain the terms MyClass and MyComponent
(error) NOT "public class" You need to specify something to match before what to exclude
(error)

repo:foo AND MyClass

You cannot combine modifiers with logical operators

Search modifiers

Modifiers can be used to refine search results:

  • Use a modifier in the form key:value
  • You can combine multiple modifiers – see Use multiple modifiers below.

The following modifiers are available:

Modifier
Example query
結果

ext:<file extension> <searchterm> 

ext:lhs jira

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

lang:<language> <searchterm>  

lang:c jira

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

project:<project name> <searchterm>   project:myProject jira Matches files in myProject that contain the term jira.
repo:<repo name> <searchterm>   repo:repoA myClass

Matches files in repoA that contain the term myClass.

Wildcards are not supported in repo names.

Only the default branch of the repo is searched.

 

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-boot file extensions are used for the Haskell programming language, and will be matched when specifying lang:haskell.

Note that 'language' as used here is unrelated to the Language setting for a repository.

Click here to see all the languages recognized by code search...
ada asp.net assembly c c++ c# clojure cobol cql css cython fortran go groovy haskell html java 
javascript json kotlin latex less lisp markdown mathematica matlab objective-c ocaml pascal perl php plain plsql properties python r ruby rust sas scala scss shell sieve soy sql swift velocity xml yaml

Use multiple modifiers

When multiple modifiers are used in a query:

  • modifiers of the same kind are implicitly combined using OR
  • modifiers of different kinds are implicitly combined using AND
  • the modifiers apply to the whole search expression.

For example, this query:

repo:A repo:B ext:js ext:jsx search-term

... will match files with either the .js or the .jsx extension, that are in either repo A or repo B, and that contain the search-term. What you don't need to do is use search operators with multiple modifiers.

Note that when using the repo modifier more than once, all the repos must be in the same account.

The following table contains examples of valid ((tick)) and invalid ((error)) search syntax:

Validity クエリ 結果
(error) ext:js AND ext:jsx MyComponent You cannot combine modifiers with logical operators
(error) (ext:js MyComponent) OR (ext:java MyClass) You cannot combine modifiers with logical operators
(error) ext:js AND project:myProject MyComponent You cannot combine modifiers with logical operators
(tick) ext:js project:myProject MyComponent Finds files with the ext extension AND that are in the myProject project that contain the term MyComponent
(tick) ext:js ext:java MyComponent OR MyClass Finds files with the js OR java extension that contain the terms MyComponent OR MyClass

Code search 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.

Last modified on Aug 4, 2017

この翻訳に満足しましたか?

はい
いいえ
この記事についてのフィードバックを送信する

Not finding the help you need?

コミュニティへの質問

Powered by Confluence and Scroll Viewport.