Google announced it is bringing code search in beta availability with the newly revamped Cloud Source Repositories. The overhaul of the service features an entirely new user interface and semantic code search capabilities.
The Google Cloud Blog announcement post states that the code search functionality is powered by the same underlying infrastructure that Google engineers perform their code searches on every day. Furthermore, code search in Cloud Source Repositories also uses the same document indexing and retrieval technologies that Google use for their Search. The Google Cloud team believe that this service can improve developer productivity, whether the code resides in Cloud Source Repositories or a developer mirrors their code from the cloud versions of GitHub or Bitbucket.
With Cloud Source Repositories developers have the benefit of leveraging the Google Search technology for their code base search - using a single query over all owned repositories. Furthermore, Cloud Source Repositories take identity and access management (IAM) permissions into account and do not show any code to developers who do not have access to view it. Also, Cloud Source Repositories support RE2 regular expressions in search patterns, allowing developers to perform complex search queries.
When a developer submits a search query in code search, that query goes to a root machine and is sharded to hundreds of leaf machines. The query processing involves matching by file names, classes, functions and other symbols, and matching of the context and the namespace of the symbols. Note that search works across all languages. However, the semantic understanding of sources which enhances search is limited to Java, JavaScript, Go, C++, Python, TypeScript and Proto files.
If a developer uses a regular expression, then the code search runs an optimized algorithm to find potential matches for the regular expression quickly. It can also refine the results against the full regular expression to find the actual matches. Russell Wolf, product manager, said in a Hacker News thread on the announcement of Cloud Source Repositories in beta:
The more code you have, the more benefit you get from having fast search tools across your entire code base that can perform complex semantic and regular expression queries. Even with smaller codebases, I find it the fastest way to find the code I need.
Developers can try Cloud Source Repositories through the Google Cloud Platform (GCP) free trial and free tier. Furthermore, developers can create a new empty repository or mirror their code from the cloud version of GitHub or Bitbucket.