Storage engines

Filesystem indexing

TNTSearch can index text files directly from a directory on your filesystem, without needing a database. This is useful for searching through collections of documents, log files, markdown files, or any directory of text-based files.


Configuration

Set the driver to filesystem and provide the directory path and file extension:

use TeamTNT\TNTSearch\TNTSearch;

$tnt = new TNTSearch;

$tnt->loadConfig([
    'driver'    => 'filesystem',
    'storage'   => '/path/to/indexes/',
    'location'  => '/path/to/documents/',
    'extension' => 'txt',
]);

Configuration options

OptionDescription
driverMust be filesystem
storageDirectory where the index file will be stored
locationDirectory containing the files to index
extensionFile extension to index (e.g., txt, md, html)

Creating the index

The indexer automatically scans the directory and indexes all files matching the extension:

$indexer = $tnt->createIndex('documents.index');
$indexer->run();

No query() call is needed since the data source is the filesystem, not a database.


Searching

Search works the same as with any other driver:

$tnt->selectIndex('documents.index');
$results = $tnt->search('search terms');

Result format

For filesystem indexes, the search results return file paths instead of document IDs:

$results = $tnt->search('important document');
// Returns an array of file paths that match the query

TNTSearch automatically maps internal document IDs back to file paths using the filemap table.


Use cases

Filesystem indexing is well-suited for:

  • Searching through documentation files
  • Indexing log files or configuration files
  • Building a search feature for static sites
  • Indexing email archives or exported data

Note

The filesystem driver uses the TextFileReader to read file contents. It works with plain text files. For other formats (PDF, Word, etc.), you would need to extract the text first and write it as plain text files.

Previous
Redis engine