Lesson 10 of 15
19. Search and Inverted Indexes

Memory card and where the analogy breaks

3 min read+10 XP

The memory card (tear this page out)

#QuestionMemory code
19.1Why LIKE '%word%' fails?A word in the middle has nowhere to jump to
19.2Tokenising and normalising?Clean the words the same way going in and coming out
19.3Inverted index?Flip the book: a card per word, listing every page it's on
19.4Ranking?Rare words count more; repeating a word stops paying
19.5Prefix search and tries?Follow the letters; the answers are already waiting below
19.6Keeping in sync?The shelves are the truth; the cards follow the change log
19.7Elasticsearch?Lucene does the cards; Elasticsearch runs the department
19.8Sharding search?Ask every room for its best, then pick the best of the best

The whole chapter in one line: Clean the words, keep a list of documents per word, rank by rare and well-placed matches, feed the index from the database's change log, and split it by document across shards.

Where the analogy breaks

  • A librarian understands meaning. An inverted index only matches terms: "car" won't find "automobile" without synonyms or vector search.
  • Library cards are updated by hand, rarely. A search index takes thousands of updates a second, through segments, merges and refreshes.
  • A library has one copy of each card. Search clusters keep several replicas, and each shard's scores are computed from its own documents only.

Quick check

Five questions on this chapter. Pick an answer, then check it.

quiz