Full-Text Search
$text searches natural-language text using each database’s own full-text engine. It goes at the top level of $where, alongside regular field conditions.
const items = await querier.findMany(Item, { $where: { $text: { $fields: ['name', 'description'], $value: 'wireless keyboard' }, isActive: true, },});$fields lists the columns to search; $value is the user’s query text.
Per-Dialect SQL
Section titled “Per-Dialect SQL”SELECT * FROM "Item"WHERE to_tsvector("name" || ' ' || "description") @@ websearch_to_tsquery($1) AND "isActive" = $2SELECT * FROM `Item` WHERE MATCH(`name`, `description`) AGAINST(?) AND `isActive` = ?SELECT * FROM `Item` WHERE `Item` MATCH {`name` `description`} : ? AND `isActive` = ?MongoDB maps $text to its own $text operator ({ $text: { $search: value } }).
Text-Search Configuration (PostgreSQL)
Section titled “Text-Search Configuration (PostgreSQL)”$config selects the text-search configuration - the dictionary that drives stemming and stop-words - and is applied to both the document and the query. It defaults to the server’s default_text_search_config.
const items = await querier.findMany(Item, { $where: { $text: { $fields: ['name'], $value: 'running shoes', $config: 'english' } },});SELECT * FROM "Item" WHERE to_tsvector($1::regconfig, "name") @@ websearch_to_tsquery($1::regconfig, $2)The value is bound as a parameter (never interpolated) and its placeholder is reused by both calls. Other dialects ignore $config.
Index Requirements
Section titled “Index Requirements”Full-text search needs dialect-specific setup - $text generates the query, not the index:
| Dialect | Requirement |
|---|---|
| PostgreSQL / CockroachDB | Works without an index, but to_tsvector(col) computed per row cannot use one. For large tables, add a stored tsvector column (or expression index) with a GIN index. |
| MySQL / MariaDB | Requires a FULLTEXT index covering exactly the columns listed in $fields, in that order - otherwise the query errors. |
| SQLite | Requires an FTS5 virtual table; MATCH only applies to one. |
| MongoDB | Requires a text index on the searched fields. |