PHP code example of karelwintersky / arris.toolkit.sphinxql-pdo-wrapper

1. Go to this page and download the library: Download karelwintersky/arris.toolkit.sphinxql-pdo-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

karelwintersky / arris.toolkit.sphinxql-pdo-wrapper example snippets


use \Arris\Toolkit\SphinxQL\PDOWrapper;

$mysql_connection = new \Arris\Database\DBWrapper([
    'driver'    =>  'mysql',
    'hostname'  =>  getenv('DB.HOST'),
    'username'  =>  getenv('DB.USERNAME'),
    'password'  =>  getenv('DB.PASSWORD'),
    'database'  =>  getenv('DB.NAME'),
    'charset'   =>  'utf8',
    'charset_collate'   =>  'utf8_general_ci',
    'slow_query_threshold'  => 1
]);

$sphinx_connection = new \Arris\Database\DBWrapper([
    'driver'            =>  'mysql',
    'hostname'          =>  getenv('SEARCH.HOST'),
    'database'          =>  NULL,
    'username'          =>  getenv('SEARCH.USER'),
    'password'          =>  getenv('SEARCH.PASSWORD'),
    'port'              =>  getenv('SEARCH.PORT'),
    'charset'           =>  NULL,
    'charset_collate'   =>  NULL
]);

$toolkit = new PDOWrapper($mysql_connection, $sphinx_connection);
$toolkit->setRebuildIndexOptions([
    'log_rows_inside_chunk' =>  false,
    'log_after_chunk'       =>  false,
    'sleep_after_chunk'     =>  $options['is_sleep'],
    'sleep_time'            =>  $options['sleeptime'],
    'chunk_length'          =>  $options['sql_limit']
]);
$toolkit->setConsoleMessenger([ \Arris\Toolkit\CLIConsole::class, "say" ]);

$rt_index = getenv('SEARCH.RT_INDEX.ARTICLES');
if ($rt_index) {
    // статьи
    $count_rebuilt['articles'] =
        $toolkit->rebuildAbstractIndex(
            'articles', 
            $rt_index, 
            static function ($item) {
                return \FSNews\SearchEngine::prepare_RTArticle($item, true);
            }, 
            " s_draft = 0 ", 
            true, 
            ['rubrics', 'districts']
        );
} else {
    CLIConsole::say("[SEARCH.RT_INDEX.ARTICLES] <font color='red'>disabled</font>");
}