How MDN’s autocomplete search works
MDN 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.
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.
- How GitHub Docs’ new search works
GitHub Engineering mediumAdeptGitHub 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.
- 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.
- Search From a Million Books in Milliseconds With Neon and pg_search
Neon mediumAdept
Swapping the OpenAI-embedding semantic search in Vercel's Next.js Book Inventory template for pg_search's BM25 full-text index on Neon Postgres made title searches over a million Goodreads books roughly 180–236x faster, dropping from about 2.7 seconds to 11–14 ms. The setup loads the dataset into a books table, prewarms the table and index with pg_prewarm, creates a covering bm25 index, and queries with the @@@ operator and paradedb.match in conjunction_mode. On the app side, Drizzle is replaced by Neon's HTTP serverless driver, and Vercel functions are co-located in us-east-2 with the database. Side-by-side tsvector/tsquery and pg_search queries with timings are included for reproduction.
- Creating an accessible search experience with the QueryBuilder component
GitHub Engineering mediumAdeptGitHub's QueryBuilder is a combobox-based search input built to stay accessible while supporting per-character styling, suggestions with different actions, and grouped results. Styling uses an aria-hidden div of spans aligned behind a real input whose text is transparent, avoiding contenteditable. Group membership and "jump to" behavior are conveyed through aria-labels that begin with the visible text (for voice control users), since role="group" inside listbox is poorly supported. An aria-live region announces result counts, and a toggled forces re-announcement when the message is unchanged. The component is built as a Web Component to be open-sourced in Primer React and ViewComponents.