MySql.php in Search API 8
File
modules/search_api_db/src/DatabaseCompatibility/MySql.php
View source
<?php
namespace Drupal\search_api_db\DatabaseCompatibility;
use Drupal\Core\Database\DatabaseException;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\search_api\SearchApiException;
class MySql extends GenericDatabase {
public function alterNewTable($table, $type = 'text') {
$charset = $type === 'text' ? 'utf8mb4' : 'utf8';
$collation = $type === 'text' ? 'utf8mb4_bin' : 'utf8_general_ci';
try {
$this->database
->query("ALTER TABLE {{$table}} CONVERT TO CHARACTER SET '{$charset}' COLLATE '{$collation}'");
} catch (\PDOException $e) {
$class = get_class($e);
$message = $e
->getMessage();
throw new SearchApiException("{$class} while trying to change collation of {$type} search data table '{$table}': {$message}", 0, $e);
} catch (DatabaseException $e) {
$class = get_class($e);
$message = $e
->getMessage();
throw new SearchApiException("{$class} while trying to change collation of {$type} search data table '{$table}': {$message}", 0, $e);
}
}
public function preprocessIndexValue($value, $type = 'text') {
$value = parent::preprocessIndexValue($value, $type);
if ($type !== 'text') {
$value = rtrim($value);
}
return $value;
}
public function orderByRandom(SelectInterface $query) {
$alias = $query
->addExpression('rand()', 'random_order_field');
$query
->orderBy($alias);
}
}
Classes
Name |
Description |
MySql |
Represents a MySQL-based database. |