Challenges In Full-Text-Search Systems
While Full-text-search is famous for search through documents at a faster rate, there are other interesting ways in which these systems handle scale, synonyms, abbreviations, misspellings etc. This post walks through those challenges, how engines are built to solve them, and where semantic and hybrid search fit in.
Updated Nov 2026. I’ve rewritten the relevance section around BM25, added the internals of search engines, precision and recall, a section on semantic and hybrid search, and a comparison of Elasticsearch, Solr, Meilisearch and Typesense.
Text problems are the most interesting ones to solve. From being a part of a CS Engineer’s academics to kick ass feature of a product, searching is everywhere. It doesn’t matter what language, database or Service you rely on, if you have a bunch of data your users will want to search through them.
Now that we know the necessity of search feature in an app, the struggle comes when your data grows. Ordinary regex or grep based search methods won’t hold good for this scale of data. Full-text search is more intuitive than just pattern matching. The main idea is to give the user with the relevant results. We need a swiss army knife a Full-text-search to solve our search problems. This blog will cover what Full-text-search and it solves those problems.
What is Full-Text-Searching?
Full text search is an advanced method of searching through documents and DB records. While conventional searches use pattern matching(grep/regex) methods and scanning through the documents, full-text search promises fast retrieval of data with advanced indexing and more intuitive search results based on relevance.
Why do we need Full-Text Search?
You tell me. Which is better looking for a book in each rack of a library or searching through a library management system and finding the rack/row number? Every Google/Amazon search we do is a Full-text-Search(FTS)
How does Full-Text Search work?
The full-text search first starts with a DB containing a bunch of Data(documents). These data are indexed based on the words in the documents and stored. When a user enters a search query, the query is split into tokens and mapped across the built index to find the relevant documents.
That is the 10,000-feet view. Here is what is actually inside an engine.
Analysis: tokenizers and normalization
Before anything is stored, the text goes through an analysis chain, and the same chain runs on the query, otherwise the two would never match.
- A tokenizer splits the text into tokens. For English, splitting on whitespace and punctuation gets you far. Meilisearch’s tokenizer, Charabia, does that by default, and also switches to dedicated pipelines for languages such as Chinese, Japanese, Hebrew, Thai and Khmer, where there are no spaces between words.
- Normalization lowercases the tokens and strips accents, so “Café” and “cafe” are the same word.
- Stop word removal and stemming (the steps listed in the scaling section below) are language-specific filters on top.
The inverted index: dictionary and postings lists
The index you build from the tokens is called an inverted index: instead of document → words, it stores word → documents. Meilisearch’s explainer puts it as a structure that “maps tokens to the documents they’re in alongside their positions in said documents.”
It has two halves, using Lucene’s file format as the example. Lucene is the library under both Elasticsearch and Solr, so this is the index most production search runs on.
- The term dictionary (the
.timfile) lists every term in a field, with per-term statistics such as how many documents contain it, and pointers to the postings. - The postings lists hold, for each term, the documents that contain it (the
.docfile), and the positions of the term inside each document (the.posfile). Frequencies are stored too, which is what scoring needs. Long lists are stored in fixed blocks of 128 entries with skip data, so a query can jump ahead instead of reading the whole list.
Looking a word up in a dictionary with millions of terms has to be fast and small. That is where FSTs (finite-state transducers) come in. Lucene’s term index (the .tip file) is an FST per field that maps a term prefix to the on-disk block holding all the terms with that prefix. Meilisearch uses FSTs as its word dictionary, one for all words and one for frequent prefixes, which is what powers search-as-you-type.
Once you have the postings for each query term, a search is set arithmetic: AND is an intersection of lists, OR is a union. Meilisearch uses Roaring bitmaps to compress the document ID lists, which makes those unions, intersections and differences cheap. It keeps all of this in LMDB, a memory-mapped key-value store (source).
Challenges In Full text Search
To understand and appreciate the mechanisms and terms involved in full-text-searching you need to understand the challenges involved in the same. A few of the common challenges are.
- Scale - How does it work for huge amounts of data?
- Relevance - How to make the search results relevant?
- Handling Synonyms, Abbreviations, homonyms, Phonetics
- Handling misspellings
- Searching through images
- Re-indexing - Handling new or constantly changing data?
- FTS is distributed Systems
- Meaning - what if the user’s words don’t match the document’s words at all?
Scaling - Indexing the Documents
As we discussed conventional grep based systems no longer works at the speed, we need when the number of documents increase. Indexing is a method followed in most data stores for fast retrieval of data. You can imagine these as hash tables with a mapping between words and its associated document.
- Take all the words from the documents and remove stop/noise words
- Stem the words based on the language
- Create a table of words mapping it to its occurrence in the document
- On entering a search query tokenize, stem the words and cross check across the index.
Relevance - from TF-IDF to BM25
Relevance is “how relevant your search results are?” to the search query. When talking about relevance we often focus on finding the documents that relates to the “Intention of the user”.
For e.g., when searching for a white shirt, the color “white” carries a specific weight.
Once documents are matched from the index, a relevance score is calculated and the results are sorted according to this score. Three ideas go into that score.
- Term frequency (TF) - The larger the number of times a term occurs in a document the more relevant it is.
- Inverse document frequency (IDF) - Rare words are more informative than common ones. The textbook definition is
idf = log(N / df), whereNis the number of documents anddfis the number of documents containing the term. A word in every document gets no weight; a word in three documents out of a million gets a lot. - Field length - A match in a short field counts for more than a match in a long one. A hit in a five-word title says more than a hit in a five-page description.
Multiplying TF by IDF is TF-IDF, and it is where I stopped in the first version of this post. It works, but it has two annoying problems. A document that repeats a word 50 times is not 50 times more relevant than one that says it 5 times. And long documents win just because they have more chances to repeat words.
BM25 is the fix, and it is the default similarity in Elasticsearch. The textbook formula for one query term is:
score(d, t) = idf(t) * ((k1 + 1) * tf) / (k1 * ((1 - b) + b * (len(d) / avg_len)) + tf)
The score of a document is the sum over the query terms. Two knobs do the new work:
k1controls term-frequency saturation. The first occurrence of a word counts for a lot, the second a bit less, and the tenth barely moves the score. Setk1to 0 and TF stops mattering. Make it very large and you are back to raw term frequency.bcontrols length normalization, from 0 (ignore document length) to 1 (fully scale by length relative to the average document).
Elasticsearch’s defaults are k1 = 1.2 and b = 0.75. The textbook suggests values between 1.2 and 2 for k1, and 0.75 for b.
To see saturation, here is the TF part of the formula with k1 = 1.2, ignoring length. This is computed from the formula above, not measured on a real index:
| Occurrences of the term | TF part of the score |
|---|---|
| 1 | 1.00 |
| 2 | 1.38 |
| 5 | 1.77 |
| 10 | 1.96 |
| 50 | 2.15 |
Fifty occurrences score about twice as much as one occurrence, rather than fifty times. The curve flattens towards k1 + 1 = 2.2. Here is a small, dependency-free Python version you can play with. It scores a tiny corpus with BM25, and also computes the precision and recall and the rank fusion that the next sections talk about:
import math
import re
from collections import Counter
docs = {
1: "jaguar top speed cheetah comparison big cats",
2: "jaguar xf review leather seats engine",
3: "jaguar habitat rainforest big cat south america",
4: "jaguar land rover sales results engine",
5: "jaguar rainforest conservation cat",
6: "ocelot habitat rainforest cat",
7: "cheetah speed savanna cat",
}
relevant = {1, 3, 5, 6, 7} # what the user meant: wild cats
def tokenize(text):
return re.findall(r"[a-z0-9]+", text.lower())
tokens = {i: tokenize(t) for i, t in docs.items()}
N = len(docs)
avg_len = sum(len(t) for t in tokens.values()) / N
df = Counter(term for t in tokens.values() for term in set(t))
def bm25(query, k1=1.2, b=0.75):
scores = {}
for i, toks in tokens.items():
tf = Counter(toks)
score = 0.0
for term in tokenize(query):
if term not in tf:
continue
idf = math.log(N / df[term])
norm = k1 * ((1 - b) + b * len(toks) / avg_len)
score += idf * (k1 + 1) * tf[term] / (norm + tf[term])
if score > 0:
scores[i] = score
return sorted(scores, key=scores.get, reverse=True)
def rrf(rankings, k=60):
fused = Counter()
for ranking in rankings:
for rank, doc_id in enumerate(ranking, start=1):
fused[doc_id] += 1.0 / (k + rank)
return [d for d, _ in fused.most_common()]
def precision_recall(retrieved, relevant):
hits = len(set(retrieved) & relevant)
return hits / len(retrieved), hits / len(relevant)
# 1. term-frequency saturation: the tf part of BM25 for k1=1.2 (length ignored)
for tf in (1, 2, 5, 10, 50):
print(f"tf={tf:>2} tf-part={(1.2 + 1) * tf / (1.2 + tf):.2f}")
# 2. precision / recall for an ambiguous query
hits = bm25("jaguar")
p, r = precision_recall(hits, relevant)
print("jaguar ->", hits, f"precision={p:.2f} recall={r:.2f}")
# 3. fuse two rankings: BM25 and a pretend 'semantic' ranking
semantic = [3, 5, 6, 1, 7, 2, 4] # stand-in for a vector-search result list
print("rrf ->", rrf([hits, semantic]))
I ran it with Python 3.13 and it prints:
tf= 1 tf-part=1.00
tf= 2 tf-part=1.38
tf= 5 tf-part=1.77
tf=10 tf-part=1.96
tf=50 tf-part=2.15
jaguar -> [5, 2, 4, 1, 3] precision=0.60 recall=0.60
rrf -> [5, 3, 2, 1, 4, 6, 7]
Real engines use slight variants of the IDF part, and they compute the length statistics per field, so don’t expect the same numbers from Elasticsearch on the same text.
Precision and Recall - how do you know the results are good?
Relevance scores order the results, but they don’t tell you whether the search as a whole is any good. For that, information retrieval uses two measures, defined in the Stanford IR book.
- Precision is the fraction of retrieved documents that are relevant. Of what I showed the user, how much was right?
- Recall is the fraction of relevant documents that are retrieved. Of everything that was right, how much did I show?
A false positive is a retrieved document that isn’t relevant, and it drags precision down. A relevant document the search missed is a false negative, and it drags recall down.
The toy corpus above shows both. Say the user searches “jaguar” and means the big cat. Five of our documents contain the word, so the search returns five. Two of them (the car review and the car sales results) are false positives, so precision is 3/5 = 0.60. There are five documents about wild cats, but the ocelot and cheetah articles never use the word “jaguar”, so they are never returned: recall is 3/5 = 0.60 too.
The two pull against each other. Add fuzzy matching, synonyms and stemming and you find more documents (recall goes up) but let in more wrong ones (precision goes down). Keyword search is naturally strong at precision for exact terms and weak at recall when the vocabulary doesn’t match, which brings us to the next section.
Full-text search vs semantic and hybrid search
Everything so far matches words. If the document says “automobile” and the user types “car”, unless you maintained a synonym list, it is a miss. Semantic search matches meaning instead.
- An embedding model turns a piece of text into a vector of numbers, so that texts with similar meanings end up close together. You embed every document at indexing time and the query at search time.
- A vector index finds the nearest vectors to the query vector. Comparing the query against every vector (exact kNN) is fine for small datasets. At scale you use approximate nearest neighbour search, which, as Elastic’s docs put it, “is best for most production workloads where low latency and scale matter more than perfect recall”. The most common structure is HNSW, a graph where each vector is linked to its neighbours. Solr and Typesense both use it.
In our toy corpus, a semantic search for “jaguar” would plausibly surface the ocelot and cheetah articles because they are about the same kind of thing, which is exactly the recall that BM25 couldn’t give.
But semantic search isn’t a replacement. A vector for “ERR_CONNECTION_RESET” or a product code is only vaguely close to the same string in a document, and a keyword search finds it exactly. My rule of thumb: keywords for exact identifiers and names, vectors for natural-language questions, and both when you can’t tell what the user will type. That is hybrid search: run both, then merge the two ranked lists.
The tricky part is merging, because BM25 scores and vector distances live on different scales, so adding them is meaningless. Reciprocal Rank Fusion (RRF) sidesteps this by using ranks instead of scores. From the original paper:
RRFscore(d) = sum over rankings r of 1 / (k + rank_r(d))
with k = 60. A document that is near the top of both lists beats one that is first in only one. The paper reports that RRF “consistently outperforms any individual system” and beats the Condorcet Fuse method. The rrf() function in the code above is the whole algorithm, and the pretend semantic ranking there shows the ocelot and cheetah articles making it into the fused list even though BM25 never returned them.
You don’t have to implement this yourself:
- Elasticsearch has an
rrfretriever that combines a standard query with aknnretriever, withrank_constantdefaulting to 60. - Typesense runs keyword and semantic search together and merges them with a weighted rank fusion, 0.7 for keyword and 0.3 for vector by default, adjustable with
alpha. - Meilisearch has a
hybridsearch parameter with an embedder and asemanticRatioyou tune to balance keyword and semantic results.
Abbreviations, synonyms, homonyms and Phonetics
In the era of instant messaging we are used to use not only the accepted abbreviations like W.H.O but we also create ones of our own like TC and AFK. Now when searching for “world health” valid to bring out documents that mentions “W.H.O”.
- Search Thesaurus - Where a mapping all the abbreviations and its associated expansion is saved.
- Text Normalization - On creating an index the abbreviations are normalized to its actual text searching on it works like searching over an actual text.
- Embeddings - A semantic model has seen “W.H.O” and “World Health Organization” in similar contexts, so it needs no hand-maintained list (see the section above).
Searching Through Images
Gif-search is an example of Full text search in images. Google Images works based on the relationship between a blog post, alt-text and an image in the page. Gif-ly works by associating emotions of the gif as a metadata along with the images.
For a true FTS to work over a bunch of images one way to do is by extracting text from those images using an OCR and using it as the metadata for search
Handling Misspellings - Fuzzy Search
Fuzzy search is a terminology used in Elasticsearch. It uses Damerau-Levenshtein distance formula.
The Damerau-Levenshtein distance between two pieces of text is the number of insertions, deletions, substitutions, and transpositions needed to make one string match the other.
For example, the Levenshtein distance between the words “ax” and “axe” is 1 due to the single deletion required.
Updating New Data
Indexes are built based on the data in the databases. In any real time system the data changes frequently. For e.g., An item might go out of stock or the prices might vary and so on. In this case the index becomes invalid and searching over it often gives wrong results. This can be handled in 2 ways
- Drop the index and rebuild it for the newly available data
- It is time consuming
- User can’t do FTS until the whole index is rebuilt again
- Keep track of all the updates and inserts to the DB and update the index asynchronously
- The only drawback in this method is the inconsistency in data, which is much better when compared to shutting off the feature for few minutes.
Full-Text-Search In Distributed Systems
As the system scales and when you adapt to a microservices architecture next set of challenges occurs.
- How to search through the data which is spread across different microservices?
- As the data scales a user with less data might get his response faster, when compared to one whose drive is overflowing. how to efficiently index the documents so that the latency does not vary for different users.
Which engine? Elasticsearch vs Solr vs Meilisearch vs Typesense
Now that you know what is inside, the four engines you will most often see compared differ mostly in how they store the index and what that costs you. I haven’t benchmarked these myself, so I only put in numbers that the vendors publish in their own docs, and say which ones are vendor claims. Where a vendor publishes nothing, the cell says so.
| Elasticsearch | Solr | Meilisearch | Typesense | |
|---|---|---|---|---|
| Under the hood | Built on Apache Lucene | Built on Apache Lucene | LMDB store with FSTs and Roaring bitmaps, Charabia tokenizer (source) | In-memory index, with a copy of the raw data on disk (source) |
| Index size | On disk. Indexes most fields by default and adds doc values; the disk usage guide lists ways to shrink it, such as index: false, match_only_text and best_compression. No fixed ratio published | On disk, as a Lucene index. No ratio published | On disk, memory-mapped. The docs say there is “no reliable way to predict the final size of a database”, and their sample dataset ends up well above the raw JSON size | In RAM: 2X-3X the size of the searchable fields. Disk must hold at least the raw dataset |
| Latency | No vendor figure. Depends on shards, hardware and query | No vendor figure | Vendor claim: every query returns in under 50 ms | Vendor claim: typically sub-50ms for search-as-you-type |
| Cost drivers | Cluster nodes and disk. A cluster to size and operate | Same shape: a cluster you run (SolrCloud) | Disk, with a low-latency disk such as NVMe recommended. Docs say a RAM-to-disk ratio of about 1/3 has no material performance impact. Managed cloud available | RAM is the main bill because the index lives there. Remote embedding services need no extra RAM; built-in models need about 2-6 GB more |
| Vectors / hybrid | dense_vector kNN and the RRF retriever | DenseVectorField with HNSW and a knn query parser; no dedicated hybrid section in the guide, but lexical and vector results can be re-ranked together | hybrid search with embedders and semanticRatio | HNSW, with built-in embedding models and rank-fusion hybrid search |
How I would pick, from the table and not from a benchmark: if you already run a Lucene stack, or need heavy analytics and aggregations, Elasticsearch or Solr. If you want search-as-you-type for a product catalogue or docs site without running a cluster, Meilisearch or Typesense are far lighter. Between those two, the main trade is disk (Meilisearch) vs RAM (Typesense). Test with your own data before you commit, because index size and latency depend on your documents and settings.
How to get Started?
Here is a step-by-step walkthrough on how to implement an Elastic search powered application
Resources
- https://issart.com/blog/full-text-search-how-it-works/
- How to add full text search to your website (Sam Dutton, 2018. Compares search engines, managed services, database search and client-side libraries, and some of the details such as the Google Site Search it mentions are dated)
- https://www.youtube.com/watch?v=FM2e2J7OJpM
- How does a Lucene Query work?
- Do Not Use MySQL indexes
- How does FTS work what can it do?
- https://conferences.xeraa.net/videos/ovUA3r
- How dropbox solves full text search
- Reciprocal Rank Fusion outperforms Condorcet and individual rank learning methods
- Introduction to Information Retrieval (Stanford)