Searching 100,000 short documents for one word with LIKE '% w1234 %' took 112 milliseconds in SQLite 3.53.1 and found 1,189 matches. The same search through an FTS5 full-text index took about 0.1 milliseconds and found 1,230. The index was not only faster; the LIKE query had quietly missed 41 documents. FTS5 is built into most SQLite distributions, needs no server, and suits search boxes in desktop apps, static site generators, note-taking tools and small web services. Tests in Python’s bundled SQLite show how to set it up, how it ranks, and the parts of its query syntax that raise errors when typed by ordinary users.
What FTS5 is
A virtual table
SQLite’s documentation describes FTS5 as “an SQLite virtual table module that provides full-text search functionality to database applications.” SQLite, FTS5 Extension A virtual table looks like a table but stores its data in its own structures. For FTS5 that structure is an inverted index: for every word, a list of the documents containing it.
Creating one
CREATE VIRTUAL TABLE docs USING fts5(title, body);
INSERT INTO docs VALUES ('Running a home server',
'Notes on running servers at home with a UPS and backups.');
SELECT rowid, title FROM docs WHERE docs MATCH 'server' ORDER BY rank;The test loaded five short documents about servers, backups and coffee. MATCH 'server' returned three of them: “Server room cooling,” “Ran out of coffee” (whose body mentions a server rebooting) and “Running a home server.” The match covered both columns at once.

The speed difference, and the missed rows
The benchmark
A second database held 100,000 documents, each 60 words drawn at random from a vocabulary of 5,000 made-up words. The same text went into an ordinary table and an FTS5 table. Each query ran five times and the average was recorded:
| Method | Matches | Average time |
|---|---|---|
LIKE '% w1234 %' |
1,189 | 112.3 ms |
FTS5 MATCH 'w1234' |
1,230 | 0.1 ms |
FTS5 was roughly a thousand times faster, because it looked the word up in its index instead of scanning every row’s text.
Why LIKE found fewer
The LIKE pattern required a space on both sides of the word, the usual trick to avoid matching w12345 when searching for w1234. That pattern cannot match a word at the very start or end of the text, since there is no space before the first word or after the last. The 41-document gap was those edge cases. FTS5 splits text into tokens and has no such blind spot.
LIKE still has its place
LIKE can find substrings inside words, such as part of a product code, which a word index does not do by default. For searching prose by word, though, the index is both faster and more correct.
The cost: disk space and write time
The speed comes from extra work at write time. The same 100,000 documents were written to two database files on disk. The plain table took 37.3 MB and 0.14 seconds to load. The FTS5 table took 59.3 MB and 1.4 seconds, about ten times slower to fill and roughly 60% larger, because it stores both the text and the index of every word.
Running FTS5’s optimize command, which merges the index’s internal pieces into one, followed by a VACUUM brought the file to 58.0 MB, a small saving on a table loaded in one batch. Tables that receive many small inserts over time accumulate more pieces, and the merge matters more there.
Looking inside the index
The companion fts5vocab virtual table exposes the index as rows. Created over the test table with CREATE VIRTUAL TABLE v USING fts5vocab(f, 'row'), it listed 5,000 terms, matching the vocabulary used to generate the documents exactly, with each term’s document count and total occurrences. The most common word, w3057, appeared in 1,313 documents. That view is a quick way to check what a tokenizer actually produced: whether accents were folded, whether stemming merged words, and whether hyphenated codes were split apart.
Ranking with bm25
Smaller is better
FTS5 ranks results with the bm25 algorithm. Its documentation explains: “The better the match, the numerically smaller the value returned.” Every FTS5 table has a hidden rank column that, in a full-text query, “contains by default the same value as would be returned by executing the bm25() auxiliary function.” Sorting by rank ascending puts the best matches first.
What it rewarded
A small set of eight documents searched for server gave these scores:
| Document | bm25 |
|---|---|
| “server server server cooling” | −0.609 |
| “server” | −0.585 |
| “server backup notes” | −0.398 |
Repeating the word raised the score, and shorter documents scored better than longer ones with the same number of matches. Searching for server OR backup put “server backup notes” first at −1.239, since it contained both terms.
A tiny-corpus oddity
In the first five-document test, all three matches for server scored −0.0. When a word appears in more than half of the documents, bm25 treats it as carrying almost no information, so its score drops toward zero. On a real collection of hundreds or thousands of documents this is rarely an issue, but a ranking demo with five rows can look broken for this reason alone.

Query syntax: the parts that break
Hyphens and punctuation
Typing server-room into a search box and passing it straight to MATCH produced an error: no such column: room. The query 3-2-1 failed the same way with no such column: 2. FTS5 read the hyphens as part of its own query language.
The documentation’s rule is that barewords may contain only letters, digits, underscore and non-ASCII characters, and “Strings that include any other characters must be quoted.” Wrapping the input in double quotes, MATCH '"3-2-1"', returned the backup document. Any search box that passes user text to MATCH needs to quote it or escape it first; otherwise a user typing a date, a part number or a hyphenated word gets an error instead of results.
A safe quoting function
A two-line Python helper handled every awkward input tried: wrap the text in double quotes and double any double quotes inside it.
def fts_quote(s):
return '"' + s.replace('"', '""') + '"'With it, 3-2-1, covid-19 and even "quoted" with its own quote marks all matched their documents instead of raising errors. The trade-off is that the whole input becomes one phrase, so server room only matches those words side by side; splitting on spaces and quoting each word separately keeps the looser any-order search.
Prefix, phrase, column and boolean queries
- Prefix:
serv*matched all three server documents. The documentation notes that a*placed inside quotes is not treated as a prefix marker. - Phrase:
"server room"matched only the document with those two words together. - Column filter:
title:backupmatched only titles. - Boolean:
server NOT coolingreturned two of the three server documents. AND, OR and NOT must be uppercase to act as operators. - Proximity:
NEAR(server notes, 2)matched “server backup notes,” where the words sit two tokens apart; the documentation gives the default distance as 10.
Tokenizers, accents and word forms
Accents removed by default
Searching for cafe without the accent found the document containing “café.” The default unicode61 tokenizer has a remove_diacritics option whose documentation says “The default value is “1”,” which folds most accented Latin letters to their plain forms. A user who cannot type an accent still finds the word.
Stemming with porter
A second table used tokenize='porter unicode61 remove_diacritics 2'. The documentation describes porter as a wrapper that “applies the porter stemming algorithm to each token.” With it, searching for running matched both “running servers” and “coffee runs,” and searching for run matched the same two. Without porter, running matched only the exact word.
Stemming improves recall for English prose and can produce odd matches for names, codes and other languages, so it is a choice per table, not a default.

Highlighting results and keeping the index healthy
highlight() and snippet()
The documentation describes highlight() as returning “a copy of the text from a specified column of the current row with extra markup text inserted to mark the start and end of phrase matches.” In the test, highlighting coffee in the café document returned “The café opens at seven; [coffee] runs until noon.”
snippet() “automatically selects and extracts a short fragment of document text.” Asked for four tokens around backup, it returned “…1 [backup] rule keeps…”, ready to display under a search result.
Keeping it in sync
An FTS5 table is separate from the main data. Applications usually either write to both in the same transaction or use FTS5’s external-content mode, which indexes columns of an existing table and relies on triggers to stay current. Since the index lives in the same database file, it is covered by the same backups; the x9m8 guide to backing up SQLite safely while it is running applies unchanged.
A short checklist
- Quote user input before passing it to MATCH.
- Order by
rankand remember lower is better. - Pick the tokenizer deliberately: unicode61 for exact words, porter for English prose.
- Test ranking on realistic amounts of data, not five rows.
Sources
- SQLite, SQLite FTS5 Extension: https://www.sqlite.org/fts5.html
