Towards Natural Language Semantic Code Search at GitHub(githubengineering.com) |
Towards Natural Language Semantic Code Search at GitHub(githubengineering.com) |
GitHub search can't even search for a literal string, let alone a regex. It can't search a subdirectory. Ranking is indistinguishable from random. It's been this way for years. How about building an actual, usable, basic code search and then getting all fancy with your machine learning?
I almost built my own "online git grep for GitHub" last year.
Disclaimer: no affiliation, just love the team and product.
P.S. I'm not affiliated, we just use Sourcegraph at a company I work for.
Currently it runs on a fairly slow machine, so regex-heavy requests will take some time on big package repositories like Rubygems, but I plan to get a nicer machine soon.
If you know Scala, you can even contribute (wink wink), just ping me. A lot of tasks we have at this stage are pretty basic.
A good example is that GitHub's own repo for their CommonMark implementation isn't searchable, because it's a fork of cmark: https://github.com/github/cmark/
Take for example,
for(int i=0;i<100;i++)
And then a search for i++ Due to the way almost every search tool works that would be split into tokens "for int i 0 100" which are not very useful. Even if you include the characters = ; < + ( ) in the search you break the ability to do things such as boolean queries or fuzzy search term~1Its totally possible to solve these issues using tweaks of the input into your index, which is what I did with searchcode.com or with a different approach which is what Google Code Search did. However neither have a requirement to be 100% in sync with the repository which I suspect is something that the github team value.
All the code search tools suffer from this in some way. At small scale its possible to just brute force the search. At scale you can do it by tweaking your algorithm and sacrificing accuracy. My feeling is that the github team chose accuracy.
[0] https://github.com/etsy/hound`{search query} -site:github.com/{repo}/{file i want to target}`
Its much clearer and concise.
My biggest gripe is that the other results show in seems to be totally random. For example, if I have a Java class called A and I search "class A" in code search, the actual A.java doesn't tend to show up anywhere near the front. I just tried this in a repo and the actual A.java file was on the last page of results when I searched "class A". The vast majority of the results before it didn't even have the words "class" and "A" next to each other, which A.java does...
Maybe I'm doing something wrong (I'd welcome any input on how to use code search correctly!), but it just feels like they're jumping the gun on trying to make their code search more advanced when the basic functionality doesn't work that well.
The search appears to be configured for natural language documents, not code. The stopwords are not right and search appears to strip all sigils. They could get pretty far just by parsing documents and changing their lucene/elasticsearch configuration.
And of course good old regex search.
"is:pr is:open ( author:bob OR author:jim )"
The lack of this pretty basic functionality makes issue & PR search much less useful than it could be.
1. exact or close string searches for code that involves ![]{}_-*() etc characters
2. searches across past commits (e.g. find a line that used to be in the code)
4. search across pull request + comments (not just issues and commit messages)
5. advanced search operators -- there should be a full filtering UI with ands and ors etc
Because of this I often find my self grepping locally, or (more often) totally out of luck.
GitHub is used by programmers. Surprisingly, they tend to be very good at telling computers precisely what they want, in the computers’ own language.
Natural language search is the exact opposite of this, invented for mom & pops who start their search phrase with “Dear Google, I’d like to search for ...”.
This is an incredible waste of time and resources that could be spent making the existing search far better with very minor tweaks. A perfect example of big company project management where nobody seems to know what their users actually want.
Please build search that lets me actually find a given file by name.
You are busy building a space rocket when all we want is a bicycle. Impressive, but useless for just popping down to the shops.
Love,
The rest of the world's developers
• 2 openings - Business Systems
• 2 openings - Communications
• 38 openings - Engineering
• 3 openings - Finance
• 1 opening - Internal Communications
• 4 openings - Legal
• 8 openings - Marketing
• 2 openings - People Operations
• 1 opening - Policy
• 7 openings - Product
• 8 openings - Sales
• 9 openings - Security
• 1 opening - Services
• 3 openings - Support
Sure, they may not be addressing your/my specific concerns, but the product is changing.
Its when you get to hundreds of repositories or 10's of gigabytes of code that local tools cannot run fast enough. They are not designed for this use-case, and usually rely on the files being searched hitting the disk cache for repeated search performance.
It may be possible for github to shell out to grep for a single repository search (I have no idea how the back-end works but I doubt its impossible) but, I suspect that almost everyone wants/expects this to work across multiple repositories or across all of the github repositories.
Since its not easily possible to do so across everything they are not adding it to even a single repository to avoid search working differently for different situations, which is a fair approach in my opinion.
On GitHub, tens of thousands of searches will be happening at once on the same search cluster. If they were all literally doing a "git grep" (a linear scan of the associated repo data), the disk caches would thrash back and forth between queries, and nothing could be answered in less than 30 seconds.
The only way for GitHub to respond to code searches at scale in a reasonable time, is to have a pre-built index.
If the index was per repo, that'd be a kind of partitioned index; and there's no DBMS that I know of that can handle a partitioned object having 58 million partitions. It makes much more sense to have an unpartitioned index... which effectively implies "cross-repo search" (because, once you have an unpartitioned index built up over all your repos, it costs nothing to enable someone to search that entire index at once.)
You could then offer code search across the whole index (minus any project marked private that you are not a part of) as a paid offering.
With ever-cheaper RAM, ever-faster SSDs, and cloud computing, it could actually make sense, now or soon, to scan through an entire repo, either on "disk" or in RAM. I started building an app that would suck down any GitHub repo by simulating a git clone in the back-end, in the time it took you to type in your query, and hold it in RAM across queries. As a user, I'm sure I would gladly pay however many cents it costs to take up this much RAM when I'm on the search page over the course of a month.
Even if a linear scan isn't feasible, regex search at scale is not an unsolved problem, and GitHub has access to world-class engineers. Google Code used trigrams to do regex search with an index (https://swtch.com/~rsc/regexp/regexp4.html). Sourcegraph offers regex search.