Full-text search allows you to perform fast text searches across multiple columns in your database.
- MySQL: Uses
MATCH AGAINSTwith FULLTEXT indexes - PostgreSQL: Uses
@@ to_tsquery()with text search vectors - SQLite: Uses
MATCHwith FTS5 virtual tables
use tommyknocker\pdodb\helpers\Db;
// Search across multiple columns
$results = $db->find()
->from('articles')
->where(Db::fulltextMatch('title, content', 'database tutorial'))
->get();$results = $db->find()
->from('articles')
->where(Db::fulltextMatch('title', 'PHP'))
->get();// Natural language mode (default)
$results = $db->find()
->from('articles')
->where(Db::fulltextMatch('title, content', 'optimization tips', 'natural'))
->get();
// Boolean mode
$results = $db->find()
->from('articles')
->where(Db::fulltextMatch('title, content', '+optimization -security', 'boolean'))
->get();// Expand search with related terms
$results = $db->find()
->from('articles')
->where(Db::fulltextMatch('title, content', 'database', null, true))
->get();CREATE TABLE articles (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255),
content TEXT,
FULLTEXT (title, content)
);CREATE TABLE articles (
id SERIAL PRIMARY KEY,
title VARCHAR(255),
content TEXT,
ts_vector TSVECTOR GENERATED ALWAYS AS (
to_tsvector('english', title || ' ' || content)
) STORED
);
CREATE INDEX idx_ts_vector ON articles USING GIN (ts_vector);CREATE VIRTUAL TABLE articles USING fts5(title, content);- Full-text indexes must be created before using full-text search
- Full-text search requires proper indexing for optimal performance
- For SQLite, use FTS5 virtual tables for full-text search
- PostgreSQL requires creating text search vectors and indexes
- MySQL FULLTEXT indexes support only
MyISAMorInnoDBwith InnoDB full-text parser plugin
- Filtering Conditions - WHERE clauses
- Helper Functions Reference - Complete helpers
- Performance - Query optimization