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_sqlite and sqlite3)
  • 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

OptionRequiredDescription
driverYesDatabase driver: mysql, pgsql, sqlite, sqlsrv, or filesystem
hostYes*Database host (*not needed for SQLite/filesystem)
databaseYes*Database name or path to SQLite file
usernameYes*Database username (*not needed for SQLite/filesystem)
passwordYes*Database password (*not needed for SQLite/filesystem)
storageYesDirectory where index files will be stored
stemmerNoStemmer class to use (defaults to NoStemmer)
tokenizerNoTokenizer class to use (defaults to Tokenizer)
engineNoStorage 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";
Previous
Getting started