Text Analysis — Turning Messy Text into Searchable Terms

Before a single word goes into the index, it passes through a quiet, decisive step: text analysis. Deciding what counts as a "word," how to normalize it, and which words to keep is what lets a search for "running" find a document about "ran," and what makes "The" not clog the index. Get analysis right and search feels intelligent; get it wrong and no clever ranking can save it. This post is about the unglamorous preprocessing that quietly determines search quality.

Posts 1–2 built the retrieval pipeline and the inverted index. This post is the step that feeds the index: turning raw text into the normalized terms that get indexed and matched. It’s easy to overlook, but it’s where a huge fraction of real search quality is decided — and where the “query and documents must speak the same vocabulary” rule (post 1) is enforced.

Tokenization: what is a word?

The first step, tokenization, breaks a stream of text into individual units (tokens, roughly “words”). This sounds trivial and isn’t: - Where are the boundaries? Spaces work for English, mostly — but what about “don’t” (one token or two?), “state-of-the-art” (one or four?), “U.S.A.” (keep the dots?), or “C++” and “covid-19” (don’t lose the symbols)? - Many languages don’t delimit words with spaces at all (Chinese, Japanese), requiring far more sophisticated segmentation. - Numbers, URLs, emails, and code need special handling or they tokenize into nonsense.

Tokenization decisions directly affect what’s findable: if “covid-19” tokenizes to “covid” and “19,” a search for the exact term may fail or match spuriously. There’s no universally correct tokenizer — it depends on the language and the content — which is why search engines let you configure analysis. The key discipline is consistency: however you tokenize, you must tokenize queries the same way as documents (post 1), or they won’t match.

Normalization: collapsing variants to one form

Raw tokens have many surface forms that mean the same thing, and normalization collapses them so a search matches regardless of superficial differences:

Normalization is what closes much of the vocabulary gap (post 1) at the term level — it’s why search feels forgiving of word forms. And again, it must be applied identically to documents and queries: if documents are stemmed but queries aren’t, they stop matching. The analysis pipeline is a contract both sides must honor.

Stop words, synonyms, and the judgment in analysis

A few more analysis decisions complete the picture, each a judgment call with real consequences:

The meta-point is that text analysis is where domain and language knowledge enters search, and it’s astonishingly high-leverage: the same index and the same ranking function produce dramatically different quality depending on analysis choices. A medical search engine, a code search engine, and a general web engine need very different analysis, and tuning analysis is often where the biggest relevance gains in a search system come from — bigger than tweaking the ranking function. It’s also the step that modern semantic search (post 7) partly transcends: embeddings capture meaning directly, reducing reliance on stemming and synonyms — but even hybrid systems still analyze text for their keyword half, so analysis remains foundational. The humble preprocessing step is, quietly, one of the most important levers in all of search.

The throughline: before indexing, text analysis turns raw text into normalized terms, and it quietly decides much of search quality. Tokenization (splitting text into tokens) is deceptively hard (punctuation, hyphens, symbols, space-less languages) and directly controls what’s findable. Normalization collapses surface variants — case folding, stemming (fast crude roots) vs lemmatization (accurate dictionary base forms), accent/Unicode handling — closing the vocabulary gap at the term level. Stop words (remove common noise vs keep for phrases — a tunable trade-off) and synonyms (map equivalents, powerful but risky) add more judgment, all language-specific. The iron rule throughout: analyze queries exactly as documents (post 1), or matching breaks. Analysis is where domain/language knowledge enters and is often the highest-leverage lever in search — more than the ranking function.

Key takeaways

Further reading

Sources & References