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
]);

// или через Arris\Database\Connector()

$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>");
}


    /**
     * @param $connection
     * @param $index
     * @return false|\PDOStatement
     */
    public static function RTIndexOptimize($connection, $index)
    {
        $query = "OPTIMIZE INDEX {$index}";
        return $connection->query($query);
    }

    /**
     * @param $connection
     * @param $index
     * @param bool $reconfigure
     * @return bool
     */
    public static function RTIndexTruncate($connection, $index, bool $reconfigure = true): bool
    {
        $with = $reconfigure ? 'WITH RECONFIGURE' : '';
        return (bool)$connection->query("TRUNCATE RTINDEX {$index} {$with}");
    }
    
        /**
     * @param $connection
     * @param $index
     * @return bool
     */
    public static function RTIndexCheckExist($connection, $index)
    {
        $index_definition = $connection->query("SHOW TABLES LIKE '{$index}' ")->fetchAll();
    
        return \count($index_definition) > 0;
    }
    
    // +show meta
    // +show version