protected function SearchApiSolrBackend::isPartOfSchema in Search API Solr 4.x
Same name and namespace in other branches
- 8.3 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.
\Solarium\Core\Client\Endpoint|null $endpoint:
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 4591
Class
- SearchApiSolrBackend
- Apache Solr backend for search api.
Namespace
Drupal\search_api_solr\Plugin\search_api\backendCode
protected function isPartOfSchema($kind, $name, ?Endpoint $endpoint = NULL) {
static $previous_calls;
$endpoint_key = $endpoint ? $endpoint
->getKey() : $this
->getServer()
->id();
$state = \Drupal::state();
// This state is resetted once a day via cron.
$schema_parts = $state
->get('search_api_solr.endpoint.schema_parts');
if (!is_array($schema_parts) || empty($schema_parts[$endpoint_key]) || empty($schema_parts[$endpoint_key][$kind]) || !in_array($name, $schema_parts[$endpoint_key][$kind]) && !isset($previous_calls[$endpoint_key][$kind])) {
$response = $this
->getSolrConnector()
->coreRestGet('schema/' . strtolower($kind), $endpoint);
if (empty($response[$kind])) {
throw new SearchApiSolrException('Missing information about ' . $kind . ' in response to REST request.');
}
// Delete the old state.
$schema_parts[$endpoint_key][$kind] = [];
foreach ($response[$kind] as $row) {
$schema_parts[$endpoint_key][$kind][] = $row['name'];
}
$state
->set('search_api_solr.endpoint.schema_parts', $schema_parts);
$previous_calls[$endpoint_key][$kind] = TRUE;
}
return in_array($name, $schema_parts[$endpoint_key][$kind]);
}