Google Cloud Platform (GCP) users who store significant amounts of code within cloud source repositories will now be able to search their code base with a new user interface and semantic code search toolkit.
The new code search capabilities offered in Google’s Cloud Source Repositories (CSR) is designed using the same infrastructure technology as Google’s Search engine. The technology has been tweaked so that it is optimised for searching code with changes in the algorithms and indexing processes.
Russell Wolf Product Manager at GCP wrote in a blog that: “When you submit a query, that query is sent to a root machine and sharded to hundreds of leaf machines. It looks for matches by file names, classes, functions and other symbols, and matches the context and namespace of the symbols.”
“If regular expressions are specified in that query, our code search runs an optimized algorithm to quickly find potential matches for the regular expression. Then, it refines results against the full regular expression to find the actual matches.”
The search toolkit then refines the results in a comparison to a full regular expression to find matches, in order to give you extra context it will also show you what it thinks are relevant snippets of code in relation to your search.
Code Search: Use Cases
In a developer case study investigating how developers implement searches for code researchers learned that: “Code search is integrated in many development activities, from helping someone with a task to reviewing code, from finding an example to finding who was responsible for a change.”
“We also learn that a search session is generally just one to two minutes in length and involves just one to two queries and one to two file clicks.”
Users accessing the CSR to initiate code searches will only be shown the code that is within their access privileges. So enterprise will not have to set up additional permissions or security around who can search what.
Wolf gave the following example of how the tool might be used: “You want to search across all the code at your company, but there are a lot of repositories with only a few stored locally—which aren’t up-to-date with the versions on the server. Storing code locally isn’t a great option, and your computer’s search tools aren’t very powerful. When you’re using Cloud Source Repositories, the default branches of all repositories are always indexed and up-to-date. It’s simpler and faster to search across all the code you have access to for a particular file/class/function, rather than hunting for the code you have stored locally.”
Mr Wolf also notes that: “Cloud Source Repositories can search across thousands of different repositories with a single query. You can search for either files or code within files in the default branch of your repository.”
Users can create a new empty repository or they can mirror their code from platforms such as Github and Bitbucket. Google customers already using Cloud Source Repositories will encounter a new landing page personalised to them.