Last year we shipped the highest requested feature for Bitbucket Cloud – code aware search, and we’re delighted with your feedback and responses.
We’re excited to announce that we’ve published the Bitbucket Cloud code search API delivering the same love to machines, and opening up code search for your needs.
All code search features and more
Our goal for the code search API was simple – to give consumers access to all search features they already know from the Bitbucket UI. That includes account scopes, powerful query language and modifiers. So how would the search for the common class QueryBuilders on the Elasticsearch repo look like?
You can get same results by making a request to:
https://api.bitbucket.org/2.0/teams/%7B6f461d1e-a3dd-433b-a0e3-7a69daf6ea47%7D/search/code?search_query=repo%3Aelasticsearch%20QueryBuilders
where search_query is just urlencoded version of:
repo:elasticsearch QueryBuilders
Match highlighting
We haven’t forgotten about search result highlighting. With the new code search API, consumers will get access to that information as well.
and this is how it’s going to be represented in the response body:
Match highlighting
{
"content_matches": [
{
"lines": [
{
"line": 39,
"segments": [
{
"text": " */"
}
]
},
{
"line": 40,
"segments": [
{
"text": "public abstract class "
},
{
"text": "QueryBuilders",
"match": true
},
{
"text": " {"
}
]
}
]
},
{
"lines": [
{
"line": 728,
"segments": []
},
{
"line": 729,
"segments": [
{
"text": " private "
},
{
"text": "QueryBuilders",
"match": true
},
{
"text": "() {"
}
]
}
]
}
]
}
For a full list of the capabilities and search query considerations with code search in Bitbucket Cloud, check out our documentation. If you're ready to use a fast and relevant code search, sign up for a Bitbucket Cloud account, create a repository, and index your code. If you’re already a Bitbucket customer, you can start using code search API today!
What will you build?
If you have feedback about code search or anything else Bitbucket related, hit us up on Twitter – we’d love to hear what you’ve got planned for the API.