arzurchris-zz / tntsearch

A fully featured full text search engine written in PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Latest Version on Packagist Total Downloads Software License Slack Status

#TNTSearch

A fully featured full text search engine written in PHP

##Demo

To see TNTSearch in action take a look at the demo page

##Installation

The easiest way to install TNTSearch is via composer. Create the following composer.json file and run the php composer.phar install command to install it.

{
    "require": {
        "teamtnt/tntsearch": "0.1.*"
    }
}

##Examples

Creating an index

In order to be able to make full text search queries you have to create an index.

Usage:

    use TeamTNT\TNTSearch\TNTSearch;

    $tnt = new TNTSearch;

    $tnt->loadConfig([
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'dbname',
        'username'  => 'user',
        'password'  => 'pass',
        'storage'   => '/var/www/tntsearch/examples/'
    ]);

    $indexer = $tnt->createIndex('name.index');
    $indexer->query('SELECT id, article FROM articles;');
    //$indexer->setLanguage('german');
    $indexer->run();

Important: "storage" settings marks the folder where all of your indexes will be saved so make sure to have permission to write to this folder otherwise you might expect the following exception thrown:

  • [PDOException] SQLSTATE[HY000] [14] unable to open database file *

Note: Your select statment MUST contain an ID field.

Searching

Searching for a phrase or keyword is trivial

    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 an array of 12 document ids that best match your query

    //to display the results you need an additional query
    //SELECT * FROM articles WHERE id IN $res ORDER BY FIELD(id, $res);

The ORDER BY FIELD clause is important otherwise the database engine will not return the results in required order

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

A fully featured full text search engine written in PHP

License:MIT License


Languages

Language:PHP 100.0%