Storage engines
SQLite engine
The SQLite engine is the default storage backend for TNTSearch. It stores the inverted index in a local SQLite database file, making it a zero-configuration option that works out of the box without any external dependencies.
Configuration
SQLite is the default engine. You don't need to specify it explicitly:
$tnt = new TNTSearch;
$tnt->loadConfig([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'user',
'password' => 'pass',
'storage' => '/path/to/indexes/',
]);
To be explicit, you can set the engine:
$tnt->loadConfig([
'driver' => 'mysql',
'engine' => 'TeamTNT\TNTSearch\Engines\SqliteEngine',
'storage' => '/path/to/indexes/',
// ... other config
]);
The index file will be created in the storage directory with the name you specify when calling createIndex().
Write-Ahead Logging (WAL)
For better concurrent read/write performance, you can enable SQLite's WAL mode:
$tnt->loadConfig([
'driver' => 'mysql',
'storage' => '/path/to/indexes/',
'wal' => true,
// ... other config
]);
WAL mode allows readers and writers to operate concurrently without blocking each other, which is beneficial when you need to update the index while searches are being performed.
Index schema
The SQLite engine creates the following tables:
| Table | Purpose |
|---|---|
wordlist | Stores unique terms with their document frequency and hit count |
doclist | Maps terms to documents (which documents contain which terms) |
hitlist | Stores term positions within documents |
fields | Metadata about indexed fields |
info | Index metadata (stemmer, tokenizer, total documents, etc.) |
filemap | Maps document IDs to file paths (for filesystem driver only) |
When to use SQLite
The SQLite engine is ideal when:
- You want a simple, self-contained setup with no external dependencies
- Your index fits comfortably on disk
- You don't need distributed or shared index access
- You're running a single application server
For high-throughput scenarios or when you need shared index access across multiple servers, consider the Redis engine.
File management
Each index is stored as a single SQLite file. You can:
- Back up an index by copying the file
- Delete an index by removing the file
- Move an index by relocating the file and updating the
storagepath
// Index is stored at: /path/to/indexes/articles.index
$indexer = $tnt->createIndex('articles.index');
