Full-text tokenization
Overview
Full-text search indexes tokens rather than arbitrary substrings. A tokenizer splits text into searchable units; a language dictionary may normalize words into lexemes. Use MATCH for SQLite FTS5, not LIKE as a substitute. The fixture contains four English documents and three Persian documents.
First example
SELECT rowid FROM sr_doc WHERE sr_doc MATCH '"sql index"' ORDER BY rowid;Observed SQLite result (rows in JSON):
[ [ 1 ]]How it works
The phrase "sql index" requires adjacent tokens in order. Prefix index* matches token beginnings, not arbitrary suffixes. The unicode61 tokenizer normalizes case but does not stem English. FTS5 query strings have their own grammar even when passed as bound parameters; quote literal input appropriately and restrict advanced syntax if needed. PostgreSQL uses tsvector and tsquery, which depend on text-search configuration.
Practical example
SELECT rowid FROM sr_doc WHERE sr_doc MATCH 'index*' ORDER BY rowid;Observed SQLite result (rows in JSON):
[ [ 1 ], [ 2 ], [ 3 ]]Practice and mistakes
Practice: search for the token index and compare with LIKE containing index. Hint 1: query sr_doc with MATCH. Hint 2: compare rowids; indexing is a different token. Expected token matches: 1, 2; substring matches: 1, 2, 3. Avoid assuming LIKE and MATCH are equivalent.
PostgreSQL 17 example — NOT RUN
SELECT to_tsvector('simple','sql index tutorial') @@ phraseto_tsquery('simple','sql index');Expected result, not executed: [[true]]