JavaRush /Java Blog /Random EN /GitHub Code Search: Find more, search less - GitHub launc...

GitHub Code Search: Find more, search less - GitHub launched a search engine

Published in the Random EN group
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. “GitHub Code Search: Find more, search less” - GitHub launched a search engine - 1This 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.
The list is already impressive! It turns out that the search engine gives us the opportunity to create complex search queries in which we can clearly define the boundaries along which the search is needed. The second important part of the engine is code navigation 😳 What are development environments convenient for and why do people pay money for them? Because they make our life easier, help us navigate through the code, so that the speed of developing and reading code increases. And GitHub now offers us this cool feature. This is incredible. Yes, I know that at the moment there is already something similar to navigation in GitHub, but the functionality is still very short and crude. That is, without a development environment, you can search where certain methods are used, where they were defined. It's just wonderful. GitHub you make me happy. Navigation for imports in classes is also available. This solves many problems in finding and studying a particular library on GitHub. Now this process is accelerated many times over. And it's all free. Just excellent. Will he be in demand? I'm sure yes!

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: “GitHub Code Search: Find more, search less” - GitHub launched a search engine - 2You 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.

A small retreat

While our delight has not yet cooled down, I would like to go back to 2018 and remember something... Remember, when everyone found out that Microsoft was buying GitHub, everyone thought that the project would be buried? That his destiny is the path of the second Skype? How did everyone start moving their projects to GitLab? But let’s be honest, in the wake of this hype I created and suffered something. But to be honest, I never visited the place where I moved the projects again. And somehow I don’t want to. And why? There are also thoughts about this. Let me remind you that after the sale of GitHub to Bill Gates, the project added the ability to have private repositories for free, GitHub Actions were released for the CI/CD process, and much more. And now also a powerful search engine. This doesn't sound like a desire to sink the project. It’s more like Microsoft didn’t want to pay taxes on profits and made a successful purchase by the end of the year for more than 9 billion dollars 😁 And then after all this they decided to develop this project. And it’s true that for an open-source developer this is a great place to store their code. You can fully develop your product without leaving GitHub.

At the end

I wrote the article in one go. I really love it when words and emotions just flow like a geyser. This is what moves technology forward. So we keep our finger on the pulse and don’t let go of the situation. I am sure that each of us should learn to use it. For anyone who hasn't signed up for GitHub, I highly recommend doing so. It's worth it. As always, friends, do not forget to subscribe to my telegram channel , in which I combine all my public activities. In addition to the articles that I publish here, I write shorter posts there in which I touch on topics that interest me from the world of development and IT in general. There are already more than 800 subscribers there! And, of course, my GitHub account , where I publish all demo projects for articles, update my libraries and develop open-source organizations. That's all, thank you all for reading, let's not say goodbye 👌
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION