Full-Text Search Database 00:00:01 Turn a shelf of books inside out A librarian who receives the words “quick fox” could open every book. Instead she builds a card for each word and lists the documents in which it appears. That reverse directory is an inverted index. No words yet. Quick brown fox: three words, three lists. Quick lazy cat: cat is new. For phrases, each entry also stores where the word stands. Positions give each posting another power. They can tell whether two terms occur next to one another, even when the same documents contain both words in a different order. 00:00:41 Teach the index what counts as a word The librarian receives a page of formatted text. Its lettering, suffixes and punctuation matter to humans in different ways. An analyzer chooses which distinctions are preserved in the searchable representation. A bold sentence from a web page. Tags are removed before anything is split. Upper and lower case now meet. This example analyzer drops a frequent word and reduces foxes to fox. Those are configured choices. There is no universally correct analyzer. Stemming helps a reader find foxes with fox. A product code or a person's name might require an exact field beside the analyzed field. 00:01:25 Follow the query down two lists Now take the reader's actual search. Analyze the query compatibly with the index, open a posting list for each term and combine the document identifiers according to the requested matching rule. Somebody types Quick fox into the search box. Each token leads to its posting list. The other words are never read. All words: only document 1 is on both lists. Any word would give documents 1 and 3. Results are sorted by score and the best ones are fetched. Here there is one. Matching selects eligible documents. Ranking answers the next question. If both books qualify, the system still needs a reason to place one above the other. 00:02:13 A rare clue earns its place On our shelves nearly every book contains a common word, but very few mention a fox. BM25 gives the rare clue more weight, rewards repeated evidence with diminishing returns, and adjusts for document length. One is rare, one is everywhere. The rare word gets 4.56, the common one 0.11. The same two foxes in a document four times the average length are worth less: the norm grows from 1.2 to 3.9. Two foxes, average length: 4.56 times 1.375 is 6.27. Those decimals come from this toy collection and its chosen parameters. Compare ranking changes against judged queries, especially where a longer excellent document competes with a short incidental mention. 00:03:12 Keep the search copy current A shop edits a price in its primary database. The search index is another representation of that product. A durable change feed lets the indexer catch up when the search system is slow. The API writes the new price to PostgreSQL only. The committed change goes through Kafka to the indexer. While the indexer is down the search view can remain available with stale prices. The committed change waits in the feed. The indexer works through the queue in order and the copy is right again. Keep the original record authoritative at checkout. Search depends on analysis, postings and a ranking rule, and its freshness depends on the lag between the search copy and the original.