Problem
GitHub Docs had an in-memory site search that loaded all searchable text into the Node.js process. It did not scale, because the docs exist in eight languages and five versions per language. After the move to Elasticsearch, a ranking question came up. Stemming helps recall, but it can also let a loosely related page outrank the page that contains the exact term the user typed. Page popularity helps pick the likely target, but a very popular page that matches only vaguely should not beat a precise title match.
Example from the article: a search for the keyword working-directory should not be dominated by a page titled "Directories that work", because both reduce to the same two stems, work and directori.
Solution in brief
Index every text field twice, once with stemming and synonyms and once without ("explicit"). Send one query that lists every combination of field, analyzer and match type, each with its own multiplicative boost, so exact title phrases score highest. Then multiply the final score by one plus a normalized page-view popularity.
Questions this case answers
- How to rank site-search results when stemming makes unrelated exact terms look like close matches and popularity signals can drown out text relevance
- How to express a full ranking policy over several fields and matching modes in one lexical search query
- How to rank documentation search results so exact keyword matches beat loose stemmed matches?
- How to combine text match scores with page popularity without letting popular pages bury better matches?
Tools and methods
- Elasticsearch — full-text index and query engine for the docs search
- match_phrase, match (OR and AND), fuzzy — matching modes combined in one query
- Per-field boosts — a fixed multiplier for title, headings, content, phrase, AND and explicit matches
- Page-view popularity multiplier — pushes frequently visited pages up
Google or a one-time email code. No password.