Hello everyone, dear friends! As a lover of new features on GitHub, I was very interested to know that soon we will all be able to quickly and efficiently search the GitHub code base. This can be very convenient, especially if you need to find a sophisticated way to use a tool. This especially resonates with the fact that a future competitor to GitHub was opened in Russia. Therefore, GitHub definitely should not rest on their laurels, despite the fact that they are undoubtedly the leaders in the market. We need to move on and develop, otherwise it’s not even an hour and competitors will catch up and sweep away. And let it not seem so incredible. As an example: how many people still use Nokia phones? Who even knows they made phones? At one time they were simply unattainable, undisputed market leaders... And now they appear somewhere in the realm of statistical error.
First impression
GitHub has created a project where you can search, navigate, and analyze your code and the billions of lines of code published on GitHub. It is important to note that the search is scalable, fast and accurate. It was created from scratch specifically for code search. Navigation works for 10 major programming languages without settings (we hope that the list will grow in the future). You can search using a regular expression, which is very cool. Other filters are also available:- by organization;
- by programming languages;
- by specific owner;
- by file extension;
- by regular expression.
Let's talk in more detail about search
It’s very interesting to take a look and try to look for yourself: is it as convenient as they say? For now, this feature is not publicly available and you can add yourself to the waiting list using the link . We fill out all the points there, the questions are simple, I won’t describe them here. As a result, we are added to the waiting list and move on. As a result, the answer will be this: You just have to wait. As soon as I am added, I will definitely show you everything. Don’t delay, add yourself so that you can figure it out later and use it to your delight) And of course, it’s a shame that you can’t try out the new tool right away, so let’s analyze their documentation and describe in more detail how we can use this tool for our work. Now about the search. It will use classes and constructs that make sense in the library that I'm writing. This will make it clearer and easier for me, and I hope it will be easier for you too.Basic search
ImageComparison is the simplest search that searches exactly with the query in file names and in their contents. Everything seems very simple here. If we want to find clearly by class name, where it is declared and where it is used, such a search will help us with this. When you enter multiple words separated by spaces, the result will be a search for all of them separately: Image Comparison , meaning it will find files and code for both Image and Comparison . If you need to search for a string containing spaces, then you just need to use quotes. For example: “ImageComparison comparison = new ImageComparison()” and then the search will match the entire string. For escaping, we use “\” as always. So far, everything is intuitive and that’s often how it’s done. Further, we can add filters to this basic search. Therefore, let's talk about each of them. These will be logical “ANDs” to the filter we have already created.Filter by repository
Once our basic filter is ready, we can narrow our search and search by specific repository, which is very convenient. You don’t need to look for which folder the class is located in, you can just write:
repo:romankh3/image-comparison ImageComparisonResult
Where we need to specify repo:${user_name}/${repo_name} . You can also search across multiple repositories by simply adding an OR:
repo:romankh3/image-comparison OR repo:romankh3/usage-image-comparison ImageComparisonResult
As indicated on GitHub, at the moment they do not support searching in repositories where the name is specified as a regular expression... This means that they are planning to add such a feature and it means that the project will not stop at the declared functionality and will develop further.
Filter by organization
Searching by organization or user is done in exactly the same way as searching by repository, only the keyword will not be repo , but org :
org:romankh3 ImageComparison
And then the search will go through all repositories of the user/organization.
Filter by programming languages
You can also specify a search for files in a specific programming language. Here the construction is the same as for the repository and organization, only the keyword is language :
language:java ImageComparison
Just like for the repository, it supports searching in several languages at once using the OR keyword:
language:java OR language:ruby ImageComparison
A complete list of languages supported by GitHub can be found here . I wonder if BrainFuck is there? 😂
Filter by file path
Each file in the project has its own path and you can also search through it by adding a filter. For example, there is a file ImageComparisonResult , it has the path:
src/main/java/com/github/romankh3/image/comparison/model/ImageComparisonResult.java
So, to find all classes whose path begins with src/main/java/com/github/romankh3/image , you need:
path:src/main/java/com/github/romankh3/image
Can be useful in cases where we don't want test classes to be left out of our search results. Or vice versa, only tests. This makes your search more flexible. A filter by file path can be specified using a regular expression. For example, we need to find
path:src/*/*.js
Boolean operations
And of course, the culmination of all filter building is combining this matter together using Boolean operations. For this we have AND, OR, AND NOT. I think this should be enough for us. For example, let’s create a complex search query: code from Java or Kotlin production for a specific user/organization:
repo:romankh3 AND (language:java OR language:kotlin) AND NOT path:*/test/*
And this, I tell you, is simply incredible. The search request is written so simply, quickly, concisely and clearly that there will be no problems in searching and reading the request.
GO TO FULL VERSION