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:

    Search line



    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).

    Search filters

    The operators AND, ORand NOTwill help clarify the query, they are useful for further filtering the search results in the case when there are too many of them.

    Logical operators

    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:


    1. Install Git and Perl (more about installing Git here )
    2. Download the desired distribution from the EAP page
    3. Launch the installer (if you are using a ZIP distribution, you will have to perform a few preliminary steps manually before starting Bitbucket Server )
    4. Complete the installation procedure and wait for the Bitbucket Server to start.
    5. ???
    6. 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 .


    Elasticsearch

    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:


    OperatorRequest exampleValue
    ANDbitbucket AND serverMatches files containing both the words "bitbucket" and "server"
    ORbitbucket OR serverMatches files containing at least one of the words "bitbucket" or "server"
    NOTbitbucket NOT jiraMatches files containing the word "bitbucket" but not containing the word "jira"
    -bitbucket -jiraUsed 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 serverequivalent 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 ANDand applied to the entire expression. The following modifiers are currently supported:


    • repo:or repository:<ключ_репозитория>- search in a specific repository. Requires a modifier proj: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:or project:<ключ_проекта/ключ_репозитория>- 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:cljlead to the same result. However, there are some languages that have multiple file extensions, for example, expansion .hsand .lhsused in the Haskell, and the files with any of these extensions will be included in search results with the modifier lang:haskell.


    • lang:or language:<язык>- 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, .texor .text) containing the word "jira":


      • jira lang:latex
      • jira language:latex

    • ext:or extension:<расширение_файла>- search for files with a specific extension. For example, you can find files containing the word "jira" and having the extension .lhsusing 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.


    Also popular now: