You are here

protected function SearchApiSolrBackend::isPartOfSchema in Search API Solr 8.3

Same name and namespace in other branches
  1. 4.x src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::isPartOfSchema()

Indicates if an 'element' is part of the Solr server's schema.

Parameters

string $kind: The kind of the element, for example 'dynamicFields' or 'fieldTypes'.

string $name: The name of the element.

Return value

bool TRUE if an element of the given kind and name exists, FALSE otherwise.

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

\Drupal\search_api_solr\SearchApiSolrException

1 call to SearchApiSolrBackend::isPartOfSchema()
SearchApiSolrBackend::getSchemaLanguageStatistics in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Gets schema language statistics for the multilingual Solr server.

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 4349

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

protected function isPartOfSchema($kind, $name) {
  static $previous_calls;
  $state_key = 'search_api_solr.' . $this
    ->getServer()
    ->id() . '.schema_parts';
  $state = \Drupal::state();

  // @todo Reset that drupal state from time to time.
  $schema_parts = $state
    ->get($state_key);
  if (!is_array($schema_parts) || empty($schema_parts[$kind]) || !in_array($name, $schema_parts[$kind]) && !isset($previous_calls[$kind])) {
    $response = $this
      ->getSolrConnector()
      ->coreRestGet('schema/' . strtolower($kind));
    if (empty($response[$kind])) {
      throw new SearchApiSolrException('Missing information about ' . $kind . ' in response to REST request.');
    }

    // Delete the old state.
    $schema_parts[$kind] = [];
    foreach ($response[$kind] as $row) {
      $schema_parts[$kind][] = $row['name'];
    }
    $state
      ->set($state_key, $schema_parts);
    $previous_calls[$kind] = TRUE;
  }
  return in_array($name, $schema_parts[$kind]);
}