Simplify Search Integration with TNTSearch

TNTSearch is a powerful and efficient full-text search engine library designed for use in applications and websites written entirely in PHP.

search.php
composer.json
use TeamTNT\TNTSearch\TNTSearch;
$tnt = new TNTSearch;
$tnt->loadConfig($config);
$indexer = $tnt->createIndex('articles.index');
$indexer->query('SELECT id, article FROM articles;');
$indexer->run();

Introduction

Welcome to TNTSearch!

Welcome to the official documentation of TNTSearch, a powerful and flexible full-text search engine written entirely in PHP. Whether you need simple keyword search or advanced features like boolean queries, fuzzy matching, geo search, and text classification, TNTSearch has you covered.

Being crafted entirely in PHP, TNTSearch integrates natively into any PHP project without external service dependencies. It uses an inverted index stored in SQLite or Redis, and ranks results using the BM25 algorithm.

Installation

Step-by-step guide to installing TNTSearch via Composer.

Basic search

Learn how to create an index and perform your first search.

Redis engine

Use Redis as your index storage engine for high-performance search.

Architecture guide

Understand the internals and how the components fit together.


Quick start

Before you begin, make sure you have PHP and Composer installed on your system. Also make sure your server meets the following requirements:

  • PHP >= 7.1
  • PDO PHP Extension
  • SQLite PHP Extension
  • mbstring PHP Extension

Installation

TNTSearch is a Composer package:

composer require teamtnt/tntsearch

Creating an index

use TeamTNT\TNTSearch\TNTSearch;

$tnt = new TNTSearch;

$tnt->loadConfig([
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'dbname',
    'username'  => 'user',
    'password'  => 'pass',
    'storage'   => '/var/www/tntsearch/examples/',
    'stemmer'   => \TeamTNT\TNTSearch\Stemmer\PorterStemmer::class
]);

$indexer = $tnt->createIndex('name.index');
$indexer->query('SELECT id, article FROM articles;');
$indexer->run();
use TeamTNT\TNTSearch\TNTSearch;

$tnt = new TNTSearch;

$tnt->loadConfig($config);
$tnt->selectIndex("name.index");

$res = $tnt->search("This is a test search", 12);

print_r($res);
// Returns: ['ids' => [...], 'hits' => 6, 'execution_time' => '0.123 ms']

You should know!

TNTSearch returns document IDs, not full records. To display results you need an additional query against your application database: SELECT * FROM articles WHERE id IN ($ids) ORDER BY FIELD(id, $ids);


Getting help

For bugs, feature requests, or specific technical problems, please open an issue on the TNTSearch GitHub repository. Before opening a new issue:

  • Search through existing issues to see if someone else has reported the same problem.
  • Provide as much detail as possible, including error messages, logs, and steps to reproduce.
  • Tag your issue appropriately (e.g., bug, enhancement, question).

Stack Overflow

For general questions or help with implementation, you can ask the community on Stack Overflow using the tag tntsearch.

Ask a Question on Stack Overflow