Introduction
Installation
TNTSearch is distributed as a Composer package and can be installed in any PHP project.
Requirements
Make sure your server meets the following requirements:
- PHP >= 7.1 (PHP 8.x fully supported)
- PDO PHP Extension
- SQLite PHP Extension (
pdo_sqliteandsqlite3) - mbstring PHP Extension
If you plan to use the Redis storage engine, you also need the predis/predis package (installed automatically as a dependency).
Install via Composer
composer require teamtnt/tntsearch
This will install TNTSearch and all required dependencies.
Configuration
TNTSearch requires a configuration array to connect to your data source and define where indexes are stored. Here is a complete example:
use TeamTNT\TNTSearch\TNTSearch;
$tnt = new TNTSearch;
$tnt->loadConfig([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'user',
'password' => 'pass',
'storage' => '/path/to/indexes/',
'stemmer' => \TeamTNT\TNTSearch\Stemmer\PorterStemmer::class,
'tokenizer' => \TeamTNT\TNTSearch\Support\Tokenizer::class,
]);
Configuration options
| Option | Required | Description |
|---|---|---|
driver | Yes | Database driver: mysql, pgsql, sqlite, sqlsrv, or filesystem |
host | Yes* | Database host (*not needed for SQLite/filesystem) |
database | Yes* | Database name or path to SQLite file |
username | Yes* | Database username (*not needed for SQLite/filesystem) |
password | Yes* | Database password (*not needed for SQLite/filesystem) |
storage | Yes | Directory where index files will be stored |
stemmer | No | Stemmer class to use (defaults to NoStemmer) |
tokenizer | No | Tokenizer class to use (defaults to Tokenizer) |
engine | No | Storage engine class (defaults to SqliteEngine) |
Supported database drivers
TNTSearch can index data from any of these databases:
- MySQL -
'driver' => 'mysql' - PostgreSQL -
'driver' => 'pgsql' - SQLite -
'driver' => 'sqlite' - SQL Server -
'driver' => 'sqlsrv' - Filesystem -
'driver' => 'filesystem'(indexes text files from a directory)
Note
The driver setting determines where your source data lives. The index itself is always stored in SQLite (default) or Redis, regardless of the source database driver.
Verify installation
To verify everything is working, create a simple test script:
use TeamTNT\TNTSearch\TNTSearch;
$tnt = new TNTSearch;
$tnt->loadConfig([
'driver' => 'sqlite',
'database' => '/path/to/your/database.sqlite',
'storage' => '/path/to/indexes/',
]);
$indexer = $tnt->createIndex('test.index');
echo "TNTSearch is installed and working!\n";
