You are here

class GenericDatabase in Search API 8

Represents any database for which no specifics are known.

Hierarchy

Expanded class hierarchy of GenericDatabase

2 files declare their use of GenericDatabase
BackendTest.php in modules/search_api_db/tests/src/Kernel/BackendTest.php
Database.php in modules/search_api_db/src/Plugin/search_api/backend/Database.php
1 string reference to 'GenericDatabase'
search_api_db.services.yml in modules/search_api_db/search_api_db.services.yml
modules/search_api_db/search_api_db.services.yml
1 service uses GenericDatabase
search_api_db.database_compatibility in modules/search_api_db/search_api_db.services.yml
Drupal\search_api_db\DatabaseCompatibility\GenericDatabase

File

modules/search_api_db/src/DatabaseCompatibility/GenericDatabase.php, line 12

Namespace

Drupal\search_api_db\DatabaseCompatibility
View source
class GenericDatabase implements DatabaseCompatibilityHandlerInterface {

  /**
   * The connection to the database.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $database;

  /**
   * The transliteration service to use.
   *
   * @var \Drupal\Component\Transliteration\TransliterationInterface
   */
  protected $transliterator;

  /**
   * Constructs a GenericDatabase object.
   *
   * @param \Drupal\Core\Database\Connection $database
   *   The connection to the database.
   * @param \Drupal\Component\Transliteration\TransliterationInterface $transliterator
   *   The transliteration service to use.
   */
  public function __construct(Connection $database, TransliterationInterface $transliterator) {
    $this->database = $database;
    $this->transliterator = $transliterator;
  }

  /**
   * {@inheritdoc}
   */
  public function getDatabase() {
    return $this->database;
  }

  /**
   * {@inheritdoc}
   */
  public function getCloneForDatabase(Connection $database) {
    $service = clone $this;
    $service->database = $database;
    return $service;
  }

  /**
   * {@inheritdoc}
   */
  public function alterNewTable($table, $type = 'text') {
  }

  /**
   * {@inheritdoc}
   */
  public function preprocessIndexValue($value, $type = 'text') {
    if ($type == 'text') {
      return $value;
    }
    return mb_strtolower($this->transliterator
      ->transliterate($value));
  }

  /**
   * {@inheritdoc}
   */
  public function orderByRandom(SelectInterface $query) {
    $alias = $query
      ->addExpression('random()', 'random_order_field');
    $query
      ->orderBy($alias);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
GenericDatabase::$database protected property The connection to the database.
GenericDatabase::$transliterator protected property The transliteration service to use.
GenericDatabase::alterNewTable public function Reacts to a new table being created. Overrides DatabaseCompatibilityHandlerInterface::alterNewTable 1
GenericDatabase::getCloneForDatabase public function Creates a clone of this service for the given database. Overrides DatabaseCompatibilityHandlerInterface::getCloneForDatabase
GenericDatabase::getDatabase public function Retrieves the database connection this compatibility handler is based upon. Overrides DatabaseCompatibilityHandlerInterface::getDatabase
GenericDatabase::orderByRandom public function Applies a random sort to the query. Overrides DatabaseCompatibilityHandlerInterface::orderByRandom 1
GenericDatabase::preprocessIndexValue public function Determines the canonical base form of a value. Overrides DatabaseCompatibilityHandlerInterface::preprocessIndexValue 2
GenericDatabase::__construct public function Constructs a GenericDatabase object.