You are here

public function StandardSolrCloudConnector::createCollection in Search API Solr 4.x

Creates collection.

Parameters

array $options:

string|null $collection: Collection.

Return value

bool TRUE if successful, FALSE otherwise.

Throws

\Drupal\search_api_solr\SearchApiSolrException

Overrides SolrCloudConnectorInterface::createCollection

File

src/Plugin/SolrConnector/StandardSolrCloudConnector.php, line 383

Class

StandardSolrCloudConnector
Standard Solr Cloud connector.

Namespace

Drupal\search_api_solr\Plugin\SolrConnector

Code

public function createCollection(array $options, ?string $collection = NULL) : bool {
  $this
    ->connect();
  $this
    ->useTimeout(self::FINALIZE_TIMEOUT);
  try {
    $collection = $collection ?? $this->configuration['core'];
    $query = $this->solr
      ->createCollections();
    $action = $query
      ->createCreate([
      'name' => $collection,
    ] + $options);
    $query
      ->setAction($action);
    $response = $this->solr
      ->collections($query);
    return $response
      ->getWasSuccessful();
  } catch (HttpException $e) {
    throw new SearchApiSolrException("Creating collection {$collection} failed with error code " . $e
      ->getCode() . ': ' . $e
      ->getMessage(), $e
      ->getCode(), $e);
  }
}