How GitHub Docs’ new search works
GitHub Docs replaced its in-memory Node.js site search, which loaded serialized indexes from the Git repo for eight languages and five versions, with Elasticsearch. Each search is sent as one query built from a matrix of fields (title, headings, content), two analyzers (explicit with no stemming or synonyms, and Snowball-stemmed) and match types (phrase, AND, OR, fuzzy). Each combination gets a distinct multiplicative boost, so exact title phrase matches rank highest and terms like `working-directory` aren't swamped by stemmed matches. Final scores are multiplied by (1 + normalized pageview popularity), and query execution stays around 20 ms server-side.
Related posts
- How MDN’s site-search works
Mozilla Hacks mediumAdeptMDN's site search builds every page nightly in a GitHub Action, emitting index.json files. A Python script strips the HTML and bulk-publishes about 50,000 documents to a managed Elasticsearch cluster in roughly 3.5 minutes, deleting and recreating the index each day for simplicity. A Django endpoint queries it with elasticsearch-dsl, ranking by phrase and term boosts on title and body plus a Google Analytics-derived popularity score (rank = popularity*10 + score), and adds "Did you mean" suggestions. The cost of the daily rebuild is a brief window of incomplete results, softened by publishing the most popular en-US Web/ pages first.
- A brief history of code search at GitHub
GitHub Engineering mediumAdeptGitHub's code search evolved from a public-only Solr index plus `git grep` for private repos, to a decade-long Elasticsearch deployment that grew to 162 nodes, 1.25PB of storage and over 53 billion indexed files. Natural-language text analysis fits source code poorly. GitHub's custom tokenizer dropped punctuation and could not do substring or regex matching. An experiment that indexed special characters made indexing 43-100% slower, grew the index 18-28% and slowed typical queries about 2.1x. A short-lived exact-match beta also failed to balance its resource cost against corpus growth. Existing trigram engines like Russ Cox's and Zoekt also fell short at GitHub's scale, so GitHub built Blackbird, a bespoke engine targeting sub-second p95 global exact-match and regex queries without using much more resources than the Elasticsearch cluster.
- GitHub Issues search now supports nested queries and boolean operators: Here’s how we (re)built it
GitHub Engineering mediumAdeptGitHub rebuilt Issues search to support AND/OR operators and nested parentheses by replacing the flat-list parser with a PEG grammar (via the Ruby parslet library) that produces an abstract syntax tree. That tree is recursively traversed into nested Elasticsearch bool queries, with AND and OR mapped to must and should clauses. To protect backward compatibility at roughly 2,000 QPS, the team reran the existing test suites with the feature flag on and off and dark-shipped 1% of searches through both systems using the scientist library, comparing result counts and performance. The rollout capped nesting at five levels and started with the GraphQL API and the repository Issues tab before expanding to the dashboard and REST API.
- How MDN’s autocomplete search works
Mozilla Hacks mediumAdeptMDN Web Docs' autocomplete search runs entirely in the browser. It lazy-loads a Brotli-compressed JSON index of every document title per locale (11,690 en-US titles, 144KB over the wire) only when the user focuses or hovers the search box or presses `/`. FlexSearch builds an in-memory index that is reused across keystrokes, and downshift handles the accessible React dropdown. Ranking comes from pre-sorting the index by relative pageview popularity at build time, so FlexSearch's matches keep that natural order. Typing `/` first switches to VS Code-style fuzzy matching on URL paths, which also works offline for content authors on a local preview server.
- The technology behind GitHub’s new code search
GitHub Engineering mediumAdeptGitHub built Blackbird, a Rust code search engine, because general text search engines handled punctuation, regex, and GitHub's scale poorly, and brute-force grep would yield about 0.01 QPS. It uses ngram inverted indices with lazily intersected posting-list iterators, shards by Git blob ID to deduplicate content, and delta-encodes repositories ordered by a similarity-based minimum spanning tree. Kafka decouples crawling from indexing and provides commit-level query consistency. Shards serve queries at about 100 ms p99 (roughly 640 QPS per 64-core host), and 115 TB of code fits in a 25 TB index that can be fully rebuilt in about 18 hours.