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

GitHub Code Search: Find more, search less - GitHub launches search engine

Published in the Random EN group
Hello everyone, dear friends! As a lover of new features on GitHub, it was very interesting for me to know that soon we will all be able to quickly and efficiently search the GitHub codebase. This can be very handy, especially if you need to find a sophisticated way to use a tool. “GitHub Code Search: Find more, search less” — GitHub launches search engine - 1This especially resonates with the fact that a future competitor to GitHub has been opened in Russia. Therefore, GitHub is definitely not worth resting on its laurels, despite the fact that they are undoubtedly market leaders. We need to go further and develop, otherwise the hour is not even and competitors will catch up and sweep away. And don't let it seem so unbelievable. 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 field of statistical error.

First impression

GitHub has created a project where you can search, navigate, and analyze your code and the billion 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 customization (we hope that the list will grow in the future). You can search by regular expression, which is very cool. Other filters are also available:
  • by organizations;
  • 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 ability to create complex search queries in which we can clearly define the boundaries for which we need to search. The second important part of the engine is code navigation 😳 Why are development environments convenient and why do they pay money for them? Because they make our life easier, help us navigate through the code, so that the speed of developing and reading the code grows. And this cool feature is now offered to us by GitHub. It's 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 raw. That is, without a development environment, you can search for where certain methods are used, where they are defined. It's just wonderful. GitHub you make me happy. Navigation through imports in classes is also available. This solves a lot of problems in finding and exploring 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 the search

It is very interesting to look in and try to search for yourself: is it as convenient as they say? So far, this feature is not in the public domain and you can add yourself to the waiting list using the link . There we fill in all the points, the questions are simple, I will not describe here. As a result, we are added to the waiting list and move on. As a result, there will be such an answer: “GitHub Code Search: Find more, search less” — GitHub launches search engine - 2It remains just to wait. As soon as they add me, I will definitely show you everything. Do not delay, add yourself so that later you can figure it out in the forefront and use it for your own joy) And of course it’s a pity that you can’t immediately try out a new tool, so we’ll analyze their documentation and describe in more detail how we can use this tool for our work. Now about the search. In it I will use classes and constructions that make sense inlibrary that I write. This will make it clearer and easier for me, and I hope you will too.

Basic search

ImageComparison is the simplest search that searches exactly as requested in filenames and their contents. Everything here seems very simple. If we want to find clearly by the name of the class, 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 separately: Image Comparison , that is, it will find files and code for both Image and Comparison . If you need to search for some string containing spaces, then you just need to use quotes for this. For example: “ImageComparison comparison = new ImageComparison()”and then the search will go to match the entire string. For escaping, we use “\” as always. So far, everything is intuitive and often done that way. Further, we can add filters to this basic search. So let's talk about each of them. These will be logical “ANDs” to the filter we have already created.

Filter by repository

When our basic filter is ready, we can narrow down the search and search for a specific repository, which is very convenient. You don't need to look for what folder the class is 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 OR:
repo:romankh3/image-comparison OR repo:romankh3/usage-image-comparison ImageComparisonResult
As stated on GitHub, at the moment they do not support searching through repositories where the name is specified as a regular expression ... And this means that they plan to add such an opportunity and means that the project will not stop at the declared functionality and will develop further.

Filter by organization

Searching for an organization or user is done in the same way as searching for a repository, only the keyword will not be repo , but org :
org:romankh3 ImageComparison
And then the search will go through all the 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 key word 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
The full 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 can also be searched by adding a filter. For example, there is an ImageComparisonResult file , it has a path:
src/main/java/com/github/romankh3/image/comparison/model/ImageComparisonResult.java
So, to find all classes whose path starts with src/main/java/com/github/romankh3/image , you need:
path:src/main/java/com/github/romankh3/image
Can be useful when we don't want test classes to be excluded from our search. Or vice versa, just tests. This makes the search more flexible. The file path filter 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 bringing it all together with Boolean operations. For this we have AND, OR, AND NOT. I think this should be enough for us. For example, let's make a complex search query: Java or Kotlin production code from a specific user/organization:
repo:romankh3 AND (language:java OR language:kotlin) AND NOT path:*/test/*
And let me tell you, it's just incredible. So simple, fast, concise and understandable is the search request that there will be no problems in searching and reading the request.

small digression

While our enthusiasm has not yet cooled down, we want to return 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 fate is the path of the second Skype? How did everyone start migrating their projects to GitLab? But why hide it, on the wave of this hype, I created and endured something. But to be honest, I never again visited the place where I transferred the projects. And somehow I don't want to. And why? There are also thoughts about it. Let me remind you that after the sale of GitHub to Bill Gates, the ability to have private repositories for free was added to the project, GitHub Actions for the CI / CD process were released, and much more. And now also a powerful search engine. It doesn't look like wanting to sink the project. It's more like that Microsoft did not 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 also decided to develop this project. And it's true, for an open-source developer, this is a great place to store your code. You can fully engage in product development without leaving GitHub.

At the end

Wrote the article in one breath. I love it when words and emotions just geyser. This is what drives technology forward. So we keep our finger on the pulse, do not let go of the situation. I am sure that each of us should learn how to use it. For anyone who hasn't signed up to 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 of interest to me from the world of development and IT in general. We have over 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, don't say goodbye 👌
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION