
Code Search in Bitbucket Server
I am pleased to share the news, which, I hope, will please some Habr readers: in Bitbucket Server , a code search is about to appear. The other day, an Early Access Program (EAP) release was released .
I’ll start with a free translation of the product manager’s appeal published on the Atlassian blog :
How often this happened to you: you see an error message, but don’t know in which part of the code it occurs, or you know the name of the function, but not the repository in whose code it is defined. Many of you have asked for a code search to be added to Bitbucket Server, and I am pleased to announce that your expectation has come to an end. Today, we invite our users to try out the code search on Bitbucket Server through the Early Access Program (EAP). Now you can search and find the desired code using the search bar:How it works?
We understand that many teams have a huge amount of code. Therefore, we made it so that you can easily limit the search results to a specific project or repository using search filters. In addition, you can search for code in a given language (for example,lang:java
) or in files with a specific extension (for example,ext:css
).
The operatorsAND
,OR
andNOT
will help clarify the query, they are useful for further filtering the search results in the case when there are too many of them.What to do to start using?
Glad you asked! Here you can download the Bitbucket Server EAP distribution with support for code search, and the step-by-step instructions prepared by us should help with the launch and configuration . We will be grateful if you tell us about your impressions of the EAP distribution - your feedback is extremely important to us. By filling out this short and simple questionnaire , you will help us improve the search for you and other Bitbucket users for its official release.
We are working to make you more happy soon. Have a nice search!
Steve king
TL; DR
In a brief retelling, the installation instructions come down to the following steps:
- Install Git and Perl (more about installing Git here )
- Download the desired distribution from the EAP page
- Launch the installer (if you are using a ZIP distribution, you will have to perform a few preliminary steps manually before starting Bitbucket Server )
- Complete the installation procedure and wait for the Bitbucket Server to start.
- ???
- PROFIT !!!
How is the search arranged?
As you can see from the help pages and the contents of the distribution kit, Elasticsearch is used to store the index with which it searches . It, in turn, is based on the famous Apache Lucene library .
Two modules provide search in Bitbucket Server: the first deals with indexing repositories, the second serves search queries from users. Indexing is constantly in the background. If you upgrade Bitbucket Server, which already contains a certain number of repositories, the initial indexing may take some time, but as soon as it is completed, subsequent changes are processed very quickly. It is worth noting that the search is available immediately, but while indexing is in progress, its results may be incomplete. In addition, in order to optimize performance, a small delay was introduced between the moment the repository was changed (for example, committing a new code) and the moment when this change is reflected in the search results. By default, this delay can reach 15 seconds.
The installation procedure, in comparison with previous versions of Bitbucket Server, has not changed: all configuration actions necessary for the search to work are performed automatically. At the same time, it is not necessary to use the built-in instance of Elasticsearch: if you wish, you can configure the required configuration yourself.
What exactly can you look for?
Search has a number of limitations:
- Only main branch files are indexed (in most repositories this is
master
, although this is not the rule) - Indexed text files less than 512 Kb
- Mask search is not supported (for example,
qu?ck buil*
) - Regex search not supported
- All punctuation marks are removed from the request.
- Case insensitive search
- A query cannot have more than ten expressions - combinations of terms and operators
- The maximum request length is limited to 250 characters
The search query must contain at least one term, which can be a word or a quoted phrase.
Operators
Operators can be added to the query to refine the search. Here is their current list:
Operator | Request example | Value |
---|---|---|
AND | bitbucket AND server | Matches files containing both the words "bitbucket" and "server" |
OR | bitbucket OR server | Matches files containing at least one of the words "bitbucket" or "server" |
NOT | bitbucket NOT jira | Matches files containing the word "bitbucket" but not containing the word "jira" |
- | bitbucket -jira | Used before term; matches files containing the word "bitbucket" but not containing the word "jira" |
( ) | bitbucket AND (server OR cloud) | Matches files containing the word "bitbucket" and any of the words "server" or "cloud" |
A query can contain several terms, and by default, they are implicitly combined using a logical operator AND
. That is, a query is bitbucket server
equivalent to a query bitbucket AND server
.
Modifiers
Modifiers help limit your search. They are recorded in format модификатор:значение
. If the query contains several modifiers, they are implicitly combined using the operator AND
and applied to the entire expression. The following modifiers are currently supported:
repo:
orrepository:<ключ_репозитория>
- search in a specific repository. Requires a modifierproj:
that identifies the project. For example, you can find files in the “atlassian” bitbucket repository that contain the word “jira” using any of the following search queries:jira repo:bitbucket proj:atlassian
jira repository:bitbucket project:atlassian
jira repo:atlassian/bitbucket
proj:
orproject:<ключ_проекта/ключ_репозитория>
- search in all repositories of a specific project. For example, you can find files in the "atlassian" project containing the word "jira" using any of these search queries:jira proj:atlassian
jira project:atlassian
File Extension and File Language Modifiers
Search may be limited by languages and file extensions. These two criteria are identical for some languages, for example, modifiers lang:clojure
, and ext:clj
lead to the same result. However, there are some languages that have multiple file extensions, for example, expansion .hs
and .lhs
used in the Haskell, and the files with any of these extensions will be included in search results with the modifier lang:haskell
.
lang:
orlanguage:<язык>
- search for files in a specific language. The language corresponds to a set of extensions. For example, the following queries will find files in LaTeX format (that is, having the extension.ltx
,.tex
or.text
) containing the word "jira":jira lang:latex
jira language:latex
ext:
orextension:<расширение_файла>
- search for files with a specific extension. For example, you can find files containing the word "jira" and having the extension.lhs
using any of these queries:jira ext:lhs
jira extension:lhs
Just in case, I’ll note that the instructions on the help pages provided in the near future will be finalized to make the installation, configuration and use of the search in Bitbucket Server even better. Let me remind you that your comments regarding any aspects of using the EAP release are warmly welcome .
For me, this news is especially pleasant and important because I am directly involved in the development of the search. I will be glad to answer any questions and comments.