text_search()
The text_search()
function provides advanced text search capabilities, allowing you to search text columns for words or phrases with automatic tokenization and language-specific normalization.
Elements
column
-
The text column to search within. This should be a column containing text content.
query
-
The search query, which can be a literal string or a parameter. The query can contain multiple words that will be searched for using an AND logic (all words must be present).
configuration
-
Optional language configuration to use for text search. If not specified, a simple configuration without language-specific features is used.
Features
- Word Tokenization
-
Automatically breaks text into tokens (words) based on language-specific rules.
- Text Normalization
-
Handles stemming, stop words, and other language-specific normalizations based on the chosen configuration.
- Multi-word Search
-
When a query contains multiple words, finds entries that contain all of those words (combined with logical AND).
- Linguistic Support
-
Supports multiple language configurations for more accurate matching in different languages.
Supported Language Configurations
The following language configurations are supported:
-
'danish'
-
'dutch'
-
'english'
-
'finnish'
-
'french'
-
'german'
-
'hungarian'
-
'italian'
-
'norwegian'
-
'portuguese'
-
'romanian'
-
'russian'
-
'simple'
(default) -
'spanish'
-
'swedish'
-
'turkish'
Examples
SELECT * FROM articles
WHERE text_search(content, 'database')
SELECT * FROM articles
WHERE text_search(content, :searchQuery)
SELECT * FROM articles
WHERE text_search(content, 'database system', 'english')
SELECT * FROM articles
WHERE text_search(content_english, :searchQuery, 'english')
OR text_search(content_spanish, :searchQuery, 'spanish')
SELECT * FROM articles
WHERE text_search(content, :searchQuery, 'english')
AND category = 'technology'
AND published_date > '2022-01-01'
How Text Search Works
The text_search()
function:
-
Tokenizes the column text into words based on the language configuration
-
Applies language-specific normalization (stemming, stop words removal)
-
Tokenizes and normalizes the query text in the same way
-
Searches for matches where all query words are present in the column text
-
Returns true for rows where all query words are found, false otherwise
Notes
-
Text search is only available for deployed services and cannot be used in local testing environments
-
For optimal performance, the text column should be indexed for text search
-
The default
'simple'
configuration provides basic tokenization without language-specific features -
Language-specific configurations provide better matching through stemming (e.g., matching "running" with "run") and stop word removal
-
Multiple words in the query are combined with AND logic (all words must be present)
-
Text search is case-insensitive by default
Related Features
-
WHERE clause - Used with text_search() for filtering
-
LIKE operator - Simpler pattern matching alternative