Full-Text Search: Beyond Simple String Matching
Full-text search isn't just string matching; it's a search engine for your data that understands language. Use it for e-commerce search or log analysis. The footgun is thinking a simple LIKE query is a substitute for a real search engine like Elasticsearch.
Why it exists
Standard database queries like WHERE description LIKE '%term%' are slow and unintelligent for searching large bodies of text. They can't handle typos, understand that "running" and "ran" are related, or rank results by relevance. We need a way to search unstructured text like a human would, finding meaning, not just character sequences.
The mental model
Think of full-text search as creating a specialized index for human language, not just data values. Instead of indexing raw text, you index processed 'tokens'. This index is like one in the back of a textbook, but smarter. It knows that 'quick', 'quicker', and 'quickly' are related and can point you to all the right documents, then rank them by how well they match your intent.
How it works
Text is passed through an analyzer pipeline. This process first breaks text into tokens (usually words). Then, it might perform several steps: converting to lowercase, removing common stopwords ('the', 'a', 'is'), and stemming or lemmatizing words to their root form (e.g., 'running' becomes 'run'). These final tokens are stored in an 'inverted index', which maps each token back to the documents containing it. When you search, your query goes through the same analysis, and the engine uses the inverted index to find matching documents instantly, calculating a relevance score for each.
When to use it
Use it when you need to search through large volumes of unstructured text and relevance matters. This is ideal for e-commerce search bars, log analysis platforms (searching for error messages), content management systems, and any application where users need to find documents by searching their actual content.
When not to use it
Don't use it for searching structured, exact-match data. If you're looking up a user by their unique email or an order by its ID, a standard database index (like a B-tree) is far more efficient. Full-text search is overkill and less performant for simple key-value lookups.
One canonical example
A user searches for "running shoe" on an e-commerce site. A simple database LIKE query would miss products described as "shoes for running." A full-text search engine, however, would have stemmed "running" to "run" during indexing. It would find documents containing "run," "running," or even synonyms if configured. It would then rank the results, showing products with "running shoe" in the title or with high sales for that query first.
Interview question
What is a key mechanism enabling full-text search to efficiently find relevant documents?
- a.Using standard relational database indexes on raw text fields.
- b.Storing processed tokens in an inverted index for quick lookups.Correct
- c.Caching entire documents in RAM to avoid disk I/O during searches.
- d.Performing a sequential scan across all documents, optimizing for keyword density.
Why? this is the answer
The card states that text is processed into 'tokens' and stored in an 'inverted index' which maps tokens to documents, allowing for instant and relevant searches. While caching (option C) can improve performance, it is not the fundamental mechanism for how full-text search identifies and ranks relevant documents based on linguistic analysis.
Just read this? Test yourself on what you have been reading.
Read the original → en.wikipedia.org
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on databases — each one lists the topics its interview covers.
See open roles