You are here

private function ExportPluginManager::getSynonymsData in Search API Synonym 8

Get synonyms matching the export options.

Return value

array Array with synonyms

1 call to ExportPluginManager::getSynonymsData()
ExportPluginManager::executeExport in src/Export/ExportPluginManager.php
Execute the synonym export.

File

src/Export/ExportPluginManager.php, line 168

Class

ExportPluginManager
Base class for search api synonym export plugin managers.

Namespace

Drupal\search_api_synonym\Export

Code

private function getSynonymsData() {

  // Create the db query.
  $query = \Drupal::database()
    ->select('search_api_synonym', 's');
  $query
    ->fields('s', [
    'sid',
    'type',
    'word',
    'synonyms',
  ]);
  $query
    ->condition('s.status', 1);
  $query
    ->condition('s.langcode', $this
    ->getExportOption('langcode'));
  $query
    ->orderBy('s.word');

  // Add type condition if it is set and different from all.
  $type = $this
    ->getExportOption('type');
  if ($type && $type != 'all') {
    $query
      ->condition('s.type', $type);
  }

  // Add filter condition if it is set and different from all.
  $filter = $this
    ->getExportOption('filter');
  if ($filter && $filter != 'all') {
    switch ($filter) {
      case 'nospace':
        $query
          ->condition('s.word', '% %', 'NOT LIKE');
        $query
          ->condition('s.synonyms', '% %', 'NOT LIKE');
        break;
      case 'onlyspace':
        $group = $query
          ->orConditionGroup()
          ->condition('s.word', '% %', 'LIKE')
          ->condition('s.synonyms', '% %', 'LIKE');
        $query = $query
          ->condition($group);
        break;
    }
  }

  // Add changed condition if incremental option is set.
  if ($incremental = $this
    ->getExportOption('incremental')) {
    $query
      ->condition('s.changed', $incremental, '>=');
  }

  // Fetch the result.
  return $query
    ->execute()
    ->fetchAllAssoc('sid');
}